memory
play

Memory Thursday, 14 February 19 Challenge managing memory see - PowerPoint PPT Presentation

IN2140: Introduction to Operating Systems and Data Communication Operating Systems: Memory Thursday, 14 February 19 Challenge managing memory see which seats are available How to find one particular person allocate a seat


  1. IN2140: Introduction to Operating Systems and Data Communication Operating Systems: Memory Thursday, 14 February 19

  2. Challenge – managing memory see which seats are available How to… find one particular person allocate a seat • • • … • University of Oslo IN2140, Pål Halvorsen

  3. Overview § Hierarchies § Multiprogramming and memory management § Addressing § A process’ memory § Partitioning § Paging and Segmentation § Virtual memory § Page replacement algorithms § Paging example in IA32 § Data paths University of Oslo IN2140, Pål Halvorsen

  4. Memory Management § Memory management is concerned with managing the systems’ memory resources − allocate space to processes − protect the memory regions − provide a virtual view of memory giving the impression of having more than the number of available bytes − control different levels of memory in a hierarchy University of Oslo IN2140, Pål Halvorsen

  5. Memory Hierarchies § A process typically needs a lot of memory: We can’t access the disk every time we need data § Typical computer systems therefore have several different components where data may be stored speed price tertiary storage (tapes) − different capacities − different speeds − less capacity gives faster access secondary storage 10 7 x and higher cost per byte (disks) § Lower levels have a copy of data in higher levels main memory 100x capacity § A typical memory hierarchy: cache(s) 2x University of Oslo IN2140, Pål Halvorsen

  6. Memory Hierarchies tertiary storage (tapes) secondary storage 5 ms 3.5 months (disks) main memory 50 ns 1.5 minutes cache(s) On die memory - 1 ns 2 s 0.3 ns < 1 s University of Oslo IN2140, Pål Halvorsen

  7. Memory Hierarchies Tapes? Well, they … tertiary storage (tapes) • store a LOOOT of data 5 ms 3.5 months (IBM TS3500 Tape Library: 2.25 exabytes) • are SLOOOOOOOW… (seconds à minutes à hours) secondary storage à Going to other far away galaxies… 50 ns 1.5 minutes (disks) à “5 sec ≈ ~290 years” On die memory - 1 ns 2 s main memory ~0.3 ns < 1 s cache(s) University of Oslo IN2140, Pål Halvorsen

  8. Storage Costs: Access Time vs Capacity offline tape 10 15 typical capacity (bytes) 10 13 magnetic disks 10 11 online tape 10 9 main memory 10 7 10 5 cache 10 -9 10 3 10 -6 10 -3 10 access time (sec) from Gray & Reuter University of Oslo IN2140, Pål Halvorsen

  9. Storage Costs: Access Time vs Price 10 4 cache 10 2 dollars/Mbytes main memory online tape 10 0 magnetic disks 10 -2 offline tape 10 -9 10 3 10 -6 10 -3 10 access time (sec) from Gray & Reuter University of Oslo IN2140, Pål Halvorsen

  10. Absolute and Relative Addressing § Hardware often uses absolute addressing 0x000… − reserved memory regions − reading data by referencing the offset from memory’s start address byte numbers in memory − read absolute byte 0x000000ff − fast!!! offset from process’ start address § What about software? process A − read absolute byte 0x000fffff (process A) ð result dependent of a process' physical location − absolute addressing not convenient − but, addressing within a process is determined during process A programming!!?? Ä Relative addressing − independent of process position in memory − address is expressed relative to some base location − dynamic address translation – find absolute address during run-time adding the relative and base addresses 0xfff… University of Oslo IN2140, Pål Halvorsen

  11. Processes’ Memory Layout § On most architectures, a process partitions its low address available memory (address space), but for what? system data segment (PCB) − a text (code) segment • read from program file … 8048314 <add>: for example by exec code segment 8048314: push %ebp • usually read-only 8048315: mov %esp,%ebp • can be shared 8048317: mov 0xc(%ebp),%eax initialized variables − a data segment 804831a: add 0x8(%ebp),%eax data segment 804831d: pop %ebp • initialized global/static variables (data) uninitialized variables 804831e: ret • uninitialized global/static variables (BSS) data segment 804831f <main>: • heap process A 804831f: push %ebp dynamic memory, e.g., allocated using malloc § heap 8048320: mov %esp,%ebp grows against higher addresses § 8048322: sub $0x18,%esp − a stack segment 8048325: and $0xfffffff0,%esp 8048328: mov $0x0,%eax • stores parameters/variables in a function 804832d: sub %eax,%esp • stores register states (e.g., calling function’s EIP) 804832f: movl $0x0,0xfffffffc(%ebp) • grows against lower addresses 8048336: movl $0x2 ,0x4(%esp,1) − system data segment (PCB) 804833e: movl $0x4 ,(%esp,1) • segment pointers 8048345: call 8048314 <add> • pid 804834a: mov %eax,0xfffffffc(%ebp) • program and stack pointers 804834d: leave • … 804834e: ret − possibly more stacks for threads 804834f: nop stack ... possible thread stacks, − command line arguments and arguments environment variables at highest addresses high address University of Oslo IN2140, Pål Halvorsen

  12. Processes’ Memory Layout § On most architectures, a task partitions its low address available memory (address space), but for what? system data segment (PCB) − a text (code) segment • read from program file for example by exec code segment • usually read-only • can be shared initialized variables − a data segment data segment • initialized global variables (data) uninitialized variables • uninitialized global variables (bss) data segment • heap process A dynamic memory, e.g., allocated using malloc § heap grows against higher addresses § − a stack segment • variables in a function • stored register states (e.g., calling function’s EIP) • grows against lower addresses − system data segment (PCB) • segment pointers • pid • program and stack pointers • … − possibly more stacks for threads stack possible thread − command line arguments and stacks, arguments environment variables at highest addresses high address University of Oslo IN2140, Pål Halvorsen

  13. Global Memory Layout § Memory is usually divided into regions 0x000… system control information − operating system occupies low memory • system control • resident routines resident operating system (kernel) − the remaining area is used for transient operating system routines and application programs § How to assign memory to concurrent processes? transient area ( application programs – and transient operating system routines) 0xfff… University of Oslo IN2140, Pål Halvorsen

  14. The Challenge of Multiprogramming § Many “tasks” require memory − several processes concurrently loaded into memory − memory is needed for different tasks within a process − process memory demand may change over time ➥ OS must arrange (dynamic) memory sharing University of Oslo IN2140, Pål Halvorsen

  15. Memory Management for Multiprogramming § Use of secondary storage − keeping all programs and their data in memory may be impossible − move (parts of) a process from memory § Swapping: remove a process from memory − with all of its state and data − store it on a secondary medium (disk, flash RAM, … , historically also tape) § Overlays: manually replace parts of code/data − programmer’s rather than OS’s work − only for very old and memory-scarce systems § Segmentation/paging: remove parts of a process from memory − store it on a secondary medium − sizes of such parts are usually fixed University of Oslo IN2140, Pål Halvorsen

  16. Fixed Partitioning § Divide memory into static partitions at system initialization time Equal sized: Unequal sized: (boot or earlier) Operating system Operating system 8MB 8MB 2MB § Advantages 8MB 4MB − easy to implement 6MB − can support swapping of processes 8MB 8MB § Equal-size partitions 8MB − large programs cannot be executed 8MB (unless parts of a program are loaded from disk) 8MB − small programs don't use the entire partition (problem called “internal fragmentation”) 12MB 8MB § Unequal-size partitions 8MB − large programs can be loaded at once 16MB − less internal fragmentation 8MB − require assignment of jobs to partitions − one queue or one queue per partition − …but, what if only small or large processes? University of Oslo IN2140, Pål Halvorsen

  17. Dynamic Partitioning § Divide memory at run-time − partitions are created dynamically Operating system 8MB − removed after jobs are finished Process 5 § External fragmentation increases Process 1 External 14MB 20MB free with system running time 20MB fragmentation 6MB free Process 4 Process 2 8MB 14MB free 56MB free 14MB 6MB free 36MB free Process 3 18MB 22MB free 4MB free University of Oslo IN2140, Pål Halvorsen

  18. Dynamic Partitioning § Divide memory at run-time Operating system − partitions are created dynamically 8MB − removed after jobs are finished Process 5 § External fragmentation increases 14MB with system running time Process 4 6MB § Compaction removes fragments by moving 8MB data in memory Process 4 6MB free − takes time 8MB Process 3 − consumes processing resources 6MB free 18MB Process 3 6MB free 18MB 16MB free 6MB free 4MB free University of Oslo IN2140, Pål Halvorsen

Recommend


More recommend