Lecture 26

advertisement
Lecture 26



Any issues with finding case study references?
Schedule for rest of term posted. Mostly back
on schedule, but note days with no lecture.
Questions?
Friday, March 16
CS 470 Operating Systems - Lecture 26
1
Outline

Kernel memory allocation

Buddy system

Slab allocation

Storage systems

File ADT


File access methods
Directory ADT

Directory structures
Friday, March 16
CS 470 Operating Systems - Lecture 26
2
Kernel Memory Allocation

Last time, briefly discussed whether OS should
compete with user processes for free frames.
Generally, it does not for the following reasons:


Many kernel data structures are less than a page,
so the OS must manage its memory usage carefully
to minimize waste. Often kernel memory is not
handled by the paging system.
Due to interaction with hardware devices, kernel
memory may need to be physically contiguous.
Friday, March 16
CS 470 Operating Systems - Lecture 26
3
Buddy System


Allocation is from a fixed-size segment of
physically contiguous pages using a power-of2 allocator. This allocator satisfies requests in
units sized as a power of 2 (4KB, 8KB, 16KB,
etc.)
For example, suppose original memory
segment size is 256KB and there is a request
for 21KB. System divides segment into two
128KB segments, call them Aleft and Aright.
Friday, March 16
CS 470 Operating Systems - Lecture 26
4
Buddy System

Aleft is further divided into 64KB segments B left
and Bright, then Bleft is divided into 32KB
segments Cleft and Cright. Cleft is used to fulfill the
21KB request.
Original 256KB segment
Aleft - 128KB
Bleft - 64KB
Aright - 128KB
Bright - 64KB
Cleft - 32KB Cright - 32KB
Friday, March 16
CS 470 Operating Systems - Lecture 26
5
Buddy System



Advantage of this system is that adjacent
buddies can be combined quickly to form larger
segments using coalescing. For example,
when the kernel releases Cleft, it can be
combined with Cright, then Bright, then Aright to
recover the original 256KB segment.
Disadvantage is that can have lots of internal
fragmentation due to the coarse segment sizes.
Original Linux kernel used this allocator.
Friday, March 16
CS 470 Operating Systems - Lecture 26
6
Slab Allocation


Define a slab as 1 or more physically
contiguous pages. Define a cache connected
with 1 or more slabs. Each cache holds objects
of a unique kernel data structure type (e.g.
process descriptor, file objects, semaphores,
etc.) usually based on size.
Kernel objects are instantiated (i.e., preallocated) in the caches and initially marked as
free. As objects are allocated, the cache
entries are marked as used.
Friday, March 16
CS 470 Operating Systems - Lecture 26
7
Slab Allocation
Friday, March 16
CS 470 Operating Systems - Lecture 26
8
Slab Allocation


The number objects stored in a cache depends
on the size of the slab (and the size of the
objects in the cache).
A particular slab may be:

full - all objects in the slab are marked as used

empty - all objects in the slab are marked as free

partial - slab contains both used and free objects
Friday, March 16
CS 470 Operating Systems - Lecture 26
9
Slab Allocation

Allocation requests are fulfilled using (in order):

free object in a partial slab

free object in an empty slab


free object in a newly created slab that is also
assigned to a cache
Advantages


No wasted memory due to fragmentation. Objects
in each cache are exactly the correct size.
Fast allocation, especially when objects are
allocated and deallocated frequently.
Friday, March 16
CS 470 Operating Systems - Lecture 26
10
Slab Allocation


Slab allocation first appeared in the Solaris 2.4
kernel. Now also used in the Linux kernel, and
for certain types of user-mode requests.
This ends the section on memory management.
The next section is on storage systems.
Friday, March 16
CS 470 Operating Systems - Lecture 26
11
Storage Systems


Storage systems logically are three parts

User/programmer API - Chapter 10

OS implementation of API - Chapter 11

Actual disk structures - Chapter 12
File system is a logical view of information
storage. The logical storage unit is a file
mapped to a physical device. For most
"normal" applications, it is the smallest unit of
information. I.e., must have a file to write to a
"disk".
Friday, March 16
CS 470 Operating Systems - Lecture 26
12
Storage Systems


Files are general. View them as containers of
bits, bytes, lines, or records. A file's format is
defined by its creator.
Files are organized into directories. Both can
be view as abstract data types (ADTs).
Friday, March 16
CS 470 Operating Systems - Lecture 26
13
File ADT


Like all ADTs, can discuss a file object's
attributes and its operations.
What might be the attributes of a file object?
Friday, March 16
CS 470 Operating Systems - Lecture 26
14
File ADT

What might be a file object's operations?
Friday, March 16
CS 470 Operating Systems - Lecture 26
15
File ADT


Many operations need to search a directory, so
most OS's require an open( ) operation. This
operation finds its file name argument in a
directory and enters it into an open file table
(OFT).
For multi-user OS's, the OFT is usually 2-level



Global system OFT for all open files, keeps track of
location, permissions, size, open count, locks
Process local OFT, keeps track access rights (e.g.,
open for read-only, etc.)
In UNIX, file descriptor is index into local OFT
Friday, March 16
CS 470 Operating Systems - Lecture 26
16
File ADT

Some OS's have memory-mapped files. Disk
pages are loaded into physical memory frames.
Processes map VM pages to these frames.
Writes to these pages become writes to a file,
which are saved when the file is unmapped
(i.e., closed).
Friday, March 16
CS 470 Operating Systems - Lecture 26
17
File Access Methods


Data in files are access using an access
method. Access methods often depend on the
hardware the data are stored on.
Sequential access allows access to one
logical data unit at a time (e.g., byte, record).
After each read/write operation, there is
automatic advancement of a current position
pointer. E.g., C++ streams are logically one
character at a time. Sometimes can reset, skip
forward, etc. Model is based on a tape drive.
Friday, March 16
CS 470 Operating Systems - Lecture 26
18
File Access Methods

Direct access (also called relative or random
access) allows specification of a position
anywhere in a file for a read/write operations. A
location can be specified to each operation as
an argument, or a seek may be required to set
the current position pointer before each
operation. Model is based on a disk drive.
Friday, March 16
CS 470 Operating Systems - Lecture 26
19
File Access Methods


To make sequential file access faster when
records are not stored in sorted order, indexed
sequential access stores an index of <key,
pointer> pairs at the beginning of the file, where
key is a unique identifier of the information in a
record, and pointer is its location in the file.
To find a record, a binary search is done on the
index to find its pointer. This is much faster
than doing a linear search of the file and often
the index is small enough to be kept in memory.
This model is a precursor to databases.
Friday, March 16
CS 470 Operating Systems - Lecture 26
20
Directory ADT

Directory ADT organizes files. Usually consists
of two parts



Partition (also called minidisk or volume) is a
virtual disk. Could be one physical disk, part of a
physical disk, or more than one physical disk.
Symbol table mapping names to directory entries.
Like a table of contents for a partition. Each
directory entry is a list of files and/or directories.
What are some Directory operations?
Friday, March 16
CS 470 Operating Systems - Lecture 26
21
Directory Structures



There are various logical structures for
directories.
Single-level structure has only one directory
level and all files are under the root.
What are some limitations of this structure?
Friday, March 16
CS 470 Operating Systems - Lecture 26
22
Directory Structures

Two-level structure has a master file directory
(MFD) that maps username/account number of
a user file directory (UFD) of files owned by that
user.
Friday, March 16
CS 470 Operating Systems - Lecture 26
23
Directory Structures


Only the UFD is searched when a user program
performs a file operation. Solves the name
collision problem between users. What are
some limitations of this structure?
The generalized two-level structure is the
familiar tree structure. Users can create
subdirectories in their UFD. Names become
path names that can be absolute or relative.
Introduce new directory operations: current
directory, change directory. New issue: what
happens when we try to delete a directory?
Friday, March 16
CS 470 Operating Systems - Lecture 26
24
Directory Structures

Sometimes users may want to share
subdirectories (i.e., have them mapped into
their UFDs). Acyclic-graph structure provides
this functionality. UNIX allows this through the
use of links. Links may be hard, creating a full
directory entry to the shared data, or soft,
creating a directory entry that is simply a path
name to the shared data.
Friday, March 16
CS 470 Operating Systems - Lecture 26
25
Directory Structures


Main issues are in directory traversal - an entry
may appear more than once, and in deletion who has the right to delete the shared data.
In UNIX, hard links are counted and a file is
removed from the physical disk only when there
are no hard links to it. Deleting a file simply
removes its directory entry and decrements the
link count. Soft links can become "dangling
pointers", if the named directory entry is
removed.
Friday, March 16
CS 470 Operating Systems - Lecture 26
26
Related documents
Download