Chapter 2 – Introduction to Operating...

22
1 school of information technology ICT106 Fundamentals of Computer Systems Topic 12 Introduction to Operating Systems ICT 106 _Week 12_06 2 school of information technology Reading Irvine (4 th Edition) Chapter 13 – 16-bit MS-DOS Chapter 14 – Disk Fundamentals – Chapter 2 – Section 2.3 IA-32 Memory management ICT 106 _Week 12_06 3 school of information technology Objectives To understand the components and functions of an operating system To understand the resource allocation functions of an operating system To understand the mechanisms by which an operating system manages programs and processes ICT 106 _Week 12_06 4 school of information technology • To understand the mechanisms by which an operating system manages the CPU • To understand the mechanisms by which an operating system manages memory Objectives

Transcript of Chapter 2 – Introduction to Operating...

Page 1: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

1

school of information technology

ICT106 Fundamentals of Computer Systems

Topic 12

Introduction to Operating Systems

ICT 106 _Week 12_06 2 school of information technology

Reading

• Irvine (4th Edition)– Chapter 13 – 16-bit MS-DOS– Chapter 14 – Disk Fundamentals– Chapter 2 –

• Section 2.3 IA-32 Memory management

ICT 106 _Week 12_06 3 school of information technology

Objectives• To understand the components and

functions of an operating system • To understand the resource allocation

functions of an operating system• To understand the mechanisms by

which an operating system manages programs and processes

ICT 106 _Week 12_06 4 school of information technology

• To understand the mechanisms by which an operating system manages the CPU

• To understand the mechanisms by which an operating system manages memory

Objectives

Page 2: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

2

ICT 106 _Week 12_06 5 school of information technology

• An Operating System (OS) consists of a set of sophisticated, coordinated and cooperative programs which – make the hardware useful by providing an

interface to the user and other programs which require the use of the computer's resources.

ICT 106 _Week 12_06 6 school of information technology

• Not all computers need an OS, eg some simple embedded applications. In such applications, a program in ROM controls some system. (eg, a car's engine management system, microprocessor controlled home electronic devices, bank ATM’s etc)

ICT 106 _Week 12_06 7 school of information technology

Services provided by an Operating System

• The services provided by an operating system (OS) can be broken into the following categories:

1. User interface and User Management: commands, GUI etc., login/logout, accounting info, access control, account maintenance

2. I/O Management : I/O services, device management

ICT 106 _Week 12_06 8 school of information technology

3. File System Management - providing an abstract view of secondary storage to the user. Functions include device maintenance, volume maintenance, creation/deletion, backup/recovery

4. Process Management - the running of programs (note: the OS itself is a program). Process creation/deletion, loading, inter-process communication

Page 3: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

3

ICT 106 _Week 12_06 9 school of information technology

5. Memory Management - very important task of OS - even the most simple OS (where there is only 1 process so that process management is not really needed) has to perform memory management. Involves memory allocation, swapping, address translation.

6. CPU Management - interrupt handling, CPU scheduling.

ICT 106 _Week 12_06 10 school of information technology

Mechanisms to call OS services (User Interface)• Calls to operating systems by the user: these

are directed through an interface provided by the OS (DOS command line, Windows - menus, icons, dialog boxes)

• the provision of the User Interface (UI) is another task of an OS: Character UI (CUI) or Graphical UI (GUI).

• Calls to the OS by user programs: User written programs making use of OS Services (via system calls - recall INT 21H)

ICT 106 _Week 12_06 11 school of information technology

System Calls• Calls to the system procedures/functions• But the code which constitutes the system

routines is not part of the collection of userfiles

• The code to be executed may already be sitting within memory

• At link time, appropriate address/references can be made provided address of system routines are known.

ICT 106 _Week 12_06 12 school of information technology

• INT 21h is an example of a system call for one particular OS.

• System calls are also called software interrupts and are generated by the CPU executing an INT n instruction.

• The INT instruction is essentially a fancy variant of the CALL instruction

• Major advantage over CALL instruction relates to software portability

Page 4: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

4

ICT 106 _Week 12_06 13 school of information technology

• Application programs contain “calls” to operating system services via software interrupts

• System software can be in physically different locations on different types of computers -don’t need to know actual address of routine (eg. BIOS)

• Interrupt vectors provide the hooks (connections) between routines desired to be executed, and their actual location (you can check this by examining the IVT).

ICT 106 _Week 12_06 14 school of information technology

• Eg, using debug we can examine element 21h of the interrupt vector table, and then unassemble the instructions found at the address specified at element 21h

• Concept of software interrupt is reasonably standard for a wide range of operating systems: Macintosh, Unix, OS/2

• Known as the TRAP instruction on some machines

ICT 106 _Week 12_06 15 school of information technology

“Cooking” Services (I/O device Management)• “Every day common services”• Typical example is keyboard echo and

backspace correction• Done by software - two components:

reading & writing• Character buffering (interrupt routine)

ICT 106 _Week 12_06 16 school of information technology

• This OS preprocessing of characters before being received by an application program is known as cooked mode– C's scanf function works in cooked mode, in which

special chars are given special processing, eg, the BackSpace key which has ASCII value 8, is given special treatment, and a "backspace action" is performed.

– Prior to hitting the return key, user can revoke previously entered characters by using the BackSpace key

Page 5: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

5

ICT 106 _Week 12_06 17 school of information technology

– In cooked mode no input is considered final until the user hits the return key

– Also, user will have to hit the return key after typing a command, instead of getting instant response

• raw mode is without preprocessing– C Example: getchar & getch – Use online help in Borland C/C++ for further details

• Also, the device drivers which control the operation of the various devices and their communication with the processor

ICT 106 _Week 12_06 18 school of information technology

File System• A file is a named collection of related

information. It is an abstraction provided to the user by an OS

• File system: part of the OS which manages files on secondary memory (eg, disk)

• Disks and associated hardware allow for reading and writing of sectors of information

ICT 106 _Week 12_06 19 school of information technology

• A single disk has two sides (surfaces). Each side is divided into tracks. Tracks are numbered: 0 (outermost), 1(the next one), 2, and so on. A track is divided into sectors. A sector is the smallest unit of information that can be transferred to/from a disk.

• The mapping from name, contents, size, creation date etc. of a file to the physical locations on a disk is handled and maintained by the file management system

ICT 106 _Week 12_06 20 school of information technology

• Implementation of file systems can be different for different OSs (even on the same computer)

• Sectors on a disc are accessed by specifying platter, side, track and sector within track.

• Easiest to deal with logical sector - all sectors on a disk aggregated into a single numbering system: 0, 1, 2, 3....

Page 6: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

6

ICT 106 _Week 12_06 21 school of information technology

• Different DOS services available for physical vs logical sector access (eg. absread (DOS) or DOS interrupt 25 )

• Typical low level OS service provides for a number of sectors of information to be copied from/to memory to/from a disk

• Some OS do not provide to a user such low level access to disk, although the OS itself does this low level disk access all the time.

ICT 106 _Week 12_06 22 school of information technology

File System Functions

• To allow users to create, update and delete their files (new, save, open, close, delete, rename, read, write etc.)

• To allow controlled access to other users’ files in order to share information, eg, read access, write access, execute access etc.

• To allow structuring of files in a manner appropriate for an application

ICT 106 _Week 12_06 23 school of information technology

• Management of secondary memory –users need not worry where on disk the files are stored

• Device independence – allow reference to files by logical names (symbolic) rather than having to use physical device names

• Provide backup and recovery facilities against system failures

ICT 106 _Week 12_06 24 school of information technology

• MS-DOS has an hierarchical, tree structuredfile system

• Top most level known as the root directory• Some files are subdirectories (ie. data

contents are essentially lists of the files contained within them)

• File descriptor: each file has a file descriptor (index entry) which contains information necessary to manage the file,

Page 7: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

7

ICT 106 _Week 12_06 25 school of information technology

Information about a File

– File name– Location on disk (address)– File type, eg, text, object, binary, etc.– File attributes (access rights), eg, read,

write, execute, delete– Current size– Date and time file created/last modified

ICT 106 _Week 12_06 26 school of information technology

• Mapping of logical file name to a physical location on disk is achieved via a file directory

• File directory is like a symbol table –contains the above information about each named file.

ICT 106 _Week 12_06 27 school of information technology

Implementation of File System under DOS

• To look at the details of the DOS implementation, it is essential to know the consecutive disc sector allocation as follows:– Boot record– File allocation table (FAT)– Directory index sectors– File data clusters (cluster 2, 3, ...)

ICT 106 _Week 12_06 28 school of information technology

• Sector 0: boot record - “normally” read into memory upon power up, containing some data - BIOS parameter block (BPB) and a small program boot loader program which reads in and begins executing OS

Page 8: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

8

ICT 106 _Week 12_06 29 school of information technology

• Some data contained in boot record includes:– bytes per sector - bytes 0bh - 0ch– sectors per cluster (a cluster is a set of

consecutive sectors grouped to form one storage unit) - byte 0dh

– number of copies of file allocation table (usually 2 copies of FAT) - byte 10h

ICT 106 _Week 12_06 30 school of information technology

– FAT lists which clusters the files are stored in, and which clusters are currently unused and thus available for new files

– Two copies of FAT are stored on disk because if one of them gets corrupted, the other may be used to recover files.

• number of directory index entries (total number of files) - bytes 11h - 12h

• FAT size in sectors - bytes 16h - 17h

ICT 106 _Week 12_06 31 school of information technology

• Directory index entries (each 20h, 32bytes long)

• Location determined from size and number of copies of FAT (eg. 7 sectors, 2 copies => FAT 1-14 sectors) or (eg. 9 sectors, 2 copies => FAT 1 - 18 sectors)

• Directory index size: 224 entries * 32 bytes ==> 7168 bytes ==> 14 sectors

• Directory index: sectors 15 to 28 (for 7 sector FAT)

ICT 106 _Week 12_06 32 school of information technology

• Each entry contains following at the given byte offsets:– b0..b7: Filename 8 chars.– b8..bA: Extension 3 chars.– bB: Attribute – eg, read-only, hidden, – system file, subdirectory, archive etc– b1A:First cluster (2 bytes)

• Cluster 2 starts after directory index, and numbered consecutively from there, but remember to take into account number of sectors per cluster

Page 9: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

9

ICT 106 _Week 12_06 33 school of information technology

• Looking at contents of “first” cluster of file, will verify it corresponds to the data in the start of the corresponding file

• First cluster indicated in directory index, remaining clusters which constitute the file are contained in the File allocation table

• FAT is a linked list data structure: entry for kth cluster contains link pointing to (k+1) cluster of file

ICT 106 _Week 12_06 34 school of information technology

• Unix and many other modern file systems (from user point of view) are largely similar to MS-DOS although they have no or higher limits on length of file names. Some (& most new) allow 255 chars for filenames and have no concept of extension.

ICT 106 _Week 12_06 35 school of information technology

Process Management• Useful to have several user programs

alternating in execution, eg, background printing, clock, network popup messages

• Known as multi-tasking - it gives the appearance that a computer is running several programs simultaneously

• CPU is still only executing one program at any one time, although several programs may exist in memory at any one time. CPU switches between the tasks very rapidly.

ICT 106 _Week 12_06 36 school of information technology

• Two simplest forms of multi-tasking– Co-operative - eg. Windows (uses

TaskSwitch functions) – Time-sharing

• MS-DOS provides limited multitasking facilities (TSR) but the hardware itself is not the limiting factor - it is the OS

Page 10: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

10

ICT 106 _Week 12_06 37 school of information technology

Process (or task as in multi-tasking)

• Fundamental to the concept of multi-tasking

• An instance of execution of a program - each instance is a process

• Could be same program code (eg. same code segment) but different data (eg. different data segments)

ICT 106 _Week 12_06 38 school of information technology

Multiple processes

• Different programs - different code & data segments

• As examples, consider – Windows - multiple instances of clock,

notepad, ... – Unix facility (‘&’ operator) to startup another

program in the background

ICT 106 _Week 12_06 39 school of information technology

Time sharing (CPU Scheduling)

• All code (programs) required to be executed is within memory or has to be brought into memory

• Executing Code + Data constitutes a Process

• States of a process: Active, Ready, Awaiting some action to complete (blocked) etc

ICT 106 _Week 12_06 40 school of information technology

– Active (running): a process is said to be active if it currently has the CPU

– Ready: a process is said to be in the ready state if it could use a CPU if one was available

– Blocked: a process is said to be in blocked state if it is waiting for some event to happen (eg, I/O transfer) before it can proceed

Page 11: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

11

ICT 106 _Week 12_06 41 school of information technology

Process Table• OS maintains tables of data concerning all

processes• Each process currently in the system is

represented by a data structure (process descriptor) which contains relevant information about the process:

ICT 106 _Week 12_06 42 school of information technology

• Unique identification of the process, eg process name

• Current state of the process (i.e., running, ready, blocked/asleep)

• The process’s priority• Addresses of code & data associated with

the process• Area to save process’s registers

ICT 106 _Week 12_06 43 school of information technology

• Linked list or queue of all processes• More sophisticated OS support priorities, time

sharing intervals (CPU scheduling) etc• Timer interrupts allow OS to periodically take a

look around and decide whether or not to switch control of the CPU to another process

• Time slice or quantum of execution is the basis for providing equity in time of execution of processes

ICT 106 _Week 12_06 44 school of information technology

Round Robin

• the simplest scheduling policy. The CPU time is divided into time-slices.

• A real-time clock generates pulses at regular and frequent intervals (typically 1/100 second).

• At each pulse, the OS performs the following steps:

Page 12: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

12

ICT 106 _Week 12_06 45 school of information technology

• The currently active process is suspended• OS checks the status of each process, in

strict sequence, to see whether the process requires CPU time. The first process requiring CPU time gets its time slice

• When the end of the sequence is reached, the CPU returns to the start of the sequence and repeats the sequence again.

ICT 106 _Week 12_06 46 school of information technology

Context switching • the term used for switching the CPU

between two processes• Wait loop I/O is avoided - tasks requiring

I/O use interrupt driven I/O while other tasks are given normal access to CPU

• Timer interrupt is absolutely essential otherwise OS has no opportunity to intervene and context switch.

ICT 106 _Week 12_06 47 school of information technology

• Context switches require OS to save the state of the currently executing process, and restoring the previous state of the task about to be switched into action

• Return from an interrupt is either to the same process OR to a different process upon a context switch

• Processes may end their turns before allocated time slice has ended by making a system call (eg. I/O access ==> I/O interrupt driven)

ICT 106 _Week 12_06 48 school of information technology

• Usually processes can be given a priority. The higher the priority the more time slices they can get.

• When interrupt driven I/O is combined with process priorities, the ability to put processes to sleep, actions of interdependent processes, etc, the scheduling or context switching algorithms can become quite complex

Page 13: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

13

ICT 106 _Week 12_06 49 school of information technology

• The most important concept to remember is as follows:

• The OS has no power whatsoever when a user program is executing. The OS cannot simply “step in” and stop a user program; either an I/O device interrupt, timer interrupt, or the user program (via system call) results in the user program relinquishing control of the CPU to the OS.

ICT 106 _Week 12_06 50 school of information technology

Memory Management (MM) • Memory Management (MM) is

required for the effective use of a computer even for a single tasking OS (eg. to hold the OS and user program)

• For a multi-tasking OS, MM is absolutely essential.

ICT 106 _Week 12_06 51 school of information technology

• In a computer system which allows multiple programs to be run concurrently, memory must be divided/shared by the resident part of the operating system (some times called the resident monitor) and a number of user programs which may be running (ie. processes).

• It is the function of the OS to perform this task of Memory Management.

ICT 106 _Week 12_06 52 school of information technology

• Why do we want to run multiple programs concurrently?– To make as efficient use of the computer

resources (typically the CPU) as possible. The CPU should not be kept running idle waiting for something to happen.

Page 14: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

14

ICT 106 _Week 12_06 53 school of information technology

• Does the CPU actually stop running?– The CPU goes through the

fetch/execute cycle (FEC) from power up – i.e. it runs something all the time. If there are no user programs to run, what is it running?

ICT 106 _Week 12_06 54 school of information technology

• Running the OS is poor use of CPU.• User programs may not be running all the

time. Such processes could be waiting for I/O - waiting for the user to process a key.

• Think of a word processor. Almost all of the word-processor’s time is spent waiting for a key to be pressed.

ICT 106 _Week 12_06 55 school of information technology

• For a process to run, it must be in memory. We want to keep running as many processes as possible, which means we would need more memory

• One solution is to keep increasing memory by adding more RAM.

• Even though RAM is cheap these days, it still costs more than other solutions to the problem.

ICT 106 _Week 12_06 56 school of information technology

• Also, there is a limit to the amount of RAM that one can use - why is that?

• The size of the address bus puts an upper limit on amount of addressable memory.

Page 15: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

15

ICT 106 _Week 12_06 57 school of information technology

• Another solution is swapping. So instead of sitting in memory while waiting for an I/O event, the process is swapped to disk so that space in memory is made available for another process.

• Swapping is used with different schemes for carving up memory for the different processes that are running.

• The OS occupies a fixed portion of memory. The rest of memory is partitioned for use by the user processes.

ICT 106 _Week 12_06 58 school of information technology

• One scheme has been to use fixed size partitions: – Memory is divided into a number of partitions of

some fixed sizes (fixed equal sizes, or fixed unequal sizes).

– For the scheme with fixed unequal sized partitions, a process brought into memory is placed into the smallest partition that can contain the process (best fit).

ICT 106 _Week 12_06 59 school of information technology

• Fixed size memory partitions are wasteful in terms of computer memory. A process may be much smaller than the smallest available partition resulting in internal fragmentation.

• Also, a process may be too big to fit in any partition. Fixed sized partitioning is generally not used today

ICT 106 _Week 12_06 60 school of information technology

Another approach is to use variable size partitions:• Another approach is to use variable size

partitions: • A process is given only as much space as

needed when it is brought into memory. When things first start out (i.e. in the beginning) this approach looks all right.

Page 16: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

16

ICT 106 _Week 12_06 61 school of information technology

• But over the life cycle of the MM technique, as processes terminate and other processes are spawned, little “holes” will develop in memory which are too small for any process to be slotted in.

• This is again wasting memory – external fragmentation -because the amount of memory used up by these “holes” could be quite large.

ICT 106 _Week 12_06 62 school of information technology

• Another way to partition memory is to use fixed size small chunks of memory called frames. – A program (process) is broken up into similar

fixed size small chunks called pages. – There is still wastage in this scheme but at

most the wastage for each process is only a proportion of a frame. The OS maintains a list of available frames.

ICT 106 _Week 12_06 63 school of information technology

• Another advantage of this technique is that page frames need not be contiguous for a program to be loaded. This leads to better memory utilisation.

• To implement this scheme, the OS maintains a page table for each process. The table maps the process’s page to the memory frames.

• Given a page number and relative address within the page, CPU hardware translates this to frame number and relative address using the page table.

• This technique for dealing with partitioned memory led to the development of virtual memory.

ICT 106 _Week 12_06 64 school of information technology

Virtual Memory• Virtual memory - the effective useable memory by

user(s) and/or OS is larger than the main memory of the computer (actual RAM, core, internal,..)

• Extra memory and contents are swapped to/from disk from/to main memory

• Disk Swap area - special area (contiguous area) is created/allocated on the disk specifically for supporting this swapping

• Actual sectors allocated can affect performance

Page 17: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

17

ICT 106 _Week 12_06 65 school of information technology

• Virtual Address Space - is the range of useable virtual addresses

• Physical Address Space - actual physical addresses corresponding to existing memory

• What does the physical address space depend on?– amount of memory (eg. I have 128 Mb of Ram)?– number of bits making up the address (size of address

bus)?ICT 106 _Week 12_06 66 school of information technology

• Virtual memory support & disk swapping etc is transparent to the user

• User program does not normally need to consider memory management. But to make efficient use of resources, an understanding of the concepts is needed.

• External user can be aware of virtual memory being utilised because of flashing HDD light.

• Program may take extra time

ICT 106 _Week 12_06 67 school of information technology

• Note however, knowledge of “virtual memory” can greatly affect “program efficiency” (ie. more or less execution time)

• The maximum execution speed of a program running in a virtual memory environment can be at most equal but never exceed the execution speed of the same program running on the same hardware but with virtual memory turned off.

• Very often, a program running in a virtual memory system is slower.

ICT 106 _Week 12_06 68 school of information technology

Paging and Paged Memory

• Physical memory is broken up into fixed size chunks called frames

• Each page is of the same size and typically 256 - 4K bytes

Page 18: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

18

ICT 106 _Week 12_06 69 school of information technology

Example implementation • 64k virtual address space with 16 4K

pages– Given any address ==> Page#– Vaddress = 4bit page# + offset into page

• 16k of main memory with 4 4K page frames– Given any main memory address ==> PageFrame#– Paddress = 2 bit page frame# + page offset– All pages cannot be in memory at any one time

ICT 106 _Week 12_06 70 school of information technology

• Page table provides mapping between pages and main memory/disk– 1 bit flag: Page in memory or is not– Several bits relating to location of page on

disk (eg. could be logical sector number)– Page frame # if in memory

ICT 106 _Week 12_06 71 school of information technology

• Vaddress access – Split into Page# and PageOffset– Go through page table to determine whether

page in memory– If not, read page from disk into a page frame

in physical memory ( page fault --> interrupt)– Get PageFrame# from table– Paddress = PageFrame# +PageOffset

ICT 106 _Week 12_06 72 school of information technology

Page replacement policy

• If all page frames are full and a required page not in memory?

• LRU - Least recently used page is a simple and most typical replacement policy

• Reuse the page frame which has been used least recently

• Thrashing is where a program generates page faults frequently and continuously

Page 19: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

19

ICT 106 _Week 12_06 73 school of information technology

Segmentation

• Some details already addressed - we have actually used segments - (remember stack segment, data segment?)

• Segmentation in the Intel Pentium (the Pentium has hardware support for both paging and segmentation)

ICT 106 _Week 12_06 74 school of information technology

• Each virtual (logical) address consists of a 16 bit selector and a 32 bit offset. 2 bits of the selector deal with memory protection or privilege and the other 14 bits take part in addressing.

• Together with the offset, 46 bits can be used for addressing, giving virtual memory space of 246 = 64 Terabytes.

• Without segmentation, virtual memory space is 232 = 4 Gigabytes. The physical address space is also 4 Gbytes as the address bus is 32 bits wide

ICT 106 _Week 12_06 75 school of information technology

• Local & Global Descriptor tables are used to support virtual memory

• LDT local to a program describes its segments corresponding to code, data, stack, etc

• GDT shared by all programs, typically system segments including operating system itself

• Each selector has bits relating to table index, local/global, and privilege level

ICT 106 _Week 12_06 76 school of information technology

• Some of the crucial MM issues specific to 80x86 machines are as follows:

1. How can many processes run the same code? (Ans: through memory sharing)

2. Can one process be prevented from accidentally writing to memory belonging to another? (Ans: use virtual addressing)

3. What if the collective size of all processes & OS exceeds available memory? (Ans: virtual memory)

Page 20: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

20

ICT 106 _Week 12_06 77 school of information technology

Memory Sharing (Issue 1)

• Segmented architecture of 80x86 is ideal for this

• Different processes can be allocated the same code segments, different data segments

ICT 106 _Week 12_06 78 school of information technology

Virtual Addressing (Issue 2)

• In real mode 80x86 support 20bit addressing (00000H to FFFFFH = 1 MB)– Address calculations typified by instruction address

16 * c(CS) + c(IP)

ICT 106 _Week 12_06 79 school of information technology

In protected mode 80x86 machines support following

• 286 - 24 bit addresses ==> 16 MB• 386/486 (and later) - 32 bit addresses ==>

(range: 00000000H to FFFFFFFFH) ==> can address up to 4 GB of RAM

• The OS maintains a Local Descriptor Table (LDT) for each program (task) it loads into memory.

• When a program is loaded, the OS puts appropriate values in the segment registers and physical segment addresses into the LDT.

ICT 106 _Week 12_06 80 school of information technology

• The values in the segment registers are used to index the LDT. Address calculations are typified by instruction address. An LDT entry contains other information too. The CS register shown below also contains other information too)

LDT [ c(CS) ] + c(IP)• OS also maintains a Global Descriptor Tables

(GDT) in memory to store info about all processes in the system

• Notation LDT[n] means contents of nth entry of LDT

Page 21: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

21

ICT 106 _Week 12_06 81 school of information technology

• Entries in LDT are physical addresses (as well as other information), size of which is equal to address size of machine

• Other segments registers identical to CS: DS, SS, ES

• In protected mode, they do not contain segment address

• Instead they contain pointers (selectors) to entries in the LDT table

ICT 106 _Week 12_06 82 school of information technology

• Once segment address is calculated, offset calculations are same as before (add the two values)

• Even in protected mode, offsets are still 16bit for 286 machines, and segment size still restricted to max of 64k

• Protected mode for 386/486 (and later machines) have 32bit offsets, so a segment could fill entire memory space

ICT 106 _Week 12_06 83 school of information technology

• All registers (eg. IP, BX, BP...) are also 32bit and are called EIP, EBX, EBP, ... etc

• Hardware has means to avoid slowdown in performance of continually having to read memory to access DT entries

ICT 106 _Week 12_06 84 school of information technology

• Virtual addressing refers to the fact that in protected mode, addresses only appear to have certain values. Any attempt to access addresses outside these values would cause memory violation.

• Physical addressing is the raw absolute address (continual mapping between virtual and physical addresses via selectors & DT entries). This is the address which is put on the address bus by the CPU.

Page 22: Chapter 2 – Introduction to Operating Systemsftp.it.murdoch.edu.au/units/ICT106/Lectures/ICT106_06_12_EL.pdf · ICT 106 _Week 12_06 5 school of information technology • An Operating

22

ICT 106 _Week 12_06 85 school of information technology

• Associated with each DT entry, is also a size which has been allocated for that selector (segment)

• If a process attempts to access memory outside the allocated segment, an interrupt will be generated.

• This addresses MM Issue 2

ICT 106 _Week 12_06 86 school of information technology

• Memory management and allocation is performed by OS, memory protection is handled by hardware (ie. latter can’t be done by OS, as it is not executing)

• Virtual addressing through the DT also allows for support of the concept of virtual memory (Issue 3)

• Virtual memory make use of the disk, and physically moves memory contents to/from physical memory from/to special regions on the disk (Disk swapping)

ICT 106 _Week 12_06 87 school of information technology

• DT entries also contain a present bit which indicates whether or not the segment is physically in memory or needs to be first read from the disk into memory

• In reading a segment from the disk to memory, if there is not enough physical memory space, a segment in memory may first be required to be saved to disk, with the present bit being changed appropriately

ICT 106 _Week 12_06 88 school of information technology

• Handled by hardware, which generates an interrupt, allow user program to be temporarily suspended while operating system loads a segment from the disk

• Normally, support of this is completely transparent to the user.

• Note: Understand the general concepts only - no need to be able to implement any of these details.