0% found this document useful (0 votes)
21 views29 pages

FileDirectory

This document summarizes key aspects of memory management in operating systems, including: 1. Memory managers coordinate how different types of memory are used, allocating and releasing areas of main memory to processes and managing swapping between main memory and disk. 2. Early systems had no memory abstractions and faced issues like internal fragmentation, static relocation, and inability to protect processes from each other. 3. Modern abstractions include base/limit registers, swapping, bitmaps, linked lists, and virtual memory using paging, with page replacement algorithms like LRU and clock.

Uploaded by

Tu Tu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views29 pages

FileDirectory

This document summarizes key aspects of memory management in operating systems, including: 1. Memory managers coordinate how different types of memory are used, allocating and releasing areas of main memory to processes and managing swapping between main memory and disk. 2. Early systems had no memory abstractions and faced issues like internal fragmentation, static relocation, and inability to protect processes from each other. 3. Modern abstractions include base/limit registers, swapping, bitmaps, linked lists, and virtual memory using paging, with page replacement algorithms like LRU and clock.

Uploaded by

Tu Tu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

File System

Files
Directories
Review
• Memory Manager
– coordinate how the different types of memory are used
– keep track memory to allocate and release areas of main
memory to processes
– manage swapping between main memory and disk
• No Memory Abstractions
– Single program
• One OS, only one process
• Special register is used to protection between OS and process
• Disadvantages: slow
– Multiple program
• One OS, many processes locate in memory
• Divided into fixed size block
• Disadvantages
– Internal fragmentations
– Two programs both reference absolute physical memory
 static relocation
Review
• Memory Abstractions
– Multiple processes locate in memory (both primary and secondary)
– Base and Limit Registers
• Multiple processes locate in memory and protection
• Base contains the first address of process in memory, Limit contains the
length of process, the process owns private address space
• Disadvantages
– External fragmentation (Defragment)
– Slow
– Swapping
• Multiple processes with ready processes locate in memory and passive
processes locate in HDD – swap file area
• Swap out/ in operator
• Disadvantages
– External fragmentation
– Process can not grow in memory and the swap area on the disk is full
 data segment upward, stack segment downward
Review
• Memory Abstractions
– Memory Management with Bitmaps
• The memory divides units with same size that has a bit corresponding bit
in the bitmap (0: free, 1: occupied)
• Disadvantages
– Slow when searching the bitmap to find a run of k consecutive 0 bits in
the map (small)
– External fragment (large size)
– Memory Management with Linked Lists
• Maintain a linked list of allocated (P) and free memory (H)
• Allocating algorithms
– First, Next, Best, Worst, Quick Fit
– Virtual Memory
• Software/ Process sizes larger than memory
• Overlays
– Developer splits program to many overlays
– Disadvantages: developer‘s knowledge is important
Review
• Memory Abstractions
– Virtual Memory
• Paging
– Address space is broken up into pages
– Physical memory is divided up into page frames
– Virtual address vs. Physical address, manage address space with bit
– MMU transfers Virtual address  p, d; then it looks up page table
following the index to get the page frame; the page frame combines
with d to determine the physical address
– Page fault: the program references a part of its address space that is
not in physical memory
– Page table
» Load to collection registers, load to memory using base register,
using TLB
» Excessive large page table: multilevel page, inverted page table,
inverted page table with hash or TLB
» Entry: Caching disabled, Referenced, Modified, Protection,
Present/absent, page frame number
• Memory Abstractions
Review
– Virtual Memory
• Paging
– Page replace algorithms
» Optimal: the page will be the latest one accessed in the future
» NRU: the page has lowest class that combines R and M bit
» FIFO: the page at the head of queue
» Second Chance: old page has not been not referenced in the
previous clock interval (R = 0). If R of page equals 1, R is reset
to 0 and put the tail of the queue.
» Clock (circular queue) : the page being pointed to by the hand is
inspected. If R = 0, page is evicted. Otherwise, R is reset to 0, the
pointer points next
» LRU: the page at the end of the list is replaced, the list must be
updated at each memory reference
» NFU, Aging (using bit): The page with the lowest counter
» Working set model, working set clock (circular queue): Third
Chance with Second Chance using age > τ with bit R
» Terminology: Thrashing, Locality of Reference, Demand paging,
prepaging, working set, page fault rate
Review
• Design Issues
– Local vs Global Policies
• Local: page frames are static allocated among current processes
(thrashing or waste memory)
• Global: page frames are dynamically allocated among runnable
processes (thrashing to others process)
– Solution
» Monitor the size of working set of all processes using aging bit
» The allocation is updated dynamically using PFF algorithms with
To periodically determine the number of running processes,
Giving each process a minimum number of frames
– Load Control
• Swapping and Considering not only process size and paging rate but also
its characteristics
– Page Size
• Optimizing the size of the page and the location of page table
Review
• Design Issues
– Separate Instruction and Data Spaces
• Sharing code, library, read only memory
• Copy on write
– Memory Mapped File
• Paging the file as process
– Cleaning Policy
• Using two-handed clock
– Front hand is controlled by the paging daemon
– Back hand is used for page replacement algorithm as in the standard clock algorithm

• Implementation Issues
– Instruction Backup
• A hidden internal is used to store the PC before each instruction is
executed
• A second register is used to store the registers auto-incremented or auto-
decremented, and by how much
• When the fault instruction is restarted, the OS can unambiguously undo
all the effects of it
Review
• Implementation Issues
– Locking Pages in Memory
• Lock pages engaged in I/O in memory so that they will not be removed
• Do all I/O to kernel buffers & copy the data to use pages later
– Backing Store
• Associated with each process is the disk address of its swap area, that is
where on the swap partition its image is kept (that also kept in process table)
• Paging to a static swap area vs. Backing up pages dynamically
– Segmentation
• Is a logical entity and Consists of a linear sequence addresses, from 0 to
some maximum that can grow and shrink independently without
effecting each other
• To specify an address in the segmented memory, the <segment-number,
offset> is used
• Implementing
– Segment table
– Segmentation with Paging
Objectives
• Files
– File Naming
– File Structure
– File Types
– File Access
– File Attributes
– File Operations
– An Example Program using File System Calls
• Directories
– Single-Level Directories Systems
– Hierarchical Directory Systems
– Path Names
– Directory Operations
Overview
• Problems
– While a process is running, it can store a limited amount of
information within its own address space. However, the storage
capacity is restricted to the size of the virtual address space
– The information is lost when the process terminates
– It is frequently necessary for multiple processes to access (parts of) the
information at the same time
• There are 3 essential requirements for long-term information
storage
– It must be possible to store a very large amount of information
– The information must be survive the termination of process using it
– Multiple processes must be able to access the information concurrently
• Disk and its 2 operation (read, write) are used to solve the long-term
storage problem
Files
Definition
• Are the abstraction (objects and mechanism), that models
in a convenient way the information stored and read it
back on hardware devices and are managed by OS
• Are logical units of information (created by processes)
• Processes can read existing files&create new ones if need be
• Information stored in files must be persistent (not be
affected by process creation and termination)
• File system
– The OS’s component that manages the information stored on the
storage devices and provides the users access to that information
in a convenient way
– Hides the complexity of storage hardware devices
– Provides the users a uniform logical view of the information
stored on these devices, based on the concept of file
– Maps files onto physical devices
Files
Naming
• When a process creates a file, it gives the file a name.
• When the process terminates, the file continues to exist
and can be accessed by other process using its name
• File name = string of characters
• The exact rules for file naming vary somewhat from
system to system
– Distinction between upper and lower letters
– Limit of name length
– Extension (optional)
• Provides some information about the file’s content structure
• Is used to register with OS and specify for each program owns that
extension
• Ex: hello.c; hello.bat, hello.txt
Files
Structure
• There are 3 common way possibilities
– An unstructured sequence of bytes
• Byte sequences (maximum flexibility)
• Can put any thing they want and name file any way
– Record sequence
• A file is a sequence of fixed length record, each with some internal
structure
• Provides read, write, and append operation
– Tree
• A file consists of a tree of records, not necessarily all the same length,
each containing a key field in a fixed position in the record
• The tree is sorted on the key field, to allow rapid searching for a
particular key
• Provides the get operation to get the record with specifies key
• OS decides the new record’s position
Files
Structure

Tanenbaum, Fig. 4-2.


Files
Types
• OS supports several types of files
– Regular files
• Contain user data information (ASCII or binary)
– Directories
• System files for maintaining the structure of the file system
– Character Special files
• Are related of I/O ad used to model serial I/O devices
• Ex: terminals, printer, networks
– Block Special files
• Disks Model
Files
Access
• Sequential access
– Reads the bytes or records in order, starting at the
beginning, but could not skip around and read them
out of order
– Could be rewound
– Specific to magnetic tapes
– Operation: read
• Random access
– Reads the bytes or records out of order, or to access
records by key rather than by position
– Specific to disks
– Operation: seek
Files
Attributes
• The extra information is associated to file by OS
• Is also called metadata
• Some attributes
– Type
– Length
– Time stamps
• creation time, time of last access, time of last modification
– Owner
– Access rights
• read (view), write (modify), execute, delete
– Different flags
• hidden, system, locked etc.
– …..
Files
Operations
• Create
• Delete
• Open
• Close
• Read
• Write
• Seek
• Get attributes
• Set attributes
• Rename
Files
An Example Program Using System Calls

Tanenbaum, Fig. 4-5.


Files
An Example Program Using System Calls

Tanenbaum, Fig. 4-5.


Directories
Definition
• A way of organizing files
• Impose a hierarchy of files
• Consists of a collection of files and
subdirectories
• Can be viewed as a special file managed by
the OS
Directories/ Folders
Single-Level Directory Systems
• Is having one directory containing all files (root directory)
• Applying on system that can be used by only one or many
users
• Is adequate for simple dedicated applications
• Advantages
– Simplicity
– The ability to locate file quickly
• Disadvantages
– The file name can be duplicated in one/ many users

Tanenbaum, Fig. 4-6.


Directories/ Folders
Hierarchical Directory Systems
• Single-Level
• Hierarchical
– It would be impossible to find
anything if all files were in a single
directory (slow) → group related
files together
– There can be as many directories as
are needed group the files in natural
ways
– If multiple users share a common
file server, as is the case many
computer networks, each user can
have a private root directory for
his or her own hierarchy Tanenbaum, Fig. 4-7.
– The ability for users to create an
arbitrary number of
subdirectories provides a powerful
structuring tool for users to
organize their work
Directories/ Folders
Path Names
• Absolute path name
– Starts from the root directory to the file
– Ex
• /home/students/john/program.c (in Linux)
• C:\Program Files\Application\run.exe (in Windows)
• Relative path name
– Starts from the current (working) directory that can be
owned to users
– Each application has its own working directory
– Ex
• john/program.c (in Linux)
• application\run.exe (in Windows)
– Special directories in relative paths
• current directory: .
• parent directory: ..
Directories/ Folders
Path Names

Tanenbaum, Fig. 4-8.


Directories/ Folders
Operations
• Create
• Delete
• Opendir
• Closedir
• Readdir
• Rename
• Link: Allow a file to appear in more than one directory
• Unlink
Summary
• Operating System Concepts
• Files
• Directories

Q&A
Next Lecture
• File System Implementation

You might also like