paging and segmentation in operating system

26
PAGING AND SEGMENTATION - Raj Mohan. B

Upload: raj-mohan

Post on 22-Apr-2015

534 views

Category:

Engineering


0 download

DESCRIPTION

Want to know how a 10GB game works on your 2GB RAM ? well, you know where to click ;)

TRANSCRIPT

Page 1: Paging and Segmentation in Operating System

PAGINGAND

SEGMENTATION

- Raj Mohan. B

Page 2: Paging and Segmentation in Operating System

MEMORY & WHY A MEMORY?

Stores all kind of data and information

Page 3: Paging and Segmentation in Operating System

TYPES OF MEMORY1. Physical Memory- Total memory of the computer. EX:

RAM

2. Logical Memory- CPU memory3. Virtual memory- An imaginary memory area supported by some operating systems (for example, Windows). It is an extension of logical memory

Page 4: Paging and Segmentation in Operating System

VIRTUAL MEMORY If the size of the program is greater than the available

memory size, then the concept of virtual memory is used

Ever wondered how a 10GB Game like God Of War fits into your 2GB RAM computer?

Page 5: Paging and Segmentation in Operating System

PAGING Paging is a memory management technique in which

the memory is divided into fixed size pages. Paging is used for faster access to data. It is a logical concept

Page 6: Paging and Segmentation in Operating System

PROGRAM X

STATEMENT 1

STATEMENT 2

STATEMENT 3

STATEMENT 4

STATEMENT 5

STATEMENT 6

STATEMENT 7

Suppose a program X consists of 7 statements. But the memory can hold only 4 statements, then Paging concept is used.

PROGRAM X

STATEMENT 1STATEMENT 2STATEMENT 3STATEMENT 4STATEMENT 5STATEMENT 6STATEMENT 7

Page 7: Paging and Segmentation in Operating System

FRAMES Frames are physical concept It is present in the RAM We cannot see Pages, but we can see Frames

Page 8: Paging and Segmentation in Operating System

MAPPING Converting pages(virtual address) into frames (physical

address) Enables program to be executed It is performed by the Memory Management Unit (M.M.U.)

CPU(WHERE

PAGES ARE DIVIDED)

MMU

Memory 1Memory

2Virtual address of each page

Converts virtual address to physical address

If any error error occurs at any physical address, it is quickly retrieved from memory and sent to the CPU

Page 9: Paging and Segmentation in Operating System

EXAMPLE-LOGICAL TO PHYSICAL ADDRESS TRANSLATION IN PAGING

0 0 0 0 0 1 0 1 1 1 0 1 1 1 0

6-bit page # 10-bit offset #

16-bit logical address

0 0 0 0 1 0 1

1 0 0 0 1 1 0

0 0 0 1 1 0 0 1 1 1 0 1 1 1 1 0

Page Table

16-bit Physical address

Page 10: Paging and Segmentation in Operating System

LOGICAL ADDRESS AND PHYSICAL ADDRESS

LOGICAL ADDRESS

PAGE NUMBER(WHICH PAGE IS TO BE

SEARCHED IN THE MEMORY)

PAGE OFFSET(WHICH BYTE OF DATA IS TO BE READ FROM THAT

PAGE)

MAXIMUM OF 6 BYTES MAXIMUM OF 10 BYTES

PHYSICAL ADDRESS

FRAME NUMBER FRAME OFFSET

MAXIMUM OF 6 BYTES MAXIMUM OF 10 BYTES

Page 11: Paging and Segmentation in Operating System

EXAMPLELOGICAL ADDRESS

PAGE P0

P1

P2

P3

P4

P5

P6

P7

MAPPING

PHYSICAL ADDRESS

P7

P2

P1

P5

FO

F1F2

F3

Page 12: Paging and Segmentation in Operating System

pageframe 0

pageframe 1

pageframe 2

pageframe 3

physical memory

offset

physical address

F3’s Value

F3

F2

F0

page table(MMU)

offset

logical address

P=3

PAGING TRANSLATION

CPU

P0P1P2P3P4P5P6P7

F1

Page 13: Paging and Segmentation in Operating System

PAGING PROTECTIONThe paging process is protected by the

concept of insertion of an additional bit called VALID/INVALID BIT

Consider a 14 bit address space= 2^14=16383 bytes

Let us set an address limit of 10468 If five process are defined within this address

space (P0-P4), it is considered as a Valid bitProcess P5 has started before 10468, so that

alone is consideredThe remaining processes are considered as

Invalid In this way the pages are internally

fragmentedThis is how Paging is protected

Page 14: Paging and Segmentation in Operating System
Page 15: Paging and Segmentation in Operating System

• No external Fragmentation

• Simple memory management algorithm

• Swapping is easy (Equal sized Pages and Page Frames)

• Internal fragmentation

• Page tables may consume more memory.

ADVANTAGES

DISADVANTAGES

Page 16: Paging and Segmentation in Operating System

SEGMENTATION Segmentation is one of the most common ways to achieve

memory protection. Because internal fragmentation of pages takes place, the user’s

view of memory is lost The user will view the memory as a combination of segments In this type, memory addresses used are not contiguous Each memory segment is associated with a specific length and a

set of permissions. When a process tries to access the memory it is first checked to

see whether it has the required permission to access the particular memory segment and whether it is within the length specified by that particular memory segment.

Page 17: Paging and Segmentation in Operating System

1

3

2

4

1

4

2

3

user space physical memory space

LOGICAL VIEW OF SEGMENTATION

Free

Free

Page 18: Paging and Segmentation in Operating System

Segment table - maps two-dimensional user defined address into one-dimensional physical address

base - starting physical address of the segment limit - length of segment

SEGMENTATION HARDWARELogical Address

space

Segment number

Offset

The maximum length of the offset value is 12 bits

Page 19: Paging and Segmentation in Operating System

Logical Address

0<d<limit

Page 20: Paging and Segmentation in Operating System
Page 21: Paging and Segmentation in Operating System

SEGMENT PROTECTION The advantage of segmentation is that the protection is

associated within the segments Sharing can be achieved by segments referencing multiple

processes Two processes that need to share access to a single segment

would have the same segment name and address in their segment tables

Page 22: Paging and Segmentation in Operating System
Page 23: Paging and Segmentation in Operating System

No internal fragmentation Segment tables consume

less memory than page Lends itself to sharing data

among processes. Lends itself to protection.

ADVANTAGESDISADVANTAGES

Costly memory management algorithm

As processes are loaded and removed from memory , the free memory space is broken into little pieces ,causing external fragmentation

Page 24: Paging and Segmentation in Operating System

COMBINING SEGMENTS AND PAGING

Page 25: Paging and Segmentation in Operating System

In a combined paging/segmentation

system a user’s address space is broken up into a

number of segments. Each segment is broken up into a

number of fixed-sized pages which are

equal in length to a main memory frame

Segmentation is visible to the programmer

Paging is transparent to the

programmer

Page 26: Paging and Segmentation in Operating System

THANK YOU !