Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 49

CHAROTAR INSTITUTE OF TECHNOLOGY

DEPARTMENT OF INFORMATION TECHNOLOGY

IT502 OPERATING SYSTEM

DEPARTMENT OF INFORMATION TECHNOLOGY

CHAROTAR INSTITUTE OF TECHNOLOGY, CHANGA

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Topics for discussion

Functions Of Operating System What is Memory Manager? The notion Of Address Space Approaches Of Memory Management Memory management without Swapping Or Paging Multiprogramming and memory usage Modeling Multiprogramming Multiprogramming with Fixed Partitions Relocation and Protection Swapping

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Major Functions Of Operating System


Processor management That is assignment of processor to different tasks being performed by the computer system.

Memory management allocation of main memory and other storage areas to the system programmes as well as user programmes and data. File management, that is, the storage of file of various storage devices to another. It also allows all files to be easily changed and modified through the use of text editors or some other files manipulation routines.
Classified e-Material Copyrights Charotar Institute of Technology, Changa 3

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Input/output management, that is, co-ordination and assignment of the different output and input device while one or more programmes are being executed. Interpretation of commands and instructions Establishment and enforcement of a priority system. That is, it determines and maintains the order in which jobs are to be executed in the computer system. In this session we are suppose to study the details about Memory mangement.
Classified e-Material Copyrights Charotar Institute of Technology, Changa 4

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

So the first question that arises in our minds is: What do you mean by memory? Memory refers to storage needed by the kernel, the other components of the operating system and the user programs. Ideally memory should be Large, Fast and Non volatile Then next question arises is: What are the different types of memory devices inherent in computer? Cache, Main memory(RAM),ROM and hard Disks

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

How do different types of memory differ? In practice, a memory hierarchy is used Small amount of fast, expensive memory cache Some medium-speed, medium price main memory Gigabytes of slow, cheap disk storage Now there is need of a controllling structure to decide what memory to use and when? This decision is taken by memory manager Definition: The part of operating system that manages memory is called the memory manager. It handles the memory hierarchy 1. 2. 3.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

The notion of address space

An address space is set of addresses that a process can use to address memory. Before executing any process cpu has to allocate address space to it For example, consider changa campus as memory and out department as a process CITC building has been allocated some space. Our address space is then Building 1.

Classified e-Material Page 7

Copyrights Charotar Institute of Technology, Changa

7 3/30/2014

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Memory Management Approaches

Monoprogramming vs. Multiprogramming One program at a time vs. many Fixed program set vs. swapping When programs are switched out, save state to disk Complete image vs. partial image (Virtual memory) Some program images wont fit in available RAM Modern systems are all multi-programmed, with swapping and virtual memory But first we will learn monoprogramming without swapping or paging

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Monoprogramming without swapping or paging

The simplest possible scheme is to have just one process in memory at a time, and allow that process to use all memory The user loads entire memory with a program from a disk or a tape and it takes over whole machine The actual technique used on microcomputers is as follows The memory is divided between operating system and a single user process The location may of memory may be at different places as shown in figure in next slide

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Simplest Memory Management


Monoprogramming without Swapping or Paging

Fig. 3-1. Three simple ways of organizing memory


Classified e-Material Copyrights Charotar Institute of Technology, Changa 10

10

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Uses And Advantages

Uses:It was used for 1. (a) was used for mainframes and minicomputers 2. (b) is used on some palmtop computers and embedded systems 3. (c) was used by early PCs running MS-DOS where BIOS device drivers were in ROM Advantages:1. The sole advantage of monoprogramming is its simplicity. 2. There is very little software required in the operating system for memory management in this case. The processis given all of the available memory which it can then use as it desires.
Classified e-Material Copyrights Charotar Institute of Technology, Changa 11

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Disadvantages of Monoprogramming

Monoprogramming is wasteful of CPU and memory resources. While the program is performing I/O, the CPU is idle Likewise, if the program doesnt use all of the available memory, the excess memory in the system is wasted. Programs cannot be larger than the size of the available physical memory.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

12

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Multiprogramming

In multiprogramming, as you know, multiple processes are conceptually executed at the same time. This permits the operating system to switch the CPU to a different process when the current process becomes blocked. The difficulty, of course, is that memory is now required to hold the images of each process that is a candidate for execution.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

13

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Multiprogramming Questions

How effective is multiprogramming? That is, how much more quickly can we execute processes than if monoprogramming was used? How much higher is CPU utilization? How much higher is memory utilization? Is the additional memory needed to support multiple processes worth the cost?

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

14

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Answering the Questions

One obvious way to answer these questions is to run the same set of processes using monoprogramming, and then again using multiprogramming. Unfortunately, this is a very expensive and time consuming procedure, and only answers the questions relative to the particular set of processes used in the analysis. A more general, mathematical analysis is desired.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

15

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

A Simple Multiprogramming Model

Assumption 1: there are n processes in memory. Assumption 2: the probability of each process being blocked is p (a number between 0 and 1). Assumption 3: all processes are independent. Assumption 4: there is one CPU, and we ignore time spent doing context switches.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

16

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Performing the Analysis

We know the CPU will be idle only if all n processes are blocked. Using elementary probability, we know that probability of all processes being blocked is Pn and probability of at least one process not being blocked is 1 pn (CPU utilization) The chart on the next slide illustrates CPU utilization for three different processing blocking probabilities: 20%, 50% and 80%.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

17

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Modeling Multiprogramming
Modeling Multiprogramming

CPU utilization as a function of number of processes in memory

Degree of multiprogramming
Suppose that a process spends a fraction p of its time waiting for I/O to complete with n processes in memory at a time, the probability that all n processes are waiting for I/O is p^n. CPU utilization is 1 - p^n (with the assumption that the processes are independent)
Classified e-Material Copyrights Charotar Institute of Technology, Changa 18

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Memory Management in Multiprogramming

With monoprogramming, memory management was simple: give all available memory to the job and were done. With multiprogramming we must decide how to arrange the memory images of the jobs in the primary memory of the system. With n jobs there are n! orderings of the jobs in memory. We must also consider what happens when one of the jobs finishes can we fit a new job in the memory space just vacated?

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

19

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Fixed Partitioning of Memory

One approach to the problem is to statically divide the available memory into a number of regions or partitions, the size of each is fixed. This approach is used in the IBM OS/MFT (Multiprogramming with a Fixed number of Tasks) operating system (now largely obsolete).

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

20

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Multiprogramming with Fixed Partitions

Fixed memory partitions


separate input queues for each partition single input queue (strategies: next convenient process, biggest process, dont ignore more than k times)
Classified e-Material Copyrights Charotar Institute of Technology, Changa 21

21

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Multiprogramming with Fixed Tasks Characteristics

Each job (with a maximum memory requirement specified) is run in the smallest partition that meets its needs. Underutilization of memory can still occur, since job sizes dont necessarily exactly match partition sizes. Suppose we have two 40K partitions and a 39K and a 41K job. Only the 39K job can be run, wasting 41K. Concern must be given to memory protection, since a program in one partition might access memory in another partition by accident or on purpose

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

22

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

MFT: Advantages & Disadvantages

Advantages: 1. Easy to implement. 2. Provides multiprogramming (faster turnaround, better use of memory and CPU). Disadvantages: 1. Scheduling can be complicated. 2. Memory resources are still wasted. 3. Job size is limited to physical memory size. 4. Extra hardware and/or software are needed for relocation and protection.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

23

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Relocation and Protection

Cannot be sure where program will be loaded in memory address locations of variables, code routines cannot be absolute (address translation: during loading/calculation during execution) must keep a program out of other processes partitions

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

24

24

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Program Relocation

To achieve relocation, OS/MFT modifies the addresses in instructions when the program is loaded to reflect the location at which the program is loaded. Consider figure A, if a program has entered partition 2 and user wants to access 100th instruction in the program then, instruction needs to be modified as 200K +100 This has some obvious disadvantages: 1)the loader must mark those instructions needing modification, and 2)the modification of the program is a slow operation

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

25

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Another Relocation Technique

Another approach to relocation causes a base register (one of the processors general registers) to be set to the address at which the program is loaded. The instructions in the program then use this base register much like an index register when they need to reference memory. Disadvantages: Additional base registers are required The approach consumes one of the CPUs registers. A program cant be easily relocated once its started.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

26

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Still Another Technique

Perhaps the most general approach is to have a special CPU register used as the base register, and automatically add its content to every memory address generated by a program. This register is protected from modification by the user and is, in fact, entirely transparent to the users program. The users program now appears to be addressing a region of memory starting at location 0.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

27

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Protection

In the IBM 360 (and others), each 2K block of memory has a special 4-bit code called the lock. Only kernel-mode programs can alter these locks. All locks for each programs memory are set to a unique value. A four-bit key is present in the Program Status Word (PSW, essentially a register containing the next instruction address, interrupt enable information, and so forth). The PSW is included in the context of a process.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

28

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Another Memory Protection Scheme

Another approach is to add a special limits register (which can only be set by supervisor mode programs). Every memory address is automatically compared with the limits register. If the limits register is exceeded, a fault is generated. Both these approaches require special dedicated hardware, and that implies additional expense in producing the CPU.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

29

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Swapping

Swapping is used to increase the probability that a process will be ready to run when the CPU would otherwise be idle. That is ,swap in process from hard disk to main memory Most of the time there is not enough memory to hold all the active processes at the same time So in that case we need to take that process back to hard disk. That is swap out process from main memory to hard disk Thus, Swapping is the process of moving a process between primary memory and secondary storage A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution. There is special place allocated for this is hard disk called swap area
Classified e-Material Copyrights Charotar Institute of Technology, Changa 30

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Schematic View of Swapping

Classified e-Material Page 31

Copyrights Charotar Institute of Technology, Changa

31 3/30/2014

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Variable Partition Sizes

Fig. 3-4. Memory allocation changes as


processes come into memory leave memory

Shaded regions are unused memory


Classified e-Material Copyrights Charotar Institute of Technology, Changa 32

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Compaction

Collectively the holes in memory might be large enough to allow the execution of another program. But our programs assume they will be executed in a contiguous region of memory and the holes are not contiguous When Swapping creates multiple holes in the memory, it is possible to coalesce all the holes into one larger hole that might be useful. This technique is memory compaction To perform compaction we must move the occupied memory regions together to eliminate the holes. Compaction can consume a great deal of CPU time during which processes cannot execute.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

33

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Advantages & Disadvantages

Advantages: 1. Conceptually there is less wasted memory. 2. Scheduling is possibly simpler.

1. 2. 3.

Disadvantages: Memory resources are still wasted (holes). Job sizes are still tied to the physical memory size. Extra hardware and/or software are still needed for relocation and protection.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

34

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

How Much Memory To Allocate?

Many programs have predictable memory requirements: code, static data, and stack (to hold procedure invocation records and local variables) However many others have less predictable memory requirements due to the need for dynamic storage allocation and recursion. As a result, processes may request execution in a partition larger than their static memory requirements. To solve this problem a traditional memory layout is used which is as shown in the next slide

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

35

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

The To accommodate stack is then placed the potential at the high for growth end ofof the region, some parts growing of adownward programs as memory items are allocation, pushed, and the contracting code, static upward data and asheap items (dynamic are removed. data) This in the allows lowest expansion part of aof memory the heap region. and the stack Classified e-Material Copyrights Charotar Institute of Technology, Changa into the region between them.

36

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Keeping Track of Memory Usage

There are three common ways to keep track of memory usage: 1. bit maps 2. linked lists The basic goals of each system are to: 1. identify all used/unused memory regions, 2. support the allocation of a contiguous unused region of n blocks of memory, and 3. handle the deallocation (freeing) of a region of memory.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

37

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Memory Management with Bit Maps or chained lists

Fig. 3-6a. Part of memory with 5 processes, 3 holes


tick marks show allocation units shaded regions are free

Fig. 3-6b. Corresponding bit map Fig. 3-6c. Same information as a list
Classified e-Material Copyrights Charotar Institute of Technology, Changa 38

38

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Memory Management with Bit map

We can use an array of bits is used to keep track of used/unused blocks of memory. We might choose to set a bit to 0 to represent an unused block, with a 1 bit meaning the block is used. The size of the block has several effects. Larger block sizes yield smaller bitmaps, but memory will likely be wasted in the last block for each region. Smaller block sizes result in larger bitmaps, but less waste will occur in a regions last block.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

39

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Bit Maps: Advantages & Disadvantages

Advantages: 1. easy to implement, 2. easy to deallocate a region, and the size is dependent only on the size of primary memory and of a block. Disadvantage: 1. it is difficult to allocate a contiguous region of size n, since the system must search the bit map for n consecutive 0 bits.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

40

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Memory Management with Linked Lists

Fig. 3-7. Four neighbor combinations for the terminating process X


Classified e-Material Copyrights Charotar Institute of Technology, Changa 41

41

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Linked Lists

Using linked lists, the basic idea is to maintain a list of free regions of contiguous memory and another list of occupied regions. The free list can be ordered in various ways: 1. ordered by memory address, 2. or ordered by size. We explicitly assume region sizes are random. Allocation of a region can be done using any of many different algorithms (e.g. first fit, best fit, next fit, worst fit, quick fit).

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

42

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

First Fit Allocation Technique

Scan the free list from its head, looking for the first unused region that satisfies (is larger than or equal to the size of) the allocation request. Then split that region, if necessary, to produce one region of the requested size. other unused) region back on the list. Advantages: 1. Easy to implement 2. Fast Disadvantage: 1. Produces lots of very small holes

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

43

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Next Fit Allocation Technique

This approach is similar to the first fit algorithm, but each new search for an acceptable unused memory region begins (in the list) where the last one ended. Disadvantage 1. In simulations, it produces slightly worse results than first fit.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

44

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Best Fit Allocation Technique

Scan the entire list to locate the smallest unused region that will accommodate the request for memory. Disadvantages: 1. it is potentially very slow; or 2. requires the list to be ordered on size; which complicates the deallocation algorithm. Expected advantage: It should reduce the number of holes.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

45

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Worst Fit Allocation Technique

Pick the largest available hole to satisfy each allocation, splitting it as necessary into the allocated region and a new hole. Disadvantage: 1. Simulation results for this technique are negative.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

46

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Quick Fit Allocation Technique

Maintain multiple lists, each list having holes of the same common sizes. To satisfy an allocation request, look first in the list with the appropriate size, then in lists of larger unused regions. Disadvantage: 1. Deallocation is costly, since all lists must be scanned to find neighboring unused regions. Advantage: 1. Allocation is fast.

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

47

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Fragmentation
External Fragmentation total memory space exists to satisfy a request, but it is not contiguous. Internal Fragmentation allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used. Reduce external fragmentation by compaction

Shuffle memory contents to place all free memory together in one large block. Compaction is possible only if relocation is dynamic, and is done at execution time.

Classified e-Material Page 48

Copyrights Charotar Institute of Technology, Changa

48 3/30/2014

IT502-OPERATING SYSTEMS

INFORMATION TECHNOLOGY

Related Exam Based Questions

1. 2. 3.

Monoprogramming without Swapping or Paging [4] Explain Swapping in detail [6] Define Memory Manager Compaction Degree of MultiProgrmming Explain Relocation problem in detail [2]

Classified e-Material

Copyrights Charotar Institute of Technology, Changa

49

You might also like