Академический Документы
Профессиональный Документы
Культура Документы
Hash Queue
98
50
10
35
99
else{
if ( there are no buffers on free list)
{
/*scenario 4*/
sleep(event any buffer becomes free)
continue;
}
remove buffer from free list;
if(buffer marked for delayed write)
{
/*scenario 3*/
asynchronous write buffer to disk;
continue;
}
/*scenario 2*/
remove buffer from old hash queue;
put buffer onto new hash queue;
return buffer;
}
}}
There are five scenarios , the kernel may follow in getblk to allocate
a buffer for a disk block
The kernel finds the block on its hash queue and its buffer is
free.
The kernel cannot find the block on the hash queue , so it
allocates a buffer from the free list.
The kernel cannot find the block on the hash queue and in
attempting to allocate a buffer from the free list , finds a buffer
on the free list that has marked delayed write. The kernel
must write the delayed write buffer to disk and allocate
another buffer.
The kernel cannot find the block on the hash queue and the free
list of buffers is empty.
The kernel finds the block on the hash queue , but its buffer is
currently busy.
6
N.I.T. Raipur,Computer Science
Scenario 1 : The kernel finds the block on its hash queue and its buffer is free.
28
64
Blkno 1 mod 4
17
97
Blkno 2 mod 4
98
50
10
Blkno 3 mod 4
35
99
Freelist header
2001.3.9
1 Scenario
st
After allocating
Blkno 0 mod 4
28
64
Blkno 1 mod 4
17
97
Blkno 2 mod 4
98
50
10
Blkno 3 mod 4
35
99
Freelist header
2001.3.9
algorithm brelse
input: locked buffer
output: none
{
wakeup all pros: event , waiting for any buffer to become free;
wakeup all pros: event , waiting for this buffer to become free;
raise processor execution level to block interrupts;
if (buffer contents valid and buffer not old)
enquence buffer at end of free list
else
enquence buffer at beginning of free list
lower processor execution level to allow interrupts;
unlock(buffer);
}
9
N.I.T. Raipur,Computer Science
Scenario 2 : The kernel cannot find the block on the hash queue , so it allocates a buffer from the free list.
17
97
Blkno 2 mod 4
98
50
10
Blkno 3 mod 4
35
99
Freelist header
2001.3.9
nd
Scenario
After allocating
Blkno 0 mod 4
28
64
Blkno 1 mod 4
17
97
Blkno 2 mod 4
98
50
10
35
99
Blkno 3 mod 4
Freelist header
(b) Remove first block from free list, assign to 18
2001.3.9
18
3rd Scenario
Not in the hash queue and there exists
delayed write buffer in the front of free list
Write delayed buffer . and choose next
Blkno 0 mod 4
28
64
Blkno 1 mod 4
17
97
Blkno 2 mod 4
98
50
10
Blkno 3 mod 4
35
99
delay
delay
Freelist header
(a) Search for block 18, delayed write blocks on free list
3 Scenario
rd
After allocating
Blkno 0 mod 4
28
Blkno 1 mod 4
17
Blkno 2 mod 4
Blkno 3 mod 4
64
5
97
98
50
10
35
99
writing
writing
Freelist header
(b) Writing block 3, 5, reassign 4 to 18
18
Scenario 4: The kernel cannot find the block on the hash queue, and the free list of buffers is empty.
17
97
Blkno 2 mod 4
98
50
10
Blkno 3 mod 4
35
99
Freelist header
(a) Search for block 18, empty free list
4th Scenario
Process A
Process B
4 Scenario
th
What to remind
When process release a buffer wake all
process waiting any buffer cache
2001.3.9
SS 1
Scenario 5:The kernel finds the block on the hash queue , but its buffer is currently
busy.
28
64
Blkno 1 mod 4
17
97
Blkno 2 mod 4
98
50
10
Blkno 3 mod 4
35
99
Freelist header
(a) Search for block 99, block busy
busy
5th Scenario
Process A
Process B
Process C
Allocate buffer
to block b
Find block b
on hash queue
Buffer locked, sleep
Lock buffer
Initiate I/O
Sleep until I/O done
I/O done, wake up
brelse(): wake up others
time
does not need to know the reason for the I/O. Instead , it copies
data to and from buffers , regardless of whether the data is part
of a file , an inode or a super block.
The system places no data alignment restrictions on user
processes doing I/O , because the kernel aligns data internally.
Hardware implementation frequently require a particular
alignment of data for disk I/O , such as aligning the data on a
two-byte boundary or on a four-byte boundary in memory.
The kernel eliminates the need for special alignment of user
buffers , making user programs simpler and more portable.
Use of the buffer cache can reduce the amount of disk traffic ,
thereby increasing overall system throughput and decreasing
response time.
Process reading from the file system may find data blocks in the
cache and the need for disk I/O.
22
22
23