Professional Documents
Culture Documents
CM Os 5sem Chapter5
CM Os 5sem Chapter5
Memory Management
File-System and Memory
Management : Syllabus
File-System
• 5.1 File- Concept, Attributes, Operations,
Types, Structure
• 5.2 Access Methods – Sequential, Direct.
• 5.3 Swapping
• 5.4 Allocation Methods – Contiguous, Linked,
Indexed.
• 5.5 Directory Structure – Single level, Two
level, Tree Structure.
2
File-System and Memory
Management : Syllabus
contd..
• 5.6 Protection –Types of accesses, Access
control.
• 5.7 Basic Memory Management –Partitioning,
Fixed & Variable.
• 5.8 Free Space management techniques –
Bitmap ,Linked List.
3
Learning Objectives
• To explain the function of file systems
• To describe the interfaces to file systems
• To discuss file-system design tradeoffs, including
access methods, file sharing, file locking, and
directory structures
4
Learning Objectives Contd..
• To explore file-system protection
• To describe the details of implementing local file
systems and directory structures
• To describe the implementation of remote file
systems
• To discuss block allocation and free-block
algorithms and trade-offs
5
5.1 File- Concept, Attributes,
Operations, Types, Structure
6
File Concept
• Contiguous logical address space
• Types:
– Data
• numeric
• character
• binary
– Program
7
5.1 File- Concept, Attributes,
Operations, Types, Structure
8
File Attributes
• Name – only information kept in human-
readable form
• Identifier – unique tag (number) identifies file
within file system
• Type – needed for systems that support different
types
• Location – pointer to file location on device
• Size – current file size
9
File Attributes contd..
• Protection – controls who can do reading,
writing, executing
• Time, date, and user identification – data for
protection, security, and usage monitoring
• Information about files are kept in the directory
structure, which is maintained on the disk
10
5.1 File- Concept, Attributes,
Operations, Types, Structure
11
File Operations
• File is an abstract data type
• Create
• Write
• Read
• Reposition within file
12
File Operations contd..
• Delete
• Truncate
• Open(Fi) – search the directory structure
on disk for entry Fi, and move the content
of entry to memory
• Close (Fi) – move the content of entry Fi in
memory to directory structure on disk
13
5.1 File- Concept, Attributes,
Operations, Types, Structure
14
File Types – Name, Extension
15
5.1 File- Concept, Attributes,
Operations, Types, Structure
16
File Structure
• None - sequence of words, bytes
• Simple record structure
– Lines
– Fixed length
– Variable length
• Complex Structures
– Formatted document
– Relocatable load file
17
File Structure contd..
• Can simulate last two with first method by
inserting appropriate control characters
• Who decides:
– Operating system
– Program
18
5.2 Access Methods
19
Access Methods
• Sequential Access
read next
write next
reset
no read after last write
(rewrite)
• Direct Access
read n
write n
position to n
read next
write next
rewrite n
n = relative block number
20
Sequential-access File
21
Simulation of Sequential Access on a Direct-
access File
22
Example of Index and Relative Files
23
5.4 Allocation Methods
24
Allocation Methods
• An allocation method refers to how disk
blocks are allocated for files:
• Contiguous allocation
• Linked allocation
• Indexed allocation
25
Contiguous Allocation
26
Contiguous Allocation contd..
LA/512
28
Linked Allocation
• Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk.
block =
pointer
29
Linked Allocation Contd..
30
Linked Allocation contd..
31
Indexed Allocation
index table
Brings all pointers together into the index block.
Logical view.
32
Example of Indexed Allocation
33
Indexed Allocation (Contd..)
34
Indexed Allocation – Mapping
(Contd..)
• Mapping from logical to physical in a file of unbounded length (block
size of 512 words).
• Linked scheme – Link blocks of index table (no limit on size).
Q1
LA / (512 x 511)
R1
Q1 = block of index table
R1 is used as follows:
Q2
R1 / 512
R2
35
Indexed Allocation – Mapping
(Contd..)
Q1
LA / (512 x 512)
R1
• Two-level index (maximum file size is 5123)
36
Indexed Allocation – Mapping
(Contd..)
outer-index
37
5.5 Directory Structure- single
level, Two level, Tree structure
38
Directory Structure
A collection of nodes containing information about all files
Directory
Files F1 F2 F4
F3
Fn
40
Operations Performed on
Directory
• Search for a file
• Create a file
• Delete a file
• List a directory
• Rename a file
• Traverse the file system
41
Organize the Directory (Logically) to
Obtain
• Efficiency – locating a file quickly
• Naming – convenient to users
– Two users can have same name for different
files
– The same file can have several different
names
• Grouping – logical grouping of files by
properties, (e.g., all Java programs, all games,
…)
42
Single-Level Directory
• Naming problem
• Grouping problem
43
Two-Level Directory
Path name
Can have the same file name for different user
Efficient searching
No grouping capability
44
Tree-Structured Directories
Spell bin Program
45
Tree-Structured Directories Contd..
• Efficient searching
• Grouping Capability
46
Tree-Structured Directories Cont..
48
Free-Space Management
0 1 2 n-1
Bit vector (n blocks) …
0 block[i] free
bit[i] =
1 block[i] occupied
49
Bit map Contd..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
• Bitmap 0001111001111110
• Bit map requires extra space
– Example:
block size = 212 bytes
disk size = 230 bytes (1 gigabyte)
n = 230/212 = 218 bits (or 32K bytes)
• Easy to get contiguous files
50
Linked List
F 0 3 4 A 2 4 4 F 2 3 4
51
Free-Space Management (Cont.)
Need to protect:
Pointer to free list
Bit map
Must be kept on disk
Copy in memory and disk may differ
Cannot allow for block[i] to have a situation where
bit[i] = 1 in memory and bit[i] = 0 on disk
Solution:
Set bit[i] = 1 in disk
Allocate block[i]
Set bit[i] = 1 in memory
52
End of Chapter 5