Segmentation. Multiple Segments. Lecture Notes Week 6

Similar documents
Virtual Memory. 1 Notes 4

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 13: Address Translation

Memory Management Basics

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

ECE 598 Advanced Operating Systems Lecture 10

Memory Allocation. Static Allocation. Dynamic Allocation. Dynamic Storage Allocation. CS 414: Operating Systems Spring 2008

Virtual Memory. 11/8/16 (election day) Vote!

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

Requirements, Partitioning, paging, and segmentation

Memory: Overview. CS439: Principles of Computer Systems February 26, 2018

Memory Management. Reading: Silberschatz chapter 9 Reading: Stallings. chapter 7 EEL 358

CS399 New Beginnings. Jonathan Walpole

! What is main memory? ! What is static and dynamic allocation? ! What is segmentation? Maria Hybinette, UGA. High Address (0x7fffffff) !

A.Arpaci-Dusseau. Mapping from logical address space to physical address space. CS 537:Operating Systems lecture12.fm.2

Memory Management. Today. Next Time. Basic memory management Swapping Kernel memory allocation. Virtual memory

11.1 Segmentation: Generalized Base/Bounds

Preview. Memory Management

CS162 Operating Systems and Systems Programming Lecture 12. Address Translation. Page 1

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

Memory Management. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Requirements, Partitioning, paging, and segmentation

CS 550 Operating Systems Spring Memory Management: Paging

CS Operating Systems

CS Operating Systems

Memory Management. Dr. Yingwu Zhu

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

CIS Operating Systems Non-contiguous Memory Allocation. Professor Qiang Zeng Spring 2018

Heap Management. Heap Allocation

Memory Management Topics. CS 537 Lecture 11 Memory. Virtualizing Resources

Chapter 8: Memory Management

The Memory Management Unit. Operating Systems. Autumn CS4023

Optimizing Dynamic Memory Management

Fall 2017 :: CSE 306. Introduction to. Virtual Memory. Nima Honarmand (Based on slides by Prof. Andrea Arpaci-Dusseau)

Chapter 8: Main Memory

Operating systems. Part 1. Module 11 Main memory introduction. Tami Sorgente 1

Chapter 8 Main Memory

Heap Management portion of the store lives indefinitely until the program explicitly deletes it C++ and Java new Such objects are stored on a heap

Chapter 8: Memory-Management Strategies

15 Sharing Main Memory Segmentation and Paging

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

Memory Management (1) Memory Management

Memory Management (1) Memory Management. CPU vs. memory. No.8. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Classifying Information Stored in Memory! Memory Management in a Uniprogrammed System! Segments of a Process! Processing a User Program!

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

Memory Management: The process by which memory is shared, allocated, and released. Not applicable to cache memory.

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

Simple idea 1: load-time linking. Our main questions. Some terminology. Simple idea 2: base + bound register. Protection mechanics.

Background. Contiguous Memory Allocation

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

Virtual Memory. CS 351: Systems Programming Michael Saelee

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

CS307: Operating Systems

In multiprogramming systems, processes share a common store. Processes need space for:

Chapter 8: Main Memory

Lecture 7. Memory Management

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

Memory Management. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

Dynamic Memory Allocation

CS370 Operating Systems

Memory Management Minsoo Ryu Real-Time Computing and Communications Lab. Hanyang University

Performance of Various Levels of Storage. Movement between levels of storage hierarchy can be explicit or implicit

16 Sharing Main Memory Segmentation and Paging

Memory Management. COMP755 Advanced Operating Systems

Motivation for Dynamic Memory. Dynamic Memory Allocation. Stack Organization. Stack Discussion. Questions answered in this lecture:

OPERATING SYSTEMS. After A.S.Tanenbaum, Modern Operating Systems 3rd edition Uses content with permission from Assoc. Prof. Florin Fortis, PhD

Processes and Tasks What comprises the state of a running program (a process or task)?

Operating Systems. Memory Management. Lecture 9 Michael O Boyle

CIS Operating Systems Memory Management. Professor Qiang Zeng Fall 2017

(page 0 of the address space) (page 1) (page 2) (page 3) Figure 12.1: A Simple 64-byte Address Space

Chapter 8: Memory Management. Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging

memory management Vaibhav Bajpai

Frequently asked questions from the previous class survey

CS252 S05. Main memory management. Memory hardware. The scale of things. Memory hardware (cont.) Bottleneck

Deallocation Mechanisms. User-controlled Deallocation. Automatic Garbage Collection

CS61C : Machine Structures

Dynamic Memory Management! Goals of this Lecture!

Programs in memory. The layout of memory is roughly:

6. Which of the following operating systems was the predecessor of Microsoft MS-DOS? a. Dynix b. Minix c. CP/M

Chapter 3 - Memory Management

COMPUTER SCIENCE 4500 OPERATING SYSTEMS

Chapter 8: Memory Management. Operating System Concepts with Java 8 th Edition

CIS Operating Systems Contiguous Memory Allocation. Professor Qiang Zeng Spring 2018

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

UNIT III MEMORY MANAGEMENT

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

Chapter 8: Memory- Management Strategies

12: Memory Management

Memory Management william stallings, maurizio pizzonia - sistemi operativi

CSCE Operating Systems Non-contiguous Memory Allocation. Qiang Zeng, Ph.D. Fall 2018

CS61C Midterm Review on C & Memory Management

The Art and Science of Memory Allocation

Memory Management. Kevin Webb Swarthmore College February 27, 2018

Chapter 9 Memory Management

Engine Support System. asyrani.com

Introduction to Operating Systems

Segmentation with Paging. Review. Segmentation with Page (MULTICS) Segmentation with Page (MULTICS) Segmentation with Page (MULTICS)

Memory Management. Dr. Yingwu Zhu

SHANDONG UNIVERSITY 1

143A: Principles of Operating Systems. Lecture 5: Address translation. Anton Burtsev October, 2018

Transcription:

At this point, we have the concept of virtual memory. The CPU emits virtual memory addresses instead of physical memory addresses. The MMU translates between virtual and physical addresses. Don't forget, we still require that the entire process t into physical memory. Segmentation Thus far, each process has one segment (think block) that can be variablesize. Initially, each segment was the same size, so external fragmentation was minimized. But since the segment size had to be some worst-case, we had a large problem with internal fragmentation. The solution was to make each segment of variable size. This is accomplished through the use of base and bounds or base and limit registers that are now private to each process space and used in the MMU. This helped some with internal fragmentation but made external fragmentation problematic. When one process exits, there is no guarantee that a new process will have a segment that ts into the space freed. Oh yeah, how do we allocate these \holes" { rst-t, best-t, worst-t? One solution to the external fragmentation problem is to periodically compact memory. That is, move all the used space to one end and all the unused space to the other end. Lots and lots of copy operations (move from memory into CPU then move from CPU to new memory location). This means lots and lots of time with the CPU not working on user processes. How often do you compress? Do all processes have to be modied to compress memory? Is there a selection strategy (e.g., more overhead)? Compress all or \just enough for now"? So now we have some hardware help in terms of an MMU which contains a single base-bounds register pair. This pair must be saved/restored on a context switch. Let's consider the amount of space between the stack and heap inside the process (internal fragmentation). We can do better. Multiple Segments If we let each part of our process occupy a segment by itself and thus allow the entire process to be composed of many segments, we can achieve better memory utilization. So now, each process has many base/bounds register pairs { more hardware support. Let's put it into the MMU. In the Intel X86 architecture, we have segment registers cs, ss, ds, es, fs, and gs. Discussion of the limits will have to wait until we have discussed descriptor tables. 1

The MMU now supports a process containing many, variable-length segments. More hardware support but more work on a context switch. Did it buy us anything? For large address spaces, only a fraction is used. Our new model helps greatly with internal fragmentation. 1. The code segment size is known at compile time. 2. The heap and stack segments can be given \reasonable" default sizes that suits most processes. May have compiler support. 3. If a stack or heap needs to grow: Is the space \next" to the top of the heap or bottom of the stack free? Change the bounds. Worst case is that the segment is copied to a larger segment and the old segment freed. Ugh. Still, it's an improvement. Example This example uses a 14-bit address space. Physical 100 4200 Virtual 2

Segment Identiers How do we know which segment? Make it part of the virtual address. Figure 1: 2-bits for Segment Selector Figure 2: VA 4200 The Stack The stack grows downward, which slightly complicates our address math. The stack is allocated at physical address 28K which is the bottom of the stack. The stack grows downward towards 26K. We need to know in which direction a stack grows. More hardware to the rescue. Let's access an address in our stack: VA 15KB which maps to PA 27KB 15KB: 11 1100 0000 0000 (0x3C00) Segment Selector: 11 Oset: 1100 0000 0000 (0xC00, 3072 10 ) Max Segment Size (MSS): 1111 1111 1111 (4KB, 4096 10 ) 1. Oset - MSS = 3072 4096 = 1024 (negative oset) 3

2. Base + negative oset = 28KB + ( 1KB) = 27KB For VA 15KB, we now see how to nd the correct address in the stack segment, namely 27KB. More Stu For the MMU We now have the MMU doing a lot of work for address translation. It turns out that we would also like to know what we can do to a memory location. For example, in most programming languages, we do not want the code segment to be modied during execution. Interestingly, under our segmentation model the type of protection we want can be specied at the segment level and so only adds a few bits of overhead for this very valuable capability. One Little Heap Problem Remember how we can allocate memory in the heap and then also deallocate it? It is possible for our heap to become quite sparse. With our segment model, we can't deal with this. Do we really want to periodically compact a heap and update all those memory addresses in our program? This is pretty ugly. Compaction We still haven't managed to solve the compaction problem. It is a very serious problem that can greatly aect performance. Since the OS can't know when it will need to compact, we must assume it will be at the most inconvenient time. Next, we will look at a mechanism at all but does away with both internal and external fragmentation, but has problems of its own. Free Space Memory that is not allocated is said to be free. The management of freespaceis critical to overall performance of our system. Fixed-sized Segments With xed-sized segments, memory can be partitioned into N pieces, each of which is the same size. If we limit physical memory to being an integer 4

multiple of the segment size, then the number of segments that t into memory is easily calculable as is the location of each segment. Each segment can then be marked as free or in-use and this is the only free-space management that is required. However, as we have seen, xed-sized segments are far from optimal. Variable-sized Segments With variable-sized segments, memory is not so easily partitioned and thus a more complex method for tracking and allocating memory to segments is required. This method is required whether or not a process is comprised of as little as one or even many variable-sized partitions. Since the standard term for a \partition" is segment, we will adopt that term from here on out. Minimizing Fragmentation For now, we will assume that variable-sized segmentation is sucient for addressing internal fragmentation (hint: it's not) and deal with external fragmentation. Part of the problem with variable-sized segments is that when they are freed (deallocated), they leave behind variable-sized holes. As segments are allocated and freed, our free memory becomes more and more fragmented, nding a suitable hole for allocation to a segment becomes a much harder task. At some point, there may be enough memory to satisfy an allocation request but the request cannot be satised because it isn't available in a large enough contiguous block. This leads to the very expensive compaction problem. If a system doesn't have a lot of physical memory and isn't very busy, this may not be burdensome. However, for most systems, compaction represents a major problem and one for which it is worth developing strategies to ameliorate. Free List Management Physical memory can be viewed as a byte-array that is initially contiguous and free. Any allocation of this memory results in the splitting of memory. Since the lifetime of some sections of allocated memory will be longer than others, it is reasonable to assume that holes will appear over time. Nothing can really be done about these holes except track them and possibly combine adjacent ones. One way to track free space is to use a simple linked list. Each node contains the start address and length of the hole. 5

Not bad. However, there are some problems, including how to traverse the list and what to do if there are two holes that are adjacent. If we use a simple linked list, then we will always traverse from the head of the list. Over time, it will take longer and longer to nd a suitable hole. When two holes are adjacent, we can choose to combine them in a technique called coalescing. The technique is fairly simple but requires a check on every deallocation. And nally, there is the problem of how much of a hole to allocate. Too many small holes and the overhead is quite large. Do we allocate entire holes or partial holes? If partial holes, do we allocate from the beginning or end of the hole? Does it matter? Does it impact coalescing? The Magic of malloc() The system call malloc() allocates space from the heap (sbrk() makes the heap bigger as necessary). Malloc needs to track the size of the space so that when free() is called that this space can be freed in its entirety. The trick, so to speak, is to allocate additional space (overhead) when allocating a block of memory. This header is xed-size. As a result, the start of the actual block of memory can be calculate from the address that malloc() returned to the calling program. How does malloc() track the free space inside an already allocated region (e.g., the heap)? The technique used is to embed the list within the region itself. 6

typedef n o d e t f i n t s i z e ; s t r u c t n o d e t next ; g node t ; 7

Allocation Strategies 1. Best t (n) 2. Worst t (n) 3. First t (1) 4. Next t (1) 5. Multiple lists: Buddy Allocator Paging Advantages of pages; internal and external fragmentation Mapping to physical memory: page frames MMU now tracks page fram numbers (PFNs) in page tables VA translation: 8

Page Tables PTE: Slow and big Need a way to make them both faster and smaller 9