0% found this document useful (0 votes)
12 views95 pages

Week 5 (2013-2014) Operating Systems

Uploaded by

007wasr
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views95 pages

Week 5 (2013-2014) Operating Systems

Uploaded by

007wasr
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 95

Introduction to Operating Systems

Lecture 5

Lecture 5 contents
Memory Management 1. Contiguous Memory Allocation
1. 2. 3. 4. 1. Fixed Partitioning Variable Partitioning Compaction Relocation Paging
1. 2. Page table implementation Page sharing

2. Non-Contiguous Memory Allocation

2.

Segmentation
2

3. Comparison

Memory management

Memory management includes


Memory needs to be allocated efficiently to pack as many processes into memory as possible Memory protection, Processes should not be able to reference memory locations in another process without permission While the program is executing, it may be swapped to disk and returned to main memory at a different location (relocated) Memory allocation of process is either:

Contiguous memory allocation: Each process is allocated a single contiguous area in memory.

Example : Fixed and Variable partitioning

Non-Contiguous memory allocation : Portions of a process address space are distributed among different memory areas

Example : Paging and segmentation


3

Operating Systems

Contiguous Allocation

1 Fixed Partitioning
memory

OS n KB 3n KB small Medium

6n KB

Large

In this method, memory is divided into partitions whose sizes are fixed. OS is placed into the lowest bytes of memory. Relocation of processes is not needed

1 Fixed Partitioning
memory

OS n KB 3n KB small Medium

Processes are classified on entry to the system according to the memory they require. We need one Process Queue (PQ) for each class of process.

6n KB

Large

large area Q

1 Fixed Partitioning
memory OS n KB 3n KB small Medium

6n KB

Large

large area Q

If a process is selected to allocate memory, then it goes into memory and competes for the processor. The number of fixed partition gives the degree of multiprogramming. Since each queue has its own memory region, there is no competition between queues for the memory.
7

1 Fixed Partitioning
memory OS n KB 3n KB small Medium

6n KB
Large large area Q

The main problem with the fixed partitioning method is how to determine the number of partitions, and how to determine their sizes.

Fixed Partitioning with Swapping


memory

OS 2K 6K P1 P2

P3

P4 P5

12K

empty

empty

This is a version of fixed partitioning that uses RRS with some time quantum. When time quantum for a process expires, it is swapped out of memory to disk and the next process in the corresponding process queue is swapped into the memory.

Fixed Partitioning with Swapping


memory OS 2K Secondary storage P1

P3

6K

P2

P4 P5

12K

empty

empty

10

1. Fixed Partitioning with Swapping


memory OS 2K

Swap out P1 Secondary storage

P3 P1
P2

6K

P4 P5

12K

empty

empty

11

Fixed Partitioning with Swapping


memory OS 2K P3

Swap in P3 Secondary storage

P1

6K

P2

P4 P5

12K

empty

empty

12

Fixed Partitioning with Swapping


memory OS 2K Secondary storage P3

P1

6K

P2

P4 P5

12K

empty

empty

13

Fixed Partitioning with Swapping


memory OS 2K

Swap out P3 Secondary storage

P1 P3
P2

6K

P4 P5

12K

empty

empty

14

Fixed Partitioning with Swapping


memory OS 2K P1

Swap in P1 Secondary storage

P3

6K

P2

P4 P5

12K

empty

empty

15

1. Fixed Partitioning with Swapping


memory OS 2K Secondary storage P1

P3

6K

P2

P4 P5

12K

empty

empty

16

Fragmentation
Fragmentation leads to poor memory utilization
memory OS 2K 6K P1 (2K) Empty (6K) If a partition is being used by a process requiring some memory smaller than the partition size, then it is called an internal fragmentation.
17

If a whole partition is currently not being used, then it is called an external fragmentation.

12K

P2 (9K) empty

Empty (3K)

2. Variable Partitioning

With fixed partitions we have to deal with the problem of determining the number and sizes of partitions to minimize internal and external fragmentation. If we use variable partitioning instead, then partition sizes may vary dynamically. In the variable partitioning method, we keep a table (linked list) indicating used/free areas in memory.

18

2. Variable Partitioning

Initially, the whole memory is free and it is considered as one large block. When a new process arrives, the OS searches for a block of free memory large enough for that process. We keep the rest available (free) for the future processes. If a block becomes free, then the OS tries to merge it with its neighbors if they are also free.

19

2. Variable Partitioning
There are three algorithms for searching the list of free blocks for a specific amount of memory. First Fit Best Fit Worst Fit

20

first fit

First Fit : Allocate the first free block that is large enough for the new process. This is a fast algorithm.

21

first fit
OS P1 12 KB <FREE> 10 KB

Initial memory mapping

P2 20 KB <FREE> 16 KB

P3 6 KB <FREE> 4 KB

22

first fit
OS P1 12 KB <FREE> 10 KB

P4 of 3KB arrives

P2 20 KB <FREE> 16 KB

P3 6 KB <FREE> 4 KB

23

first fit
OS

P4 of 3KB loaded here by FIRST FIT

P1 12 KB P4 3 KB <FREE> 7 KB P2 20 KB <FREE> 16 KB

P3 6 KB <FREE> 4 KB

24

first fit
OS P1 12 KB

P5 of 15KB arrives

P4 3 KB <FREE> 7 KB P2 20 KB <FREE> 16 KB

P3 6 KB <FREE> 4 KB

25

first fit
OS

P5 of 15 KB loaded here by FIRST FIT

P1 12 KB P4 3 KB <FREE> 7 KB P2 20 KB P5 15 KB <FREE> 1 KB P3 6 KB <FREE> 4 KB

26

Best fit
Best Fit : Allocate the smallest block among those that are large enough for the new process. In this method, the OS has to search the entire list, or it can keep it sorted and stop when it hits an entry which has a size larger than the size of new process. This algorithm produces the smallest left over block. However, it requires more time for searching all the list or sorting it If sorting is used, merging the area released when a process terminates to neighboring free blocks, becomes complicated.
27

Best fit
OS P1 12 KB <FREE> 10 KB

Initial memory mapping

P2 20 KB <FREE> 16 KB

P3 6 KB <FREE> 4 KB

28

Best fit
OS P1 12 KB

P4 of 3KB arrives

<FREE> 10 KB

P2 20 KB <FREE> 16 KB

P3 6 KB <FREE> 4 KB

29

Best fit
OS

P4 of 3KB loaded here by BEST FIT

P1 12 KB <FREE> 10 KB

P2 20 KB <FREE> 16 KB

P3 6 KB P4 3 KB <FREE> 1 KB
30

Best fit
OS P1 12 KB

P5 of 15KB arrives

<FREE> 10 KB

P2 20 KB <FREE> 16 KB

P3 6 KB P4 3 KB <FREE> 1 KB
31

Best fit
OS

P5 of 15 KB loaded here by BEST FIT

P1 12 KB <FREE> 10 KB

P2 20 KB P5 15 KB <FREE> 1 KB P3 6 KB P4 3 KB <FREE> 1 KB
32

Worst fit
Worst Fit : Allocate the largest block among those that are large enough for the new process. Again a search of the entire list or sorting it is needed. This algorithm produces the largest over block.

33

Worst fit
OS

Initial memory mapping

P1 12 KB <FREE> 10 KB

P2 20 KB <FREE> 16 KB

P3 6 KB <FREE> 4 KB

34

Worst fit
OS P1 12 KB

P4 of 3KB arrives

<FREE> 10 KB

P2 20 KB <FREE> 16 KB

P3 6 KB <FREE> 4 KB

35

Worst fit
OS P1 12 KB P4 of 3KB Loaded here by WORST FIT <FREE> 10 KB

P2 20 KB P4 3 KB <FREE> 13 KB P3 6 KB <FREE> 4 KB

36

Worst fit
OS

No place to load P5 of 15K

P1 12 KB <FREE> 10 KB

P2 20 KB P4 3 KB <FREE> 13 KB P3 6 KB <FREE> 4 KB

37

Worst fit
OS

No place to load P5 of 15K

P1 12 KB <FREE> 10 KB

P2 20 KB P4 3 KB <FREE> 13 KB P3 6 KB <FREE> 4 KB

Compactio n is needed !!

38

3. Compaction

Compaction is a method to overcome the external fragmentation problem. All free blocks are brought together as one large block of free space. Compaction requires dynamic relocation. Certainly, compaction has a cost and selection of an optimal compaction strategy is difficult. One method for compaction is swapping out those processes that are to be moved within the memory, and swapping them into different memory locations
39

3. Compaction
OS

Memory mapping before compaction

P1 12 KB <FREE> 10 KB

P2 20 KB P4 3 KB <FREE> 13 KB P3 6 KB <FREE> 4 KB

40

3. Compaction
OS P1 12 KB

P2 20 KB P4 3 KB

Swap out P2

P3 6 KB

41

Compaction
OS P1 12 KB P2 20 KB

Swap in P2
Secondary storage

P4 3 KB

P3 6 KB

42

Compaction
OS P1 12 KB P2 20 KB

Secondary storage P4 3 KB Swap out P4

P3 6 KB

43

compaction
OS P1 12 KB P2 20 KB P4 3 KB

Swap in P4 with a different starting address


P3 6 KB

Secondary storage

44

compaction
OS P1 12 KB P2 20 KB P4 3 KB Secondary storage Swap out P3 P3 6 KB

45

compaction
OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB

Swap in P3
Secondary storage

46

compaction
OS P1 12 KB

Memory mapping after compaction

P2 20 KB P4 3 KB P3 6 KB <FREE> 27 KB

Now P5 of 15KB can be loaded here

47

3. Compaction
OS P1 12 KB P2 20 KB P4 3 KB P3 6 KB P5 12 KB <FREE> 12 KB

P5 of 15KB is loaded

48

4. Relocation

Instructions using memory addresses are address-

sensitive

Relocation is needed if program is to execute correctly in


some other memory area: involves changing addresses
49

4. Relocation

Relocation may be performed in two ways:

Static (before program is executed) Dynamic (during program execution)


Alternative 1: suspend execution and relocate Alternative 2: use a relocation register

50

Contiguous Memory Allocation

In contiguous memory allocation each process is allocated a single contiguous area in memory

Faces the problem of memory fragmentation

Apply techniques of memory compaction and reuse


Compaction requires a relocation register Lack of this register is also a problem for swapping

51

Operating Systems

Contiguous Allocation

Memory types

Physical memory : It referred to as the physical storage or the real storage. RAM is the amount of real storage, and is the total amount of memory installed on a computer. Logical memory : Is the address space, assigned to a logical partition, that the operating system perceives as its main memory. Virtual memory involves the separation of logical memory as perceived by the users and the physical memory. The separation allows an extremely large virtual memory for programmers. The programmer no longer need to worry about the amount of physical memory available.
53

1. Paging

Paging permits a program to allocate noncontiguous blocks of memory. The OS divide each process into pages which are blocks of small and fixed size. Then, it divides the physical memory into frames which are blocks of size equal to page size. Each page is matched to a corresponding frame in a page table saved by the OS in the registry for faster access or in memory for large page tables or both. Each page and each frame is subdivided into an equal set of words
Logical memory P0 P1 P2 P3 page 0 1 2 3

PAGE TABLE
frame 4 3 1 5 Attributes

Physical memory f0 P2 f1 f2 P1 P0 P3 f3 f4 f5

54

1. Paging
Logical memory
Word 0 Word 1 Word 7 Word 8 Page 0 (P0)

Physical memory
Word 0 Word 1 Frame 3 (f3) Word 7

PAGE TABE
Page Frame

Word 9
Word 15 Word 16 Word 17 Word 23

Page 1
(P1)

0
1 2

3
6 4

Word 16
Word 17 Word 23 Frame 4 (f4)

Page 2 (P2)

Word 8 Word 9 Word 15 Frame 6 (f6)

55

1. Paging

The OS uses a page table to map program pages to memory frames. Page size (S) is defined by the hardware. Logical Physica

With this arrangement, the words in the program have an address called as logical address. Every logical address is formed of <p,d> pair

addres s p d

l addres s f d

Logical address: <p,d>

frame

page

attr

p is page number p = logical address div S d is displacement (offset)

f
p f
physical memory

d = logical address mod S

Physical address is calculated as (f*S+d)

The first the frame number f corresponding to page p.

logical memory

For example : If the program is 7 statement (words), the page is 4 words only. The program will be placed in two pages (p0 and p1). Then the page p of the six word is (6 div 4 = 1 p1) and 56 the displacement d of the fifth word is (6 mode 4 = 2 2 words from the start).

1 Page table implementation

Every access to memory should go through the page table. Therefore, it must be implemented in an efficient way.

How to Implement The Page Table?


1. 2. 3.

Using fast dedicated registers Keep the page table in main memory Use content-addressable associative registers

57

1. Using fast dedicated registers

Keep page table in fast dedicated registers. Only the OS is able to modify these registers. However, if the page table is large, this method becomes very expensive since requires too many registers.

58

1. Using fast dedicated registers


logical address PTLR: Page Table Length Register

d
physical address YES

P<PTLR
NO ERROR

access PT in register s
rat

access memor y
mat

Effective Memory Access Time emat=rat+mat

2. Keep the page table in main memory

In this second method, the OS keeps a page table in the memory, instead of registers. For every logical memory reference, two memory accesses are required:
1. 2.

To access the page table in the memory, in order to find the corresponding frame number. To access the memory word in that frame

This is cheap but a time consuming method.

60

2. Keep the page table in main memory


logical address

PTBR: Page Table Base Register PTLR: Page Table Length Register

d Access PT entry in Memory at address PTBR + p


mat physical address

YES

P<PTLR
NO ERROR

access memor y
mat

Effective Memory Access Time: emat=mat+mat=2mat

3. Use content-addressable associative registers

This is a mixing of first two methods. Associative registers are small, high speed registers built in a special way so that they permit an associative search over their contents. That is, all registers may be searched in one machine cycle simultaneously. However, associative registers are quite expensive. So, a small number of them should be used. In the overall, the method is not-expensive and not-slow.

62

3. Use content-addressable associative registers


logical address physical address

f Found? Yes (HIT)

No (MISS) P<PTL R
No ERROR Yes

search PT in AR
rat

Access PT entry in Memory at address PTBR + p


mat

physical address

d access memory
mat

Effective Memory Access Time:

h: hit ratio

Emat=h *ematHIT + (1-h) * ematMISS =h(rat+mat)+(1-h)(rat+mat+mat)

3. Use content-addressable associative registers

Assume we have a paging system which uses associative registers. These associative registers have an access time of 30 ns, and the memory access time is 470 ns. The system has a hit ratio of 90 %. rat=30 ns mat=470ns h=0.9

64

3. Use content-addressable associative registers


rat=30 ns, mat=470ns, h=0.9

Now, if the page number is found in one of the associative registers, then the effective access time: ematHIT = 30 + 470 = 500 ns. Because one access to associative registers and one access to the main memory is sufficient.

65

3. Use content-addressable associative registers


rat=30 ns, mat=470ns, h=0.9

On the other hand, if the page number is not found in associative registers, then the effective access time: ematMISS = 30 + (470+470) = 970 ns. Since one access to associative registers and two accesses to the main memory are required.

66

3. Use content-addressable associative registers


rat=30 ns, mat=470ns, h=0.9 ematHIT = 500 ns, ematMISS = 970 ns.

Then, the emat is calculated as follows: emat= h *ematHIT + (1-h) * ematMISS = 0.9 * 500 + 0.1 * 970 = 450 + 97 = 547 ns

67

Sharing Pages

Sharing pages is possible in a paging system, and is an important advantage of paging. It is possible to share system procedures or programs, user procedures or programs, and possibly data area. Sharing pages is especially advantageous in time-sharing systems.

68

Sharing Pages

A reentrant program (non-self-modifying code = read only) never changes during execution. So, more than one process can execute the same code at the same time. Each process will have its own data storage and its own copy of registers to hold the data for its own execution of the shared program.

69

Sharing Pages

Example 3.4 Consider a system having page size=30 MB. There are 3 users executing an editor program which is 90 MB (3 pages) in size, with a 30 MB (1 page) data space. To support these 3 users, the OS must allocate 3 * (90+30) = 360 MB space. However, if the editor program is reentrant (non-self-modifying code = read only), then it can be shared among the users, and only one copy of the editor program is sufficient. Therefore, only 90 + 30 * 3 = 180 MB of memory space is enough for this case
70

P0 P1 P2 P3

User-1 e1 e2 e3 data1

PT-1 Page# 0 1 2 3 PT-2 Page# 0 1 2 3 PT-3 Page# 0 1 2 3

Frame# 8 4 5 7

P0 P1 P2 P3

User-2 e1 e2 e3 data2

Frame# 8 4 5 12

P0 P1 P2 P3

User-3 e1 e2 e3 data3

Frame# 8 4 5 10

f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15

Physical Memory OS OS OS e2 e3

data1 e1

71

P0 P1 P2 P3

User-1 e1 e2 e3 data1

PT-1 Page# 0 1 2 3 PT-2 Page# 0 1 2 3 PT-3 Page# 0 1 2 3

Frame# 8 4 5 7

P0 P1 P2 P3

User-2 e1 e2 e3 data2

Frame# 8 4 5 12

P0 P1 P2 P3

User-3 e1 e2 e3 data3

Frame# 8 4 5 10

f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15

Physical Memory OS OS OS e2 e3

data1 e1

data 2

72

P0 P1 P2 P3

User-1 e1 e2 e3 data1

PT-1 Page# 0 1 2 3 PT-2 Page# 0 1 2 3 PT-3 Page# 0 1 2 3

Frame# 8 4 5 7

P0 P1 P2 P3

User-2 e1 e2 e3 data2

Frame# 8 4 5 12

P0 P1 P2 P3

User-3 e1 e2 e3 data3

Frame# 8 4 5 10

f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15

Physical Memory OS OS OS e2 e3

data1 e1 data3
data 2

73

P0 P1 P2 P3

User-1 e1 e2 e3 data1

PT-1 Page# 0 1 2 3

Frame# 8 4 5 7

User-2 PT-2 User 2 terminates: P0 e1 Page# Data2 page is removed P1memory, e2 but editr 0 from P2 1 pagese3 remain.. P3 data2 2 3 User-3 e1 e2 e3 data3 PT-3 Page# 0 1 2

Frame# 8 4 5 12

P0 P1 P2 P3

Frame# 8 4 5 10

f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15

Physical Memory OS OS OS e2 e3

data1 e1 data3

74

P0 P1 P2 User 1 P3

data1 is also removed from memory.


P0 P1 P2 P3 User-2 e1 e2 e3 data2

User-1 e1 e2 e3 terminates: data1

PT-1 Page# 0 1 2 3 PT-2 Page# 0 1 2 3 PT-3 Page# 0 1 2

Frame# 8 4 5 7

Frame# 8 4 5 12

P0 P1 P2 P3

User-3 e1 e2 e3 data3

Frame# 8 4 5 10

f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15

Physical Memory OS OS OS e2 e3

e1

data3

75

P0 P1 P2 P3

User-1 e1 e2 e3 data1

PT-1 Page# 0 1 2 3 PT-2 Page# 0 1 2 3

Frame# 8 4 5 7

P0 P1 P2 P3

User-2 e1 e2 e3 data2

When User 3 terminates: PT-3 User-3 Data-3 P0 e1 and also editor Page# segments are P1 e2 0 removed from 1 P2 e3 memory. P3 data3 2
3

Frame# 8 4 5 12

Frame# 8 4 5 10

f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15

Physical Memory OS OS OS

76

2. Segmentation

In segmentation, programs are divided into variable size segments, instead of fixed size pages. This is similar to variable partitioning, but programs are divided to small parts. Every logical address is formed of a segment name and an offset within that segment. In practice, segments are numbered. Programs are segmented automatically by the compiler or assembler.

77

OS

2. Segmentation

main Func 1

For example, a C compiler may create segments for: the code of each function the local variables for each function the global variables. main

Func 2

Data 1 Func 1 Func 2 Data 2

Data 1
Data 3

Data 2
Data 3

Logical memory

Physical memory

2. Segmentation

For logical to physical address mapping, a segment table is used. When a logical address <s, d> is generated by the processor:
1.

2.
3.

Base and limit values corresponding to segment s are determined using the segment table The OS checks whether d is in the limit. (0 d < limit) If so, then the physical address is calculated as (base + d), and the memory is accessed.

79

2. Segmentation
Logical address s d No ERROR 0d <limit
base

OS

Segment Table
d

segment s

Yes

seg. #

limit

base

attr

acess the word at physical address = base + d


Physical memory

2. Segmentation
Example 3.5 Generate the memory map according to the given segment table. Assume the generated logical address is <1,1123>; find the corresponding physical address.

Segment 0 1 2 3

Limit 1500 200 700 2000

Base 1000 5500 6000 3500


81

OS

2. Segmentation
1000

Segment 0

Limit 1500

Base 1000

s0

1500 2500 3500

1
2 3

200
700 2000

5500
6000 3500
s3
2000

5500

s1

200 5700 6000 700 6700

s2

Physical memory
82

OS

2. Segmentation
1000

Segment 0

Limit 1500

Base 1000

s0

1500 2500 3500

1
2 3

200
700 2000

5500
6000 3500

s3

2000

5500
Logical address: <3,1123> s=3, d=1123 Check if d<limit? 1123<2000, OK Physical address= base+d=3500+1123=4623

s1 s2

200

5700 6000 6700

700

Physical
83

OS

2. Segmentation
1000

Segment

Limit

Base

s0
Base= 3500

1500 2500 3500

0
1 2 3

1500
200 700 2000

1000
5500 6000 3500

s3

2000 5500

Logical address: <3,1123> s=3, d=1123 Check if d<limit? 1123<2000, OK Physical address= base+d=3500+1123=4623

s1

200 5700 6000 700 6700

s2

Physical memory
84

OS

2. Segmentation
1000

Segment 0

Limit 1500

Base 1000
Base= 3500

s0

1500 2500 3500

1
2 3

200
700 2000

5500
6000 3500
4623 d= 1123

s3

2000 5500

Logical address: <3,1123> s=3, d=1123 Check if d<limit? 1123<2000, OK Physical address= base+d=3500+1123=4623

s1

200 5700 6000 700 6700

s2

Physical memory
85

2. Segmentation

Segment tables may be implemented in the main memory or in associative registers, in the same way it is done for page tables. Also sharing of segments is applicable as in paging. Shared segments should be read only and should be assigned the same segment number.

86

OS

Sharing Segments
user1 s0 s1
Editr
Data-1
1000

ST1 seg 0 1

lim 1500 2000

base 1000 3500

Editr

1500 2500 3500

Data-1

2000 5500

Physical memory
87

OS

Sharing Segments
user1
s0 s1
Editr ST1 seg 0 1 lim 1500 2000 base 1000 3500 Data-1 lim 1500 200 base 1000 5500 Data-2
200 5700 2000 5500 1000

Editr

1500 2500 3500

Data-1

user2 s0 s1
Editr Data-2

ST2 seg 0 1

Physical memory
88

OS

user1 s0 s1 user2 s0 s1 user3 s0 s1

Sharing Segments
Editr Data-1 ST1 seg 0 1 lim 1500 2000 base 1000 3500 Editr
1500 2500 3500 1000

Editr Data-2

ST2 seg 0 1

lim 1500 200

base 1000 5500

Data-1

2000 5500

Data-2 ST3 seg Editr 0 1 lim 1500 700 base 1000 6000 Data-3

200 5700 6000 700 6700

Data-3

Physical memory
89

OS

user1 s0 s1

Sharing Segments
Editr Data-1 ST1 seg 0 1 lim 1500 2000 base 1000 3500 Editr
1500 2500 3500 1000

User 2 terminates: Data-2 removed from memory, but editr remains.. user3 s0 s1
Editr

Data-1

2000 5500

ST3 seg 0

6000

lim 1500

base 100

Dat-3

700 6700

Data-3

700

6000

Physical memory
90

OS

Sharing Segments
User 1 terminates: Data-1segment is removed from memory.
1000

Editr

1500 2500

user3 s0 s1
Editr ST3 seg 0 1 Data-3 lim 1500 700 base 100 6000
700

6000 6700

Data-3

Physical memory
91

OS

Sharing Segments

When User 3 terminates: Data-1 Data-3and segment also editor and also segments editor segment are are removed removed from from memory.

Physical memory
92

Paging vs segmentation

Paging: separates physical organization from logical address space Uses fixed-size units called pages, which are stored in page frames. Requires page table to keep track of (possibly many) pages. Segmentation: preserves users structural view of logical address space Uses variable-size units called segments.
93

Memory Management Schemes


Internal fragmentation contiguousThere is external fragmentation (as address There is no internal memory spaces are allocated contiguously and holes fragmentation allocation develop as finished processes release its (variable size space and new processes are allocated and method) the size of the new process is almost smaller than the old one) pure paging There is no external fragmentation There is internal fragmentation (it appears in the last frame because the process size almost not a multiplex of page size ) pure There is external fragmentation There is no internal segmentation (fragmentation would occur as segments of fragmentation finished processes are replaced by segments of new processes. and the size of the new process is almost smaller than the old one)
Method External fragmentation

ability to share code It does not allow processes to share code.

Able to share code between processes

Able to share code between processes

94

Operating Systems

Lecture 5

You might also like