Buffer Cache
Buffer Cache
Buffer Cache
User programs
libraries
trap
User level
Kernel level
File subsytem
Buffer cache
Chracter
Process
control
sybsystem
Inter-process
communication
scheduler
Memory
management
block
Device drivers
Kernel level
Hardware level
Hardware control
hardware
System Calls
System call are similar to ordinary functions
Libraries map these function call to primitives
needed to enter OS
Assembly programs can directly invoke system
call
System calls can be categorized into :
File subsystem related calls
Process control system related calls
Super block
Inode list
Data blocks
Buffering
File subsystem accesses file data using
buffering mechanism
The mechanism regulates the flow between
buffer and secondary storage
The mechanism interacts with block i/o
device driver to initiate the data transfer
block I/O devices are random access
storage devices
Device drivers are kernel module that
controls the device operation
5
Buffer Cache
When a process wants to access data from a file,
the kernel brings the data into main memory,
alters it and then request to save in the file
system
Buffering increases the response time ,
throughput,
Buffering minimizes the frequency of disk
access by keeping a pool of internal data buffer
called buffer cache.
6
Buffer Cache
Buffer cache contains the data in recently used
disk blocks
When reading data from disk, the kernel
attempts to read from buffer cache.
If data is already in the buffer cache, the kernel
does not need to read from disk
If data is not in the buffer cache, the kernel
reads the data from disk and cache it
7
Buffer Headers
A buffer consists of two parts
a memory array
buffer header
status
ptr to previous buf on hash queue
ptr to next buf on hash queue
ptr to previous buf on free list
ptr to next buf on free list
Figure 3.1 Buffer Header
Buffer Headers
device num
logical file system number
block num
block number of the data on disk
status
free list
head
buf 1
buf 2
buf n
Back ptrs
10
28
64
blkno1 mod 4
17
97
blkno2 mod 4
98
50
10
blkno3 mod 4
35
99
blkno0 mod 4
11
12
28
64
17
97
98
50
10
35
99
blkno0 mod 4
blkno1 mod 4
blkno2 mod 4
blkno3 mod 4
freelist header
13
64
17
97
98
50
10
35
99
blkno0 mod 4
blkno1 mod 4
blkno2 mod 4
blkno3 mod 4
freelist header
14
28
64
17
97
98
50
10
35
99
blkno0 mod 4
blkno1 mod 4
blkno2 mod 4
blkno3 mod 4
freelist header
15
28
64
17
97
98
50
10
35
99
blkno0 mod 4
blkno1 mod 4
blkno2 mod 4
blkno3 mod 4
18
freelist header
28
64
17
97
blkno0 mod 4
blkno1 mod 4
blkno2 mod 4
blkno3 mod 4
delay
98
50
10
35
99
delay
freelist header
28
64
blkno0 mod 4
blkno1 mod 4
17
97
writing
blkno2 mod 4
blkno3 mod 4
98
50
10
35
99
18
writing
freelist header
(b) Writing Blocks 3, 5, Reassign 4 to 18
Figure 3.8
18
28
64
17
97
blkno2 mod 4
98
50
10
blkno3 mod 4
35
99
blkno0 mod 4
blkno1 mod 4
freelist header
19
28
64
17
97
98
50
10
35
99
blkno0 mod 4
blkno1 mod 4
blkno2 mod 4
blkno3 mod 4
busy
freelist header
20
namei
alloc free
iget
ialloc ifree
iput
buffer allocation algorithms
getblk
brelse
bread
bwrite
Inode
contains the information necessary for a process to
access a file
exits in a static form on disk and the kernel reads
them into an in-core inode
22
Inodes
consists of
- file owner identifier
- file type
- file access permissions
- file access times
- number of links to the file
- table of contents for the disk address of data in a
file
- file size
23
Inodes
in-core copy of the inode contains
- status of the in-core inode indicating
- logical device number of file system
- inode number
- pointers to other in-core inodes
- reference count
24
25
26
Data Blocks
direct0
direct1
direct2
direct3
direct4
direct5
direct6
direct7
direct8
direct9
single indirect
double indirect
triple indirect
27
28