You are on page 1of 51

RESOURCE mANAGEMENT

Resource Management
Topics Memory management
Resident and transient routines Related terminologies Dynamic address translation Virtual memory

Processor management
Control blocks and interrupts Types of scheduling processes Scheduling algorithms Queuing routine and scheduler Multiprogramming and time sharing Deadlock

Scenario that evokes memory management


Picture a computer with a single program in memory. The program cannot process data it does not yet have, and success cannot be assumed until an output operation is finished, so the program waits for input or output. Since the program controls the computer, the computer waits, too. Typically, given the speed disparity between the processor and its peripheral devices, a program spends far more time waiting for I/O than processing data. Why not put two programs in memory? Then, when program A is waiting for data, the processor can turn its attention to program B. And why stop at two programs? With three, even more otherwise wasted time is utilized .Generally,

the more programs in memory, the greater the utilization of the processor.

Memory Management
Memory management is the act of managing computer memory. In its simpler forms, this involves providing ways to allocate portions of memory to programs at their request, and freeing it for reuse when no longer needed. The management of main memory is critical to the computer system.

Memory Management
Memory management is done by memory manager. Main tasks are to:
Keep track of which parts of memory are in use and which parts are not in use Allocate memory to processes when they need it and deallocate it when they are done Manage swapping between main memory and disk when main memory is too small to hold all the processes

Memory Management
The allocation of computer storage in a multiprogramming system so as to maximize processing efficiency. The collection of routines for placing, fetching, and removing pages or segments into or out of the main memory of a computer system.

Memory Management
Memory management systems on multitasking operating systems usually deal with the following issues:
Relocation Protection Sharing Logical organization Physical Organization

Relocation
In systems with virtual memory, programs in memory must be able to reside in different parts of the memory at different times.
The program is swapped back into memory after being swapped out for a while it can not always be placed in the same location.

Memory management in the operating system should therefore be able to relocate programs in memory and handle memory references and addresses in the code of the program so that they always point to the right location in memory.

Protection
Processes should not be able to reference the memory for another process without permission. This is called memory protection, and prevents malicious or malfunctioning code in one program from interfering with the operation of other running programs

Sharing
Even though the memory for different processes is normally protected from each other, different processes sometimes need to be able to share information and therefore access the same part of memory. Shared memory is one of the fastest techniques for Inter-process communication.

Logical organization
Programs are often organized in modules. Some of these modules could be shared between different programs, some are read only and some contain data that can be modified. The memory management is responsible for handling this logical organization that is different from the physical linear address space. One way to arrange this organization is segmentation.

Physical Organization
Memory is usually divided into fast primary storage and slow secondary storage. Memory management in the operating system handles moving information between these two levels of memory.

Memory Allocation in a PC

Resident Routines
OS is a collection of software routines Resident routines (Rutin Tetap)
The part of a program that must remain in memory at all times. Instructions and data that remain in memory can be accessed instantly. A routine that stays in the memory eg routines that control physical I/O and directly support application programs as they run

In computing, a resident module or resident program stays in memory throughout the lifetime of a computing session.
One such program might be an anti-virus program. This has given rise to the term resident protection.

Transient Routines
Transient routines (Rutin Sementara) A routine that is stored on disk loaded as needed
routines that format disks

Resident and Transient routines


The operating system occupies low memory. Key control information comes first followed by the various resident operating system routines. The transient area, is where application programs and transient operating system routines are loaded.
System Control Information

Resident Operating System

Transient Area

Terminologies related to memory management :


Fixed partition memory management Dynamic memory management Segmentation Paging
Memory management Real memory Fixed Partition Dynamic Virtual memory Segmentation Paging

Fixed partition memory management


Memory is divided into n (possibly unequal and fixed length) partition each of which holds one program Partition sizes are set when the system is initially started So the memory allocation decision is made before the actual amount of space needed by a given program is known

Fixed partition memory management


When a job arrives, it can be put into the input queue for the smallest partition large enough to hold it. Since a partition is fixed in this scheme, any space in a partition not used by a job is lost (internal fragmentation)

Fixed partition memory management


Major advantage is simplicity Disadvantage of sorting the incoming jobs into separate queues is when the queue for a large partition is empty but the queue of a small partition is full(Refer figure a) Small jobs have to wait to get into memory, even though plenty of memory is free Alternative of separate queues is to maintain a single queue(Refer figure b)

Fixed partition memory management


Whenever a partition becomes free, the job closest to the front of the queue that fits in could be loaded into the empty partition and run Small partition is usually used to allow small jobs to run without having to allocate large partition for them which will cause waste of partition space

Fixed partition memory management: Figure a


800K Multiple input queues

Partition 4
700K

Partition 3

Partition 2

400K

Partition 1 Operating System

200K 100K

0K

Fixed partition memory management: Figure b


800K

Partition 4
700K

Partition 3

Single input queue Partition 2 400K

Partition 1 Operating System

200K 100K

0K

Dynamic memory management


Transient area is treated as a pool of unstructured free space. When the system loads a particular program, a region of memory just sufficient to hold the program is allocated from the pool. Because a program gets only the space it needs, relatively little space is wasted

Dynamic memory management


Disadvantage :
does not completely solve the wasted space problems. (Refer figure c)

Dynamic memory management: Figure c


Example, a 640K program has just
Operating System Other Regions

finished executing. If there are no 640K programs available, the system might load a 250K and a 300K programs, but note that 90K remains unallocated. If there are no 90K or smaller programs available, the space will not be used. This will lead to external fragmentation .

250K Region

300K Region Unused 90K Fragment Other Regions

Segmentation: Figure d
Programs are divided into independently addressed segments and stored in noncontiguous memory (Refer Figure d)
Operating Systems Other Programs Program A, segment 0 Other Programs Program A, segment 1 Other Programs Program A, segment 2 Other Programs

Segmentation:
Different segments may and usually do have different lengths Segments length may changed during execution

Segmentation:
requires adding a step to the address translation process. When a program is loaded into memory, the operating system builds a segment table listing the (absolute) entry point address of each of the programs segments (Refer figure e)

Segmentation:
When the operating system starts a given program, it loads the address of that programs segment table into a special register. As the program runs, addresses must be translated from relative to absolute form because programmers still write the same code and compilers still generate base-plusdisplacement addresses.

Segmentation
After fetching an instruction, the instruction control unit expands each operand address by adding the base register and the displacement. Traditionally, the expanded address was an absolute address.

Segmentation
The expanded address consists of two parts:
a segment number a displacement

Dynamic Address Translation will convert the segment/displacement address to an absolute address.

Absolute Address.
The term absolute distinguishes it from a relative address, which indicates a location by specifying a distance from another location. Absolute addresses are also called real addresses and machine addresses.

Segmentation: Figure e
Base Displacement

Expand

Segment

Displacement

Segment 0

Segment

Start address

Segment start address plus displacement equals absolute segment address

Segment 1

0
1 2

Aaa
Bbb Ccc Segment 2

Paging
a program is broken into fixed-length pages Page size is generally small (perhaps 2K to 4K) Like segments, a programs pages are loaded into noncontiguous memory.

Paging
Addresses consist of two parts :
a page number in the high-order positions a displacement in the low-order bits.

Addresses are dynamically translated as the program runs.

Paging
When an instruction is fetched, its base-plus displacement addresses are expanded to absolute addresses by hardware. Then the pages base address is looked up in a program page table (like the segment table, maintained by the operating system) and added to the displacement.

Paging: Figure f
Base Displacement

Expand

Page

Displacement

Page 0

Page 0 1 2

Start address aaa bbb ccc

Segment start address plus displacement equals absolute page address

Page 1

Page 2

Dynamic Address Translation


If, while executing an instruction, a CPU fetches an instruction located at a particular virtual address, or fetches data from a specific virtual address or stores data to a particular virtual address, the virtual address must be translated to the corresponding physical address. This is done by a hardware component, sometimes called a memory management unit, which looks up the real address (from the page table) corresponding to a virtual address and passes the real address to the parts of the CPU which execute instructions. If the page tables indicate that the virtual memory page is not currently in real memory, the hardware raises a page fault exception (special internal signal) which invokes the paging supervisor component of the operating system.

Dynamic Address Translation


Steps to convert the segment/displacement address to an absolute address, hardware:
1. checks the special register to find the programs segment table, 2. extracts the segment number from the expanded address, 3. uses the segment number to search the programs segment table,

Dynamic Address Translation


4. finds the segments absolute entry point address, and 5. adds the displacement to the entry point address to get an absolute address

Virtual Memory
splits up a program into small modular pieces a technique that allows the execution of processes that may not be completely in memory.
ie, the process can start executing with only part of the process image in the memory.

Virtual Memory
Advantage :
the program can be larger than the physical memory. You can run more applications at once. You can run larger applications with less real RAM. Applications may launch faster because of File Mapping. You don't have to buy more memory(RAM).

Virtual Memory
Applications run slower. It takes more time to switch between applications. Less hard drive space for your use. Reduced system stability.

Virtual Memory
It shows three levels of storagevirtual memory, the external paging device, and real memory. Real memory is good, old-fashioned main memory, directly addressable by the processor.

Virtual Memory
The external paging device is usually disk, model that simplifies address translation. Virtual memory is a model that simplifies address translation. It contains the operating system and all the application programs, but it does not physically exist anywhere

Virtual Memory
A computer system technique, which gives an application program the impression that it has contiguous working memory (an address space), while in fact it may be physically fragmented and may even overflow on to disk storage.

Virtual Memory
Consists of 3 main parts :
Main memory (RAM) Secondary memory(disk) Page Table

Virtual Memory
Main Memory(RAM)

Store the more recently used pages. Each page is stored into subdivisions of memory called "frames." A frame size is the same as page size.
If we have a 4096 byte page size, then each frame will hold 4096 bytes to accommodate the pages.

The first frame will take up actual addresses 0x00000000 to 0x00000FFF. The second frame will take up address 0x00001000 to 0x00001FFF. Etc. If physical memory is 256 megabytes, the last page would be from 0x0FFFF000 to 0x0FFFFFFF. Notice that the range of addresses covers 4096 bytes.

Virtual Memory
Disk

The disk memory is a repository for pages not currently in use. When a page needs to be brought to memory, the appropriate page is found and transferred to main memory. Whenever a page that has been modified during its time in main memory, it is written to disk. Think of the pages on the disk as being in long term storage.

Virtual Memory
Page Table keeps track of where pages are, and what their properties are. The system updates the page table as changes in the state of the system warrant. It makes sense that there are as many entries in the page table as there are pages in our virtual address space. Therefore, in a virtual address space addressed by 32 bits, at 4K per page that's 220 pages, and hence 220 entries in the page table. The first entry in the page table contains information about the first page. The second entry contains information about the second page. Etc. If we have a virtual address with virtual page number 56 (and hence is the 57th page), we can find information about that page in the 57th entry in the page table.

You might also like