Memory management, part 3: outline

Similar documents
Memory management, part 3: outline

Modeling Page Replacement: Stack Algorithms. Design Issues for Paging Systems

Multi-Process Systems: Memory (2) Memory & paging structures: free frames. Memory & paging structures. Physical memory

Virtual Memory Management

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management

Chapter 4 Memory Management. Memory Management

Page Table Structure. Hierarchical Paging. Hashed Page Tables. Inverted Page Tables

Memory Management. Chapter 4 Memory Management. Multiprogramming with Fixed Partitions. Ideally programmers want memory that is.

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition

CS307: Operating Systems

Chapter 8 Main Memory

Chapter 8: Main Memory

Chapter 8: Memory- Manage g me m nt n S tra r t a e t gie i s

Chapter 8: Memory-Management Strategies

Segmentation ITCS /25/2013. Group #2: Daniel Scroggins Farida Bestowros Rowena Winston Vitali Kuyel Willie Holguin

Chapter 8: Memory Management

Chapter 8: Main Memory. Operating System Concepts 9 th Edition

Clock page algorithm. Least recently used (LRU) NFU algorithm. Aging (NFU + forgetting) Working set. Process behavior

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts

Chapter 8: Main Memory

Segmentation (Apr 5 and 7, 2005)

CHAPTER 8: MEMORY MANAGEMENT. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

Memory Management and Protection

Memory management, part 2: outline. Operating Systems, 2017, Danny Hendler and Amnon Meisels

Page Size Page Size Design Issues

SHANDONG UNIVERSITY 1

Operating Systems, Fall Lecture 5, Tiina Niklander 1

Memory management, part 2: outline

Move back and forth between memory and disk. Memory Hierarchy. Two Classes. Don t

Memory Management Ch. 3

Operating Systems, Fall Lecture 5 1. Overhead due to page table and internal fragmentation. Tbl 8.2 [Stal05] 4.

Operating Systems, Fall Lecture 5 1

Chapter 9 Memory Management

CS450/550 Operating Systems

Chapter 8: Main Memory. Operating System Concepts 8th Edition

Memory Management Virtual Memory

Module 8: Memory Management

8.1 Background. Part Four - Memory Management. Chapter 8: Memory-Management Management Strategies. Chapter 8: Memory Management

Chapter 9 Memory Management Main Memory Operating system concepts. Sixth Edition. Silberschatz, Galvin, and Gagne 8.1

Virtual Memory Outline

Chapter 8: Virtual Memory. Operating System Concepts

Chapter 8: Main Memory

Main Memory. CISC3595, Spring 2015 X. Zhang Fordham University

Chapter 8: Main Memory

CSE 380 Computer Operating Systems

Outline. V Computer Systems Organization II (Honors) (Introductory Operating Systems) Advantages of Multi-level Page Tables

OPERATING SYSTEM. Chapter 9: Virtual Memory

VII. Memory Management

Chapter 9: Memory Management. Background

Topics: Memory Management (SGG, Chapter 08) 8.1, 8.2, 8.3, 8.5, 8.6 CS 3733 Operating Systems

Chapter 8: Memory Management Strategies

CS399 New Beginnings. Jonathan Walpole

Operating Systems. IV. Memory Management

Lecture 8 Memory Management Strategies (chapter 8)

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

MEMORY MANAGEMENT/1 CS 409, FALL 2013

CS 3733 Operating Systems:

CS3600 SYSTEMS AND NETWORKS

The Operating System. Chapter 6

Chapter 9: Virtual Memory

Virtual Memory I. Jo, Heeseung

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Chapter 8: Memory- Management Strategies

CS307: Operating Systems

The cow and Zaphod... Virtual Memory #2 Feb. 21, 2007

Operating Systems Lecture 6: Memory Management II

Operating Systems CSE 410, Spring Virtual Memory. Stephen Wagner Michigan State University

Chapter 8 Virtual Memory

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Memory Management Cache Base and Limit Registers base limit Binding of Instructions and Data to Memory Compile time absolute code Load time

Module 8: Memory Management

CIS Operating Systems Memory Management Address Translation for Paging. Professor Qiang Zeng Spring 2018

Module 9: Memory Management. Background. Binding of Instructions and Data to Memory

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Virtual Memory Design and Implementation

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

Virtual to physical address translation

Process size is independent of the main memory present in the system.

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 8: MEMORY

Background. Contiguous Memory Allocation

Memory Management. Memory Management

Recap: Memory Management

Chapters 9 & 10: Memory Management and Virtual Memory

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Virtual Memory #2 Feb. 21, 2018

Part Three - Memory Management. Chapter 8: Memory-Management Strategies

Motivation. Memory Management. Memory Management. Computer Hardware Review

Operating System Concepts 9 th Edition

VIRTUAL MEMORY. Operating Systems 2015 Spring by Euiseong Seo

Computer Organization and Architecture. OS Objectives and Functions Convenience Making the computer easier to use

CS370 Operating Systems

Operating System 1 (ECS-501)

Logical versus Physical Address Space

Principles of Operating Systems

File Systems. OS Overview I/O. Swap. Management. Operations CPU. Hard Drive. Management. Memory. Hard Drive. CSI3131 Topics. Structure.

I.-C. Lin, Assistant Professor. Textbook: Operating System Principles 7ed CHAPTER 8: MEMORY

Memory: Paging System

Transcription:

Memory management, part 3: outline Segmentation Case studies o MULTICS o x86 (Pentium) o Unix o Linux o Windows 1

Segmentation Several address spaces per process a compiler needs segments for o source text o symbol table o constants segment o stack o parse tree o compiler executable code Most of these segments grow during execution 2

Users' view of segments 3

Segmentation - segment table 4

Segmentation Hardware 5

Segmentation vs. Paging 6

Segmentation pros and cons Advantages: o Growing and shrinking independently o Sharing between processes simpler o Linking is easier o Protection easier Disadvantages: o Pure segmentation --> external Fragmentation revisited o Segments may be very large. What if they don't fit into physical memory? 7

Segmentation Architecture Logical address composed of the pair <segment-number, offset> Segment table maps to linear address space; each table entry has: o base contains the starting linear address where the segment resides in memory. o 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. 8

Segmentation Architecture (Cont.) Protection: each segment table entry contains: o validation bit = 0 illegal segment o 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) 9

Sharing of segments 10

Segmentation with Paging Segments may be too large Cause external fragmentation The two approaches may be combined: o Segment table. o Pages inside a segment. o Solves fragmentation problems. Many systems provide a combination of segmentation and paging 11

Memory management, part 3: outline Segmentation Case studies o MULTICS o x86 (Pentium) o Unix o Linux o Windows 12

The MULTICS OS Ran on Honeywell computers Segmentation + paging Up to 2 18 segments Segment length up to 2 16 36-bit words Each program has a segments table (itself a segment) Each segment has a page table 13

MULTICS data-structures 36 bits Page 2 entry Page 2 entry Page 1entry Page 1entry Segment 4 descriptor Segment 3 descriptor 18 bits Page 0 entry Page table for segment 3 Page 0 entry Page table for segment 1 Segment 2 descriptor Segment 1 descriptor 18 bits Segment 0 descriptor Process descriptor segment (Process segment table) 18 bits Main memory address of the page table Page size: 0 1024 word 1 64 words 0 paged 1 not paged 9 bits 1 1 1 3 3 Segment length (in pages) Segment descriptor Unused misc Protection bits 14

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 o if not a segment fault occurs o if there is a protection violation TRAP (fault) 3. page table entry examined, a page fault may occur. o 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. 15

MULTICS Address Translation Scheme Segment number (18 bits) Page number (6 bits) Page offset (10 bits) 16

MULTICS TLB Simplified version of the MULTICS TLB Existence of 2 page sizes makes actual TLB more complicated 17

Memory management, part 3: outline Segmentation Case studies o MULTICS o x86 (Pentium) o Unix o Linux o Windows 19

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 13 0 = GDT/ 1 = LDT 1 2 Privilege level (0-3) Index Pentium segment selector 20

Pentium- segment descriptors 21

Pentium - Forming the linear address Segment descriptor is in internal (microcode) register If segment is not zero (TRAP) or paged out (TRAP) o Offset size is checked against limit field of descriptor o Base field of descriptor is added to offset (4k page-size) 22

Intel Pentium address translation 10 10 12 Can cover up to 4 MB physical address space 23

Memory management, part 3: outline Segmentation Case studies o MULTICS o x86 (Pentium) o Unix o Linux o Windows 24

UNIX process address space Stack pointer Process A Process B Stack pointer 20K 8K 0 BSS Init. Data Text OS BSS Init. Data Text 20K 8K 0 Physical memory 25

Memory-mapped file Stack pointer Process A Process B Stack pointer Memory mapped file Memory mapped file 20K 8K 0 BSS Data Text OS BSS Data Text 20K 8K 0 Physical memory 26

Unix memory management sys calls Not specified by POSIX Common Unix system calls o s=brk(addr) change data segment size. (addr sepcified the first address following new size) o 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) o s=unmap(addr,len) unmap a file (or a portion of it) 27

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

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 29

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 o If page is referenced before 2 nd hand comes, it will not be freed 30

Page replacement Unix, cont'd if there is thrashing, the swapper process removes processes to secondary storage o Remove processes idle for 20 sec or more o If none swap out the oldest process out of the 4 largest Who get swapped back is a function of: o Time out of memory o size 31

Memory management, part 3: outline Segmentation Case studies o MULTICS o x86 (Pentium) o Unix o Linux o Windows 32

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, ) 33

Linux page tables organization Expanded to 4-level indirect paging in Linux 2.6.10. In Pentium, the two middle levels are degenerated. 36

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: o Linked lists of same-size free blocks are maintained o 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 37

Linux page replacement algorithm Variant of clock algorithm Order of inspection of the page-freeing daemon is o By size of process from large to small o In virtual address order (maybe unused ones are neighbors ) Freed pages are categorized into clean; dirty; unbackedup Another daemon writes up dirty pages periodically 38

Memory management, part 3: outline Segmentation Case studies o MULTICS o x86 (Pentium) o Unix o Linux o Windows 39

Win 8: 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? 40

Win 8: memory mngmt. concepts Each virtual page can be in one of following states: o Free/invalid Currently not in use, a reference causes access violation o Committed code/data was mapped to virtual page o Reserved allocated to thread, not mapped yet. When a new thread starts, 1MB of process space is reserved to its stack o Readable/writable/executable Dynamic (just-in-time) backing store management o Improves performance of writing modified data in chunks o Up to 16 pagefiles Supports memory-mapped files 41

Win 8: 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) - o PF and WS < Min add to WS o PF and WS > Max replace in 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 - o surplus pages (to the WS) are removed from a process (large background before small foreground ) o Pages `age-counters are maintained 43

Physical Memory Management (1) Various page lists and transitions between them 44