Docsity

Segmentation and Paging - Problems with Solutions | EECS 370, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
Segmentation and Paging
Recall the problems with base&bound relocation:
• Fragmentation of Memory: variable size holes
• Only one segment. How can two processes share code while keeping
private data areas (e.g. shared editor)?
Solutions
• Paging: Divide physical and virtual memory into fixed size chunks
(pages). Keep a table mapping virtual page (numbered consecutively from
0) to a physical page (arbitrary, not necessarily sequential).
• Segmentation: Processes split up into several logical areas of memory,
e.g., code, data, stack. Some segments can be made read-only.
Multiple segments (segmentation)
Permit process to be split between several areas of memory, called segments.
Use a separate base and bound for each segment, and also add two protection bits
(read and write).
pf3
pf4
pf5

Partial preview of the text

Download Segmentation and Paging - Problems with Solutions | EECS 370 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Segmentation and Paging

Recall the problems with base&bound relocation:

•^

Fragmentation of Memory: variable size holes

-^ Only one segment. How can two processes share code while keepingprivate data areas (e.g. shared editor)?

Solutions

•^

Paging:

Divide physical and virtual memory into fixed size chunks (pages). Keep a table mapping virtual page (numbered consecutively from0) to a physical page (arbitrary, not necessarily sequential).

-^ Segmentation:

Processes split up into several logical areas of memory,

e.g., code, data, stack. Some segments can be made read-only.

Multiple segments (segmentation) Permit process to be split between several areas of memory, called

segments.

Use a separate base and bound for each segment, and also add two protection bits(read and write).

Segment

Base

Bounds

RW

XXX

XXX

Each memory reference indicates a segment and offset:

•^

Top bits of address select segment, low bits the offset.segment #

offset

Segment table holds the bases and bounds for all the segments of a process. Whathappens on a context switch?Memory mapping procedure consists of a table lookup + add + compare. (Draw apicture)

•^

Do segments have to start on even 000 physical addresses?

-^ What if hardware provides eight segments but your operating system (e.g.UNIX) only uses two or three?

Segmentation pros:

o^ Segments can be shared, swapped, and assigned to storage independently.Show an example where code is shared between two processes safely.

Assume that code is segment 0 for both P1 and P2 and we would like them toshare the code in physical memory, but not share data (e.g., two users using thegcc library).Similar ideas apply to sharing libraries, so that only one copy of large libraries(e.g., X windows) is needed in physical memory when running multipleapplications that use the library. Segmentation Cons:

(This problem also applies to base and bound schemes)

Paging The goal of paging is to make allocation and swapping easier, and to reducememory fragmentation.Make all chunks of memory the same size, call them

pages.

Typical sizes range

from 512 to 8k bytes.For each process, a page table defines the base address of each of that process'pages along with read-only and valid bits.Translation process: page number always comes directly from the virtual address.Since page size is a power of two, no comparison or addition is necessary. Just doa table lookup and bit substitution. (Show a picture)Pros:

•^

Easy to allocate: keep a free list of available pages and grab the first one.Easy to swap since everything is the same size, which is usually the samesize as disk blocks to and from which pages are swapped. Cons:

•^

Efficiency of access: even small page tables are generally too large toload into fast memory in the relocation box. Instead, page tables are keptin main memory and the relocation box only has the page table's baseaddress. It thus takes one overhead reference for every real memoryreference.Solution from EECS 370 to get access time back to close to one realmemory reference?