CSNB334 Advanced Operating Systems 5. Memory Management

Slides:



Advertisements
Similar presentations
Memory Management Chapter 7.
Advertisements

Memory Management Chapter 7. Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as.
Chapter 7 Memory Management
OS Fall’02 Memory Management Operating Systems Fall 2002.
Chapter 7 Memory Management
Lecture 11: Memory Management
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Memory Management 2010.
Chapter 3.2 : Virtual Memory
1 Chapter 8 Virtual Memory Virtual memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory.
Memory Management Chapter 5.
Computer Organization and Architecture
Chapter 91 Translation Lookaside Buffer (described later with virtual memory) Frame.
1 Lecture 8: Memory Mangement Operating System I Spring 2008.
Operating System Chapter 7. Memory Management Lynn Choi School of Electrical Engineering.
Review of Memory Management, Virtual Memory CS448.
Memory Management Chapter 7.
1 Memory Management Memory Management COSC513 – Spring 2004 Student Name: Nan Qiao Student ID#: Professor: Dr. Morteza Anvari.
CSNB334 Advanced Operating Systems 5. Memory Management
Chapter 7 Memory Management
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
Page 1 2P13 Week 6. Page 2 Table 7.1 Memory Management Terms Frame A fixed-length block of main memory. Page A fixed-length block of data that resides.
Page 1 2P13 Week 5. Page 2 Page 3 Page 4 Page 5.
Memory Management. Roadmap Basic requirements of Memory Management Memory Partitioning Basic blocks of memory management –Paging –Segmentation.
Subject: Operating System.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Chapter 4 Memory Management Virtual Memory.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Memory Management. Why memory management? n Processes need to be loaded in memory to execute n Multiprogramming n The task of subdividing the user area.
Informationsteknologi Wednesday, October 3, 2007Computer Systems/Operating Systems - Class 121 Today’s class Memory management Virtual memory.
Memory management Ref: Stallings G.Anuradha. What is memory management? The task of subdivision of user portion of memory to accommodate multiple processes.
Chapter 7 Memory Management Eighth Edition William Stallings Operating Systems: Internals and Design Principles.
1 Memory Management n In most schemes, the kernel occupies some fixed portion of main memory and the rest is shared by multiple processes.
2010INT Operating Systems, School of Information Technology, Griffith University – Gold Coast Copyright © William Stallings /2 Memory Management.
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.
MEMORY MANAGEMENT. memory management  In a multiprogramming system, in order to share the processor, a number of processes must be kept in memory. 
Virtual Memory Chapter 8.
Chapter 7 Memory Management
Memory Management Chapter 7.
ITEC 202 Operating Systems
Chapter 2 Memory and process management
Requirements, Partitioning, paging, and segmentation
Chapter 8: Main Memory.
COMBINED PAGING AND SEGMENTATION
Chapter 8 Main Memory.
Virtual Memory Chapter 8.
Main Memory Management
Chapter 8: Main Memory.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy 11/12/2018.
Operating System Concepts
Memory Management 11/17/2018 A. Berrached:CS4315:UHD.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Computer Architecture
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Main Memory Background Swapping Contiguous Allocation Paging
Lecture 3: Main Memory.
Operating System Chapter 7. Memory Management
Chapter 8: Memory Management strategies
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
COMP755 Advanced Operating Systems
Operating Systems: Internals and Design Principles, 6/E
CSE 542: Operating Systems
Virtual Memory 1 1.
Page Main Memory.
Presentation transcript:

CSNB334 Advanced Operating Systems 5. Memory Management Semester 2, 2007/2008 Lecturer: Asma Shakil

Review of basic concepts What are the requirements of memory management? Relocation For managing the available memory in a multiprogramming environment. Protection Must be satisfied by the hardware (processor) rather than the OS. Permissibility of a memory reference by an instruction can only be checked at the time of execution of the instruction. Sharing Physical Organization Moving information between the main memory and secondary memory.

Memory Management Techniques Fixed partitioning Main memory is divided into a number of static partitions at system generation time. Equal-size partitions Unequal-size partitions Pros Simple to implement; little OS overhead Cons Inefficient : internal fragmentation Maximum number of active processes – fixed. Placement Algorithm One process queue per partition. Single queue.

Memory Management Techniques Dynamic partitioning Partitions are created dynamically Each process is loaded into a partition of exactly the same size as that process. Pros No internal fragmentation. Cons External fragmentation. Counteract : by compaction. But an overhead for the processor. Placement Algorithm : (because compaction is time consuming) Best-fit First-fit. Next-fit.

Relocation Phenomenon by which a process may occupy different partitions during the course of its life. Three types of addresses Logical Address Reference to a memory location independent of the current assignment of the process to memory. Relative Address Type of logical address – address is expressed as a location relative to some known point. Physical Address/ Absolute Addres Actual location in main memory.

Loading Absolute Loading Relocatable Loading. Dynamic Run-Time loading Decision of where to load a module in the memory is made at compile time. Thus, a given module is always loaded into a specific location in main memory. Relocatable Loading. Decision is made at load time. Thus a module can be loaded anywhere in the main memory. But, is swapped back to the same memory. Dynamic Run-Time loading Decision is made at run-time. Therefore, we can swap a process image into different locations at different times. Done by special processor hardware rather than software. Base Register, Bounds Register, Adder, Comparator.

Memory Management Techniques Paging Main memory is divided into a number of equal-sized, relatively small frames. Each process is divided into a number of equal-sized pages – same length as a frame. A process is loaded by loading all of its pages into available frames. Not necessarily be contiguous. Possible thru the use of a page table for each process. Logical address (page number, offset) --- Physical Address (frame number, offset). Pros No external fragmentation Cons A small amount of internal fragmentation.

Address Translation in a Paging System Logical address Page # Offset Frame # Offset Register Page Table Ptr Page Table Offset Page Frame P# + Frame # Program Paging Main Memory

Memory Management Techniques Segmentation Each process is divided into number of segments. Need not be of same size. A process is loaded by loading all of its segments into dynamic partitions. Need not be contiguous Use segment table. Difference with dynamic partitioning A process may occupy more than one partition. Partitions need not be contiguous. Pros No internal fragmentation. Cons External fragmentation : though less severe than dynamic partitioning because of the small size of the segments.

Hardware support Program Segmentation Main Memory Virtual Address Segment Table Seg # Offset = d + Base + d Register Seg Table Ptr Segment Table d Segment S# + Length Base Program Segmentation Main Memory

Memory Management Techniques Virtual memory Similar to paging/segmentation except that it is not necessary to load all of the segments/pages of a process into main memory. Nonresident pages/segments that are needed are brought in later automatically. May require writing a page/segment out to disk if the memory is full. Pros: Large virtual address space. More processes may be maintained in main memory. A process may be larger than all of main memory. Cons Overhead of complex memory management. Thrashing : The system spends most of its time swapping pieces rather than executing instructions.

Translation Lookaside Buffer Every virtual memory reference causes two physical memory access: To fetch the appropriate page table entry. To fetch the desired data. Thus, the memory access time is doubled. To overcome this: Use a special high-speed cache for page table entries – Translation Lookaside Buffer Similar to a memory cache. Contains those page table entries – most recently used.

Use of a Translation Lookaside Buffer

Virtual Memory Virtual memory can be based on Paging only Segmentation Virtual Address : Page Number + Offset Page table entry : P(bit)+M(bit)+ Frame Number Segmentation Virtual Address : Segment Number + Offset Segment table entry : P(bit)+M(bit)+ Length + Segment Base Or, a combination of the two. Virtual Address : Segment Number + PageNumber + Offset Segment table entry : Length + Segment Base

Memory Management in Linux Linux uses demand paged virtual memory for memory management design. It's a dynamic memory allocation technique that consists of deferring page frame allocation until the last possible moment, for example, when a process attemps to access a page that is not present in RAM. Basic unit of memory allocation – page. Page size : 212 (4096 bytes or 4KB). Allocation of blocks in physical memory is as page frames Protection mechanism is page by page Sharing is also based on pages Swapping controls automatic movement through the memory hierarchy.

Getting the Page size The standard POSIX method Linux also provides #include <unistd.h> long sysconf (int name); long page_size = sysconf(_SC_PAGESIZE); Linux also provides int getpagesize (void); Returns the page size in bytes. PAGE_SIZE macro defined in <asm/page.h> int page_size = PAGE_SIZE Retrieves the page size at compile time.

Abstract view of memory management

Managing the Virtual Address Space in Linux Each process : its own virtual address space. In i386 arch, the virtual address is 32-bits wide. Therefore, the total virtual memory that a virtual address can reference = 232 = 4GB. Page Size = 212. Therefore, number of pages that a virtual address can reference = 220. Assuming that each PTE is 4 bytes, how many pages are needed to store the page table? Each entry in the theoretical page table contains the following information: Valid flag. This indicates if this page table entry is valid, The physical page frame number that this entry is describing, Access control information. This describes how the page may be used. Can it be written to? Does it contain executable code?

Segmentation in Linux Linux uses the segmentation model in a limited way. Each virtual address space is divided into segments: 1GB kernel segment : 2 sectors (code and data/stack) for KERNEL SPACE from [0xC000 0000] (3 GB) to [0xFFFF FFFF] (4 GB) 3 GB user segment : 2 sectors (code and data/stack) for USER SPACE from [0] (0 GB) to [0xBFFF FFFF] (3 GB) 4 GB Kernel Space (Code + Data) Kernel 3 GB 2 GB Tasks User Space (Code + Data) 1 GB ox00000000

Per-Process Virtual Memory Layout Code (also called text) segment Static Data segments Initialized global (and C static) variables Uninitialized global variables (zeroed when initializing the process, also called bss) Stack segment: function calls, local variables (also called automatic in C) Heap segment (malloc())

Two Level Page Table The amount of memory devoted to page tables alone is quite high. Therefore, page tables are stored in virtual memory rather than main memory. This is achieved thru the use of a two-level hierarchical page table. Root Page Table (4KB) User Page Table (4MB) User Address Space (4 GB)

Hierarchical paging Address translation scheme:

Virtual -> physical address translation ……is a three level process in Linux

Virtual address 4 parts: Page directory offset j.pgd Page middle director offset j.pmd Page table offset j.pte Offset within page j.offset The physical address i for a virtual address j is : i = PTE(PMD(PGD(j.pgd)+j.pmd)+j.pte)+j.offset.

The x86(32-bit addressing) only supports a two level conversion of the address. This is dictated by the hardware’s MMU… This is accomplished by reducing each page middle directory to only a single entry.

Page Table Flags PAGE_NONE – No physical memory page associated with entry. PAGE_SHARED – All types of access permitted. PAGE_READONLY – No writing. “Copy-on-Write” can be used. PAGE_KERNEL – kernel segment only allowed access. PAGE_KERNEL_RO – kernel read-only access.