Operating Systems Chapter 4: Memory Management E 4.1 Basic memory management 4.2 Swapping(交换) 43 irtual memory(虚拟内存) H 4.4 Page replacement algorithms H 4.5 Design issues for paging systems E 4.6 Implementation issues 47 Segmentation(分段) Gao Haichang, Software School, Xidian University 3
Operating Systems Gao Haichang , Software School, Xidian University 3 Chapter 4: Memory Management 4.1 Basic memory management 4.2 Swapping (交换) 4.3 Virtual memory (虚拟内存) 4.4 Page replacement algorithms 4.5 Design issues for paging systems 4.6 Implementation issues 4.7 Segmentation (分段)
Operating Systems Memory Management c Ideally programmers want memory that is A large t fast 口 non volatile Memory hierarchy(层次) H small amount of fast, expensive memory -cache E some medium-speed medium price main memory H gigabytes ofslow, cheap disk storage G Memory manager handles the memory hierarchy Gao Haichang, Software School, Xidian University
Operating Systems Gao Haichang , Software School, Xidian University 4 Memory Management Ideally programmers want memory that is large fast non volatile Memory hierarchy (层次) small amount of fast, expensive memory – cache some medium-speed, medium price main memory gigabytes of slow, cheap disk storage Memory manager handles the memory hierarchy
Operating Systems Basic memory management G Memory Management Systems can be divided into two classes: H That move processes back and forth between main memory and disk during execution(swapping and paging) That do not ce Program expand to fill the memory available to hold them Gao Haichang, Software School, Xidian University
Operating Systems Gao Haichang , Software School, Xidian University 5 Basic Memory Management Memory Management Systems can be divided into two classes: That move processes back and forth between main memory and disk during execution (swapping and paging). That do not. Program expand to fill the memory available to hold them
Operating Systems Gs Monoprogramming without Swapping or Paging OXFFF Operating Device system in drivers in ROm ROM ser program ser User program Operating Operating system in system in RAM RAM Three simple ways of organizing memory an operating system with one user process (a) formally used on mainframes and minicomputers but is really used any more (b)used on some palmtop computers and embedded systems (c)used by early PC(MS-DOS), where the portion of the system in the ROM is called the bios Gao Haichang, Software School, Xidian University
Operating Systems Gao Haichang , Software School, Xidian University 6 Monoprogramming without Swapping or Paging Three simple ways of organizing memory - an operating system with one user process - (a) Formally used on mainframes and minicomputers but is really used any more. - (b) used on some palmtop computers and embedded systems. - (c) used by early PC (MS-DOS), where the portion of the system in the ROM is called the BIOS
Operating Sy Multiprogramming with Fixed Partitions Multiple input queues H口 Partition 44 Partition 4 Partition 3 Single Partition 3 input queue H Partition 2 Partition 2 200K Partition 1 100K erating gratin stem Fixed memory partitions H separate input queues for each partition H single input queue Gao Haichang, Software School, Xidian University
Operating Systems Gao Haichang , Software School, Xidian University 7 Multiprogramming with Fixed Partitions Fixed memory partitions separate input queues for each partition single input queue
Modeling multiprogramming Operam tting Systems 20%/0 wait 100 980 50%I/o wait 60 80%I/o wait 012345678910 Degree of multiprogramming CPU utilization as a function of number of processes in memory Gao Haichang, Software School, Xidian University
Operating Systems Gao Haichang , Software School, Xidian University 8 Modeling Multiprogramming CPU utilization as a function of number of processes in memory Degree of multiprogramming
Modeling multiprogramming tting Systems c Suppose a computer has 32MB of memory, with the os taking up 16MB and each user program taking up 4MB H These sizes allow 4 programs to be in memory at once. With an 80% average lO wait. we have a cPu utilization of 1-0.8460% H Adding another 1 6MB of memory allow 8 programs, thus raising the CPU utilization to 83% w Adding yet another 1 6MB of memory allow 12 programs, only increase CPU utilization to 93% ..97 Gao Haichang, Software School, Xidian University
Operating Systems Gao Haichang , Software School, Xidian University 9 Modeling Multiprogramming Suppose a computer has 32MB of memory, with the OS taking up 16MB and each user program taking up 4MB. These sizes allow 4 programs to be in memory at once. With an 80% average I/O wait, we have a CPU utilization of 1-0.8^4≈60%. Adding another 16MB of memory allow 8 programs, thus raising the CPU utilization to 83%. Adding yet another 16MB of memory allow 12 programs, only increase CPU utilization to 93%. …97% …
Operating Systems G> Analysis of Multiprogramming System Performance CPU Arrival minutes Processes Job time needed 1234 1000 CPU idle 10:10 4322 CPU busy 20364959 10:15 CPU/process. 20. 18. 16.1 1020 2.0 3Ir Job 1 finishe 9 8 31 9 2 Job 2 starts 8 3 9 3 15 2022 27.628231.7 Time(relative to job 1's arrival) (a) Arrival and work requirements of 4 jobs g(b)CPU utilization for 1-4 jobs with 80%I0 wait e()Sequence of events as jobs arrive and finish i note numbers show amount of CPU time jobs get in each interval Gao Haichang, Software School, Xidian University 10
Operating Systems Gao Haichang , Software School, Xidian University 10 Analysis of Multiprogramming System Performance (a) Arrival and work requirements of 4 jobs (b) CPU utilization for 1 – 4 jobs with 80% I/O wait (c) Sequence of events as jobs arrive and finish note numbers show amount of CPU time jobs get in each interval
Operating Systems Relocation and protection g Cannot be sure where program will be loaded in memory t address locations of variables code routines cannot be absolute w must keep a program out of other processes' partitions g Use base and limit values i address locations added to base value to map to physical addr address locations larger than limit value is an error Gao Haichang, Software School, Xidian University
Operating Systems Gao Haichang , Software School, Xidian University 11 Relocation and Protection Cannot be sure where program will be loaded in memory address locations of variables, code routines cannot be absolute must keep a program out of other processes’ partitions Use base and limit values address locations added to base value to map to physical addr address locations larger than limit value is an error
Operating Systems Base and Limit register limit relocation register register logical physical address yes address CPU memory no trap; addressing error Gao Haichang, Software School, Xidian University 12
Operating Systems Gao Haichang , Software School, Xidian University 12 Base and Limit register