Lecture 26OutlineKernel Memory AllocationBuddy System 1Buddy System 2Buddy System 3Slab Allocation 1Slab Allocation 2Slab Allocation 3Slab Allocation 4Slab Allocation 5Storage Systems 1Storage Systems 2File ADT 1File ADT 2File ADT 3File ADT 4File Access Methods 1File Access Methods 2File Access Methods 3Directory ADTDirectory Structures 1Directory Structures 2Directory Structures 3Directory Structures 4Directory Structures 5Friday, March 18 CS 470 Operating Systems - Lecture 26 1Lecture 26Any issues with finding case study references?Questions?Friday, March 18 CS 470 Operating Systems - Lecture 26 2OutlineKernel memory allocationBuddy systemSlab allocationStorage systemsFile ADTFile access methodsDirectory ADTDirectory structuresFriday, March 18 CS 470 Operating Systems - Lecture 26 3Kernel Memory AllocationLast 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 18 CS 470 Operating Systems - Lecture 26 4Buddy SystemAllocation is from a fixed-size segment of physically contiguous pages using a power-of-2 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 18 CS 470 Operating Systems - Lecture 26 5Buddy SystemAleft is further divided into 64KB segments Bleft and Bright, then Bleft is divided into 32KB segments Cleft and Cright. Cleft is used to fulfill the 21KB request.Original 256KB segmentAleft - 128KB Aright - 128KBBleft - 64KB Bright - 64KBCleft - 32KBCright - 32KBFriday, March 18 CS 470 Operating Systems - Lecture 26 6Buddy SystemAdvantage 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 18 CS 470 Operating Systems - Lecture 26 7Slab AllocationDefine 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., pre-allocated) in the caches and initially marked as free. As objects are allocated, the cache entries are marked as used.Friday, March 18 CS 470 Operating Systems - Lecture 26 8Slab AllocationFriday, March 18 CS 470 Operating Systems - Lecture 26 9Slab AllocationThe 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 usedempty - all objects in the slab are marked as freepartial - slab contains both used and free objectsFriday, March 18 CS 470 Operating Systems - Lecture 26 10Slab AllocationAllocation requests are fulfilled using (in order):free object in a partial slabfree object in an empty slabfree object in a newly created slab that is also assigned to a cacheAdvantagesNo 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 18 CS 470 Operating Systems - Lecture 26 11Slab AllocationSlab 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 18 CS 470 Operating Systems - Lecture 26 12Storage SystemsStorage systems logically are three partsUser/programmer API - Chapter 10OS implementation of API - Chapter 11Actual disk structures - Chapter 12File 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 18 CS 470 Operating Systems - Lecture 26 13Storage SystemsFiles 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 18 CS 470 Operating Systems - Lecture 26 14File ADTLike all ADTs, can discuss a file object's attributes and its operations.What might be the attributes of a file object?Friday, March 18 CS 470 Operating Systems - Lecture 26 15File ADTWhat might be a file object's operations?Friday, March 18 CS 470 Operating Systems - Lecture 26 16File ADTMany 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-levelGlobal system OFT for all open files, keeps track of location, permissions, size, open count, locksProcess local OFT, keeps track access rights (e.g., open for read-only, etc.)In UNIX, file descriptor is index into local OFTFriday, March 18 CS 470 Operating Systems - Lecture 26 17File ADTSome 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 18 CS 470 Operating Systems - Lecture 26 18File Access MethodsData 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
View Full Document