Memory management, part 3: outline

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Part IV: Memory Management
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Paging Hardware With TLB
CSC 322 Operating Systems Concepts Lecture - 18: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Memory Management Design & Implementation Segmentation Chapter 4.
Chapter 8.3: Memory Management
Memory Management (II)
1 Pertemuan 16 Isu-Isu pada Sistem Paging dan Segmentasi Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5.
Memory Management.
Chapter 3.2 : Virtual Memory
Memory Management (continued) CS-3013 C-term Memory Management CS-3013 Operating Systems C-term 2008 (Slides include materials from Operating System.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Silberschatz, Galvin and Gagne  Operating System Concepts Segmentation Memory-management scheme that supports user view of memory. A program.
A. Frank - P. Weisberg Operating Systems Simple/Basic Segmentation.
Main Memory. Background Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only.
1 Memory Management in Representative Operating Systems.
Chapter 3 Memory Management 3.7 Segmentation. A compiler has many tables that are built up as compilation proceeds, possibly including: The source text.
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
Virtual Memory  Early computers had a small and fixed amount to memory. All programs had to be able to fit in this memory. Overlays were used when the.
Operating System Machine Level  An operating system is a program that, from the programmer’s point of view, adds a variety of new instructions and features,
Chapter 8: Main Memory.
CS333 Intro to Operating Systems Jonathan Walpole.
CS 346 – Chapter 8 Main memory –Addressing –Swapping –Allocation and fragmentation –Paging –Segmentation Commitment –Please finish chapter 8.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-7 Memory Management (1) Department of Computer Science and Software.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
Cosc 3P92 Week 9 & 10 Lecture slides
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
Memory Management 3 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
CS212: OPERATING SYSTEM Lecture 5: Memory Management Strategies 1 Computer Science Department.
Page 110/20/2015 CSE 30341: Operating Systems Principles So far…  Page  Fixed size pages solve page allocation problem (and external fragmentation) 
1 Memory Management 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement algorithms.
8.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Implementation of Page Table Page table is kept in main memory Page-table base.
CE Operating Systems Lecture 14 Memory management.
1 Memory Management (b). 2 Paging  Logical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Chapter 4 Memory Management Segmentation. (a) One address space. (b) Separate I and D spaces. Separate Instruction and Data Spaces.
9.1 Operating System Concepts Paging Example. 9.2 Operating System Concepts.
Demand Paging Reference Reference on UNIX memory management
操作系统原理 OPERATING SYSTEM Chapter 3 Memory Management 内存管理.
Page Replacement Implementation Issues Text: –Tanenbaum ch. 4.7.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Fragmentation External Fragmentation – total memory space exists to satisfy.
COS 318: Operating Systems Virtual Memory Design Issues.
 Segmentation  Case studies o MULTICS o Pentium o Unix o Linux o Windows Memory management, part 3: outline 1 Operating Systems, 2015, Danny Hendler,
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
W4118 Operating Systems Instructor: Junfeng Yang.
UNIT–IV: Memory Management
Chapter 8: Memory Management
COMBINED PAGING AND SEGMENTATION
Simple/Basic Segmentation
Chapter 8: Main Memory.
Page Replacement Implementation Issues
Virtual Memory Chapter 8.
Paging and Segmentation
Chapter 8: Main Memory.
Operating System Concepts
Main Memory Background Swapping Contiguous Allocation Paging
Page Replacement Implementation Issues
Memory management, part 3: outline
Main Memory Session - 16.
Lecture 3: Main Memory.
Chapter 8: Memory Management strategies
COMP755 Advanced Operating Systems
CSE 542: Operating Systems
Presentation transcript:

Memory management, part 3: outline Segmentation Case studies MULTICS Pentium Unix Linux Windows Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Segmentation Several address spaces per process a compiler needs segments for source text symbol table constants segment stack parse tree compiler executable code Most of these segments grow during execution symbol table symbol table Source Text source text constant table parse tree call stack Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Users view of segments Symbol table Parse tree Source text Call stack Constants A segmented memory allows each table to grow or shrink independently of the other tables. Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Segmentation - segment table Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Segmentation Hardware Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Segmentation vs. Paging consideration Paging Segmentation Need the program be aware of the technique ? no yes How many per-process virtual address spaces ? 1 many Can the total address space exceed physical memory ? Can procedures and data be distinguished ? Sharing of procedures among users facilitated ? Motivation for the technique Get larger linear space, eliminate external fragmentation Programs and data in logical independent address spaces, sharing and protection made simpler Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Segmentation pros and cons Advantages: Growing and shrinking independently. Sharing between processes simpler Linking is easier Protection easier Disadvantages: Pure segmentation --> external Fragmentation revisited Segments may be very large. What if they don't fit into physical memory? Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Segmentation Architecture Logical address composed of the pair <segment-number, offset> Segment table – maps to linear address space; each table entry has: base – contains the starting linear address where the segment resides in memory. limit – specifies the length of the segment. Segment-table base register (STBR) points to the segment table’s location in memory. Segment-table length register (STLR) indicates number of segments used by a program; segment number s is legal if s < STLR. Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Segmentation Architecture (Cont.) Protection: each segment table entry contains: validation bit = 0  illegal segment read/write/execute privileges Protection bits associated with segments; code sharing occurs at segment level. Since segments vary in length, memory allocation is a dynamic storage-allocation problem (external fragmentation problem) Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Sharing of segments Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Segmentation with Paging Segments may be too large Cause external fragmentation The two approaches may be combined: Segment table. Pages inside a segment. Solves fragmentation problems. Most systems today provide a combination of segmentation and paging Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Memory management, part 3: outline Segmentation Case studies MULTICS Pentium Unix Linux Windows Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

The MULTICS OS Ran on Honeywell computers Segmentation + paging Up to 218 segments Segment length up to 216 36-bit words Each program has a segments table (itself a segment) Each segment has a page table Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

MULTICS data-structures 36 bits Page 2 entry Page 2 entry Page 1entry Page 1entry Page 0 entry Page 0 entry Segment 4 descriptor 18 bits Page table for segment 3 Page table for segment 1 Segment 3 descriptor Segment 2 descriptor 18 bits Segment 1 descriptor Segment 0 descriptor Process descriptor segment 18 bits 6 bits 1 1 1 3 3 Main memory address of the page table Segment length (in pages) Page size: 0 – 1024 word 1 – 64 words 0 – paged 1 – not paged Segment descriptor misc Unused Protection bits Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

MULTICS memory reference procedure 1. Use segment number to find segment descriptor Segment table is itself paged because it may be large. The descriptor-base-register points to its page table. 2. Check if segment’s page table is in memory if not a segment fault occurs if there is a protection violation TRAP (fault) 3. page table entry examined, a page fault may occur. if page is in memory the start-of-page address is extracted from page table entry 4. offset is added to the page origin to construct main memory address 5. perform read/store etc. Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

MULTICS Address Translation Scheme Segment number (18 bits) Page number (6 bits) Page offset (10 bits) Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

MULTICS TLB Simplified version of the MULTICS TLB Existence of 2 page sizes makes actual TLB more complicated Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Multics - Additional checks during segment link (call) Since segments are mapped to files, ACLs (access-control list) are checked with first access (open) Protection rings are checked A very advanced 1970's Architecture. Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Memory management, part 3: outline Segmentation Case studies MULTICS Pentium Unix Linux Windows Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Pentium: Segmentation + paging Segmentation with or without paging is possible 16K segments per process, segment size up to 4G 32-bit words page size 4K A single global GDT, each process has its own LDT 6 segment registers may store (16 bit) segment selectors: CS, DS, SS… When the selector is loaded to a segment register, the corresponding descriptor is stored in microprogram registers Privilege level (0-3) 0 = GDT/ 1 = LDT 13 1 2 Index Pentium segment selector Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Pentium- segment descriptors Pentium code segment descriptor. Data segments differ slightly Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Pentium - Forming the linear address Segment descriptor is in internal (microcode) register If segment is not zero (TRAP) or paged out (TRAP) Offset size is checked against limit field of descriptor Base field of descriptor is added to offset (4k page-size) Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Intel Pentium address translation 10 10 12 Can cover up to 4 MB physical address space Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Memory management, part 3: outline Segmentation Case studies MULTICS Pentium Unix Linux Windows Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

UNIX process address space BSS Init. Data Text Stack pointer 8K 20K Process B Stack pointer 20K BSS Init. Data 8K Text OS Physical memory Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Memory-mapped file OS Process A Process B Stack pointer Stack pointer BSS Data Text Stack pointer 8K 20K Process B Stack pointer Memory mapped file Memory mapped file 20K BSS Data 8K Text OS Physical memory Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Unix memory management sys calls Not specified by POSIX Common Unix system calls s=brk(addr) – change data segment size. (addr sepcified the first address following new size) a=mmap(addr,len,prot,flags,fd,offset) – map (open) file fd starting from offset in length len to virtual address addr (0 if OS is to set address) s=unmap(addr,len) – unmap a file (or a portion of it) Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Unix 4BSD memory organization Main memory Core map entry Index of next entry Used when page frame is on free list Index of previous entry Page frame 3 Disk block number Page frame 2 Disk device number Page frame 1 Block hash code Page frame 0 Index into proc table Text/data/stack Core map entries, one per page frame Offset within segment Misc. Kernel Free In transit Wanted Locked Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Unix Page Daemon It is assumed useful to keep a pool of free pages freeing of page frames is done by a pagedaemon - a process that sleeps most of the time awakened periodically to inspect the state of memory - if less than ¼ 'th of page frames are free, then it frees page frames this strategy performs better than evicting pages when needed (and writing the modified to disk in a hurry) The net result is the use of all of available memory as page-pool Uses a global clock algorithm – two-handed clock Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Page replacement - Unix a two-handed clock algorithm clears the reference bit first with the first hand and frees pages with its second hand. It has the parameter of the “angle” between the hands - small angle leaves only “busy” pages If page is referenced before 2’nd hand comes, it will not be freed Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Page replacement – Unix, cont'd if there is thrashing, the swapper process removes processes to secondary storage Remove processes idle for 20 sec or more If none – swap out the oldest process out of the 4 largest Who get swapped back function of: Time out of memory size Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Memory management, part 3: outline Segmentation Case studies MULTICS Pentium Unix Linux Windows Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Linux processes Each process gets 3GB virtual memory Remaining 1GB for kernel and page tables Virtual address space composed of areas with same protection, paging properties (pageable or not, direction of growth) Each process has a linked list of areas, sorted by virtual address (text, data, memory-mapped-files,…) Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

vm_area_struct Process virtual address space partitioned to areas struct vm_area_struct { unsigned long vm_start; unsigned long vm_end; unsigned long vm_flags; struct vm_area_struct *vm_next; /* plus some other fields */ }; Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Linux page tables organization Page middle directory Page Directory Page table Selected word Directory Middle Page Offset This is the situation in Alpha. In Pentium, the page middle directory is degenerated. Expanded to 4-level indirect paging after Linux 2.6.10 Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Linux main memory management Kernel never swapped The rest: user pages, file system buffers, variable-size device drivers The buddy algorithm is used. In addition: Linked lists of same-size free blocks are maintained To reduce internal fragmentation, a second memory allocation scheme (slab allocator) manages smaller units inside buddy-blocks Demand paging (no pre-paging) Dynamic backing store management Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Linux page replacement algorithm Variant of clock algorithm Based on aging, pages are in either active or inactive list Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Memory management, part 3: outline Segmentation Case studies MULTICS Pentium Unix Linux Windows Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Win 2000: virtual address space Virtual address space layout for 3 user processes White areas are private per process Shaded areas are shared among all processes What are the pros/cons of mapping kernel area into process address space? Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Win 2000: memory mngmt. concepts Each virtual page can be in one of following states: Free/invalid – Currently not in use, a reference causes access violation Committed – code/data was mapped to virtual page Reserved – allocated to thread, not mapped yet. When a new thread starts, 1MB of process space is reserved to its stack Readable/writable/executable Dynamic (just-in-time) backing store management Improves performance of writing modified data in chunks Up to 16 pagefiles Supports memory-mapped files Can use 4K or 4M pages Executable access pattern recorded for SuperFetch prepaging Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Win 2000: page replacement alg. Processes have working sets defined by two parameters - the minimal and maximal # of pages the WS of processes is updated at the occurrence of each page fault (i.e. the data structure WS) - PF and WS < Min add to WS PF and WS > Max remove from WS If a process thrashes, its working set size is increased Memory is managed by keeping a number of free pages, which is a complex function of memory use, at all times when the balance-set-manager is run (every second) and it needs to free pages - surplus pages (to the WS) are removed from a process (large background before small foreground…) Pages `age-counters’ are maintained (on a multi-processor refs bits don’t work since they are local…) Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Implementation of Memory Management A page table entry for a mapped page on the Pentium Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels

Physical Memory Management (1) Various page lists and transitions between them Ben-Gurion University Operating Systems, 2011, Danny Hendler and Amnon Meisels