Operating systems Seminar 6 Before the seminar Open
Operating systems Seminar 6
Before the seminar • Open https: //fitcw 2016. wordpress. com/ • Explore – CW structure draft – FAQ: Word limit, deadline, number of companies
Agenda • Memory Management • Process Management • CPU Scheduling
MEMORY MANAGEMENT
Memory Management • Main memory can be thought of as a big continuous chunk of space divided into groups of 8, 16, or 32 bits. – The first memory address is 0 • Each byte or word of memory has a corresponding address, which is simply an integer that uniquely identifies that particular part of memory
Memory Management • In a multiprogramming environment, multiple programs (and their data) are stored in main memory at the same time. • Thus, operating systems must employ techniques to: – track where and how a program resides in memory. – convert logical program addresses into actual memory addresses.
Memory Management • A program is filled with references to variables and to other parts of the program code. • When the program is compiled, these references are changed into the addresses in memory where the data and code reside. • But since we don’t know exactly where a program will be loaded into main memory, how can we know what address to use for anything?
Memory Management • A logical address (sometimes called a virtual or relative address) is a value that specifies a generic location, relative to the program but not to the reality of main memory. • A physical address is an actual address in the main memory device, when a program is compiled, a reference to an identifier (such as a variable name) is changed to a logical address. • When the program is eventually loaded into memory, each logical address finally corresponds to a specific physical address. • The mapping of a logical address to a physical address is called address binding.
Memory is a continuous set of bits referenced by specific addresses
Memory Management • The later we wait to bind a logical address to a physical one, the more flexibility we have. – Logical addresses allow a program to be moved around in memory or loaded in different places at different times. • As long as we keep track of where the program is stored, we are always able to determine the physical address that corresponds to any given logical address.
Memory management techniques 1. Single contiguous memory management 2. Partition memory management 3. Paged memory management
1. Single contiguous memory management • Entire application program is loaded into one large chunk of memory. • Only one program other than the operating system can be processed at one time. • To bind addresses, all we have to take into account is the location of the operating system.
Main memory is divided into two sections
Single contiguous memory management • Logical address is simply an integer value relative to the starting point of the program. – That is, logical addresses are created as if the program is loaded at location 0 of main memory. • To produce a physical address, we add a logical address to the starting address of the program in physical main memory.
Single contiguous memory management example • If the program is loaded starting at address A, then the physical address corresponding to logical address L is A+L. – Suppose the program is loaded into memory beginning at address 555555. – When a program uses relative address 222222, we know that actually refers to address 777777 in physical main memory.
Single contiguous memory management advantages Advantages Disadvantages • simple to implement and manage • memory space and CPU time are almost certainly wasted. • It is unlikely that an application program needs all of the memory not used by the operating system, and CPU time is wasted when the program has to wait for some resource.
2. Partition Memory Management • sharing memory space and CPU time. Thus, memory must be divided into more than two partitions. • two strategies that can be used to partition memory – fixed partitions – dynamic partitions
Fixed partitions • Main memory is divided into a particular number of partitions. • The partitions do not have to be the same size, but their size is fixed when the operating system initially boots. • A job is loaded into a partition large enough to hold it. • The OS keeps a table of addresses at which each partition begins and the length of the partition.
Dynamic partitions • Dynamic partitions, the partitions are created to fit the need of the programs. • Main memory is initially viewed as one large empty partition. As programs are loaded, space is “carved out, ” using only the space needed to accommodate the program and leaving a new, smaller empty partition, which may be used by another program later • The operating system maintains a table of partition information, but in dynamic partitions the address information changes as programs come and go.
fixed and dynamic partitions • At any point in time in both fixed and dynamic partitions, memory is divided into a set of partitions, some empty and some allocated to programs. • Address binding is basically the same for both fixed and dynamic partitions. • As with the single contiguous technique, a logical address is an integer relative to a starting point of zero.
Fixed and dynamic partitions • There are various ways an OS might handle the details of the address translation. • One way is to use two special purpose registers in the CPU to help manage addressing. When a program becomes active on the CPU, the OS stores the address of the beginning of that program’s partition into the base register. • Similarly, the length of the partition is stored in the bounds register. When a logical address is referenced, it is first compared to the value in the bounds register to make sure the reference is in that program’s allocated memory space. If it is, the value of the logical address is added to the value in the base register to produce the physical address.
Partition selection techniques • First fit, in which the program is allocated to the first partition big enough to hold it • Best fit, in which the program is allocated to the smallest partition big enough to hold it • Worst fit, in which the program is allocated to the largest partition big enough to hold it - not suitable for fixed sized partition
3. Paged memory management • Puts much more burden on the operating system to keep track of allocated memory and to resolve addresses. • Benefits gained by this approach are generally worth the extra effort. • In the paged memory technique, main memory is divided into small fixed-size blocks of storage called frames. • Process is divided into pages that (for the sake of our discussion) we assume are the same size as a frame.
3. Paged memory management • When a program is to be executed, the pages of the process are loaded into various unused frames distributed through memory. Thus the pages of a process may be scattered around, out of order, and mixed among the pages of other processes. • To keep track of all this, the operating system maintains a separate page-map table (PMT) for each process in memory; it maps each page to the frame in which it is loaded.
PROCESS MANAGEMENT
Process management • Processes move through specific states as they are managed in a computer system. • A process enters the system, is ready to be executed, is executing, is waiting for a resource, or is finished.
CPU SCHEDULING
CPU scheduling • …is the act of determining which process in the ready state should be moved to the running state. • That is, CPU scheduling algorithms decide which process should be given over to the CPU so that it can make computational progress.
CPU scheduling • Nonpreemptive scheduling – CPU scheduling that occurs when the currently executing process gives up the CPU voluntarily • Preemptive scheduling – CPU scheduling that occurs when the operating system decides to favor another process, preempting the currently executing process
- Slides: 29