Resource Management ( HL Part of Paper 1 20%)


In a typical computer system resource handling, for example, memory management, interrupt handling and multi-tasking, is the task of the Operating System. This is also particularly important in specialised OS's like a network os or a real time control based one which prioritise (policies - see below) processes relevant to its purpose.

The difference between multi-programming, multi-tasking, multi-processing...

They sound like the same thing.


Multi-programming -More than 1 whole  program apparently running at the same time but in reality they are time sharing. This can cause security issues.


Multi-tasking – As above but programs are split into tasks and share the use of the CPU. Waits for one task to be executed and then the next is executed. To the user it seems that both are running at the same time.

A multi-user system works the same way so overwriting of data in RAM is .avoided

Multi-processing – You have more than one CPU core. Your program must be designed to take advantage.


Multi -threading - Each process is split into threads. One GUI thread executing means your app does not freeze whilst another thread is doing some complex processing

 

Processes

Differences between a program, process and thread are given below:

A program is stored on the hard drive whereas:

  • A process is an executing instance of a program moved to RAM (IAS)
  • A thread is the smallest unit of process.
  • Processes can be divided into multiple threads whereas a thread cannot be divided.

A process in a ready state has all the resources it needs but is waiting for the OS to give it CPU time.


A process in a waiting state is waiting for a resource such as input from a user.


I am hoping that you can see that if two processes are in a waiting state for resources that the other one has control of then nothing happens -this is known as deadlock.


We can pre-empt deadlock by:

1. Taking from 1 process and giving it to the other.

2. We can kill one or more processes

3. Rollback to a checkpoint and re-allocate

How does the Operating System know when to allocate resources to a process, say in a control system of some sort or to allow multi programming?

The answer is by polling, interrupt handling and scheduling


Polling

In the classroom scenario mentioned the teacher asks every pupil in turn whether they need help. This is polling on a round robin basis.

Some of the advantages of polling are the relatively simple program, transmission reliability that takes place at maximum speed, i.e. as soon as the I/O device is ready and the no need of additional access chips.

However it is a waste ot time. In the polling process, the CPU is on hold and checks if any device needs a service. This unnecessarily wastes time.

A better way would to let pupils for example put up their hand or interrupt when they need help or resources (ISR)

Interrupt handling

You already know that the CPU fetches -decodes and executes instructions or processes. Interrupt handling is vital to not only deal with problems but to allow multi-tasking.


From time to time the processor is interrupted. This could be hardware related such as a key is pressed on the keyboard or software such as an urgent error handling request.

Imagine a teacher is interrupted by a knock on the door whilst he/she is in full flow.


Step 1:  Acknowledge the interruption
Step 2: Identify who is interrupting
Step 3: Identify the priority of the interruption (pupil or head?)
Step 4 :Remember where they were up to before being interrupted
Step 5: Deal with the interruption
Step 6: Recall where they were and continue


An OS interrupt service routine (ISR) does exactly this.

ISR

A more sophisticated way of dealing with interrupts is to use an interrupt handling routine where a signal is sent along the control bus. 

The processor knows that each wire on the bus represents a particular interrupt priority. If before fetching the instruction in the program counter the control unit interrupted by a higher priority process than the contents of the CPU is stored on a stack.  (Like Step 4 above).

The program counter will now store the first instruction of the ISR and the CPU will fetch-decode-execute the instructions in this routine.

After the interrupt is dealt with the stack is popped

The diagram below shows the state of things when the interrupt itself is interrupted by a higher priority process:

interrupts

How long will this go on for?  OS software called a scheduler works with the ISR to allocate time slices to processes. The scheduler runs after each time slice to check priorites.  This is how multi-tasking is managed by the OS. A pre-emptive scheduling is a high priority interrupt. More about this later.

Disadvantages of interrupts are the requirement for more complex hardware/software and loss of time until the CPU establishes which units request for interruption.

 

Memory Management


When you want to use some applications or want to work on a file, you typically double-click on it. It is then transferred by the operating system from a secondary storage device into the IAS. The operating system has a piece of software called a ‘loader that is responsible for:

    • Transferring an application or file into an appropriate place in the primary memory.

This loader must deal with problems:

  • What if a process states a particular piece of data is in IAS location 10110110 but it has been moved?
  • Another problem is if you are multi-tasking. Then you may have a number of applications and a number of files open at the same time.  These applications and files may interfere with each other and the loader must ensure that they don’t!

 They all need to be in RAM but each one is in danger of overwriting the
RAM locations of other applications and files.

  •  What if the IAS is full?

Solutions:


  Paging:


The OS splits RAM into pages of a fixed size. Each program is split into the same size pages. 4KB for a 32 bit system.


The more memory you have, then the more pages you can keep in it and the less swapping (in and out of RAM and the secondary storage) you need to do!

For problem 3 above then a set location in secondary storage is also split into pages of the same fixed size to act as pretend or virtual RAM.

The OS keeps track of where pages are in a page table. When a page is needed the table is accessed to recall the page into the correct location in RAM

All the operating system has to do is keep track of all of the pages. This system is used in virtual memory a lot. All well and good but it is slower than having real extra RAM. Each application will have associated with it a page table. This will identify each page for each application and will contain information about where to find that page if it is on the hard disk in virtual memory.

If a page is in RAM then the entry for that particular page will be blank. When a page is needed, the operating system looks up the page reference in the page table, finds out where it is in virtual memory and then transfers it from the hard disk to the primary memory. A hashing algorithm decides where in RAM data is stored. A good algorithm avoids the same location being used.


Disadvantages of paging
This, of course, all takes time and contributes to the computer slowing down. This kind of tracking system for pages is relatively simple to implement but there are some disadvantages.

    • Paging is a simple system to implement but may not be the most efficient. This is because the pages are of a fixed size. A page may only have a small amount of data in it but will require a whole page to store it in.
    • Pages are fixed sizes. They will contain code that may not be a logical group of code (for example, a logical block of code such as a function might run across 6 different pages). This means that to load that particular function will require 6 pages to be loaded up, which is not as efficient as loading e.g. one page for the whole function.
    • Page tables are typically large and accessing them slows down the computer.
    • Processes which quit should notify the OS otherwise memory leaking occurs

Segmentation to the rescue


The difference is that unlike page sizes, segments can vary in size .

You could have a segment per procedure, for example, and this would reduce the size of the tables needed to store the segment information.

The downside to segmentation is that retrieving a segment is more complicated. You need to store both the start address of a segment and the size of the segment. Start addresses have to be calculated with care because the sizes of each segment varies.  With paging, it is entirely predictable where each page starts and finishes.

More about sceduling resources

The scheduler is the part of the OS that decides which programs have access to the processor. The OS has two schedulers. A high-level one which selects tasks from secondary storage to go into RAM. It does its job by reference to priorities and if the required resources of that task are available. The low level one actually does decide which tasks in RAM will run.

CPU-bound jobs can be put into a seperate queue from AN INPUT/OUTPUT JOB .

The scheduler can also automate OS functions like anti virus checks, backups and defragmentation.

Policies - The policies what is to be done while the mechanism specifies how it is to be done. The decision of how long the timer is set for a particular user is a policy decision

The actual timer is a construct (limiting the time a process can use the CPU for) thereby ensuring CPU protection is called the mechanism.

The separation of mechanism and policy is important to provide flexibility to a system.

 

There are six popular process scheduling algorithms. These algorithms are either non-preemptive or preemptive. Non-preemptive algorithms are designed so that once a process enters the running state, it cannot be preempted until it completes its allotted time.

The preemptive scheduling is based on priority where a scheduler may preempt a low priority running process anytime when a high priority process enters into a ready state

  • First-Come, First-Served (FCFS) Scheduling
  • Jobs are executed on first come, first serve basis.
  • It is a non-preemptive, pre-emptive scheduling algorithm.
  • Easy to understand and implement.
  • Its implementation is based on FIFO queue.
  • Poor in performance as average wait time is high.
  • Shortest-Job-Next (SJN) Scheduling
    • This is a non-preemptive, pre-emptive scheduling algorithm.
    • Best approach to minimize waiting time.
    • Easy to implement in Batch systems where required CPU time is known in advance.
    • Impossible to implement in interactive systems where required CPU time is not known.
    • The processer should know in advance how much time process will take.
  • Priority Scheduling
    • Priority scheduling is a non-preemptive algorithm and one of the most common scheduling algorithms in batch systems.
    • Each process is assigned a priority. Process with highest priority is to be executed first and so on.
    • Processes with same priority are executed on first come first served basis.
    • Priority can be decided based on memory requirements, time requirements or any other resource requirement.
  • Shortest Remaining Time
    • Shortest remaining time (SRT) is the preemptive version of the SJN algorithm.
    • The processor is allocated to the job closest to completion but it can be preempted by a newer ready job with shorter time to completion.
    • Impossible to implement in interactive systems where required CPU time is not known.
    • It is often used in batch environments where short jobs need to give preference.
  • Round Robin(RR) Scheduling
    • Round Robin is the preemptive process scheduling algorithm.
    • Each process is provided a fix time to execute, it is called a quantum.
    • Once a process is executed for a given time period, it is preempted and other process executes for a given time period.
    • Context switching is used to save states of preempted processes.

Batch processing

Jobs are grouped together and run without user or operator involvement.


There will be checks like the name of the batch –how many jobs were there so a check can be made to see if that number was actually processed.

Printing off gas bills for example would not be run one at a time by a utility company. Batch processing is mainly done on mainframe computers, although network managers have been known to run batch programs in the background. This is in contrast with a multi-programming environment

Drivers

The OS adds a level of abstraction to the user. When you print a document you only need basic print commands. The driver software acts as a bridge to give functionality to devices
These drivers should be updated regularly and are provided by the manufacture on a CD or downloads.

Memory

Types of RAM

The following are some common types of RAM:

  • SRAM: Static random access memory uses multiple transistors, typically four to six, for each memory cell but doesn't have a capacitor in each cell. It is used primarily for cache.
  • DRAM: Dynamic random access memory has memory cells with a paired transistor and capacitor requiring constant refreshing.
  • FPM DRAM: Fast page mode dynamic random access memory was the original form of DRAM. It waits through the entire process of locating a bit of data by column and row and then reading the bit before it starts on the next bit. Maximum transfer rate to L2 cache is approximately 176 MBps.
  • EDO DRAM: Extended data-out dynamic random access memory does not wait for all of the processing of the first bit before continuing to the next one. As soon as the address of the first bit is located, EDO DRAM begins looking for the next bit. It is about five percent faster than FPM. Maximum transfer rate to L2 cache is approximately 264 MBps.

 

past paper