1 / 24

CMSC421: Principles of Operating Systems

CMSC421: Principles of Operating Systems. Nilanjan Banerjee. Assistant Professor, University of Maryland Baltimore County nilanb@umbc.edu http://www.csee.umbc.edu/~nilanb/teaching/421/. Principles of Operating Systems

zoltan
Télécharger la présentation

CMSC421: Principles of Operating Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CMSC421: Principles of Operating Systems Nilanjan Banerjee Assistant Professor, University of Maryland Baltimore County nilanb@umbc.edu http://www.csee.umbc.edu/~nilanb/teaching/421/ Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof. Mark Corner and Prof. Emery Berger’s OS course at Umass Amherst

  2. Announcements • Project 2 progress report due on Nov. 9th • Homework 3 will be out soon (hopefully before the end of this week)

  3. Quick Activity • How much mem does a page table need? • 4kB pages, 32 bit address space • page table entry (PTE) uses 4 bytes • 2^32/2^12*4=2^22 bytes=4MB • Is this a problem? • Isn’t this per process? • What about a 64 bit address space? • Any ideas how to fix this?

  4. Locality • Most programs obey 90/10 “rule” • 90% of time spent accessing 10% of memory • Exploit this rule: • Only keep “live” parts of process in memory A A B B 4

  5. Multi-Level Page Tables • Use a multi-level page table A A Level 0 Table Level 1 Table A Level 1 Table

  6. Quick Activity • How much mem does a page table need? • 4kB pages, 32 bit address space • Two level page table • 20bits = 10 bits each level • page table entry (PTE) uses 4 bytes • Only first page of program is valid • 2^10*4+2^10*4=2^13 bytes=8kB • Isn’t this slow?

  7. Translation Lookaside Buffer (TLB) • TLB: fast, fully associative memory • Caches page table entries • Stores page numbers (key) and frame (value) in which they are stored • Assumption: locality of reference • Locality in memory accesses =locality in address translation • TLB sizes: 8 to 2048 entries • Powers of 2 simplifies translationof virtual to physical addresses

  8. Linear Address in Linux • Uses a three-level paging strategy that works well for 32-bit and 64-bit systems • Linear address broken into four parts:

  9. Three-level Paging in Linux

  10. Inverted Page Tables Maintain one global page table for all processes

  11. Swap Space

  12. Page table entry and page faults 12

  13. User-space memory allocation in the heap (malloc) What happens int *arg = (int *)malloc(sizeof(int)) • Programs ask memory manager • to allocate/free objects (or multiple pages) • Memory manager asks OS • to allocate/free pages (or multiple pages) User Program malloc, free Allocator(libc) Pages (mmap,brk) OS 13

  14. User-space memory allocation in the heap (malloc) kernel stack sbrk(100) brk allocated sbrk(100) brk allocated brk sbrk(100) allocated sbrk(0) sbrk(0) Text region A demo? 14

  15. User-space memory allocation in the heap (malloc) kernel stack Memory allocator keeps track of the free blocks brk allocated free free allocated sbrk(0) Text region 15

  16. Few Scenarios kernel stack brk allocated malloc(200) Waste of resources allocated free free sbrk(0) Text region 16

  17. Coalescing kernel stack brk malloc(200) Waste of resources allocated free sbrk(0) Text region 17

  18. Jobs of a memory allocator like malloc • Manage heap space in virtual memory • Use sbrk to ask for more memory from OS • Coalescing • Keep track of free blocks • Merge them together when adjacent blocks are free • Malloc needs to be really fast • Decide which free block to allocate • Lets take a look at the data structure that is used for implementing malloc and free

  19. Memory layout of the heap this linked list can be ordered in different ways http://gee.cs.oswego.edu/dl/html/malloc.html

  20. Selecting the free block to allocate: Fragmentation • Intuitively, fragmentation stems from “breaking” up heap into unusable spaces • More fragmentation = worse utilization • External fragmentation • Wasted space outside allocated objects • Internal fragmentation • Wasted space inside an object

  21. Classical Algorithms • First-fit • find first chunk of desired size

  22. Classical Algorithms • Best-fit • find chunk that fits best • Minimizes wasted space

  23. Classical Algorithms • Worst-fit • find chunk that fits worst • name is a misnomer! • keeps large holes around • Reclaim space: coalesce free adjacent objects into one big object

  24. In-class Discussion

More Related