• No results found

Design issues for paging systems

N/A
N/A
Protected

Academic year: 2022

Share "Design issues for paging systems"

Copied!
15
0
0

Loading.... (view fulltext now)

Full text

(1)

Design issues for paging systems

We’ve seen the basic mechanisms of virtual memory system using paging and how page replacement works. To design a system, however, there are a few more things to consider that will tie everything together.

(2)

Locality of reference again

Most modern systems use demand paging, that is, pages are loaded only on demand, not in advance.

Demand paging means that when a process starts, lots of page faults will occur. However due to locality of reference, after a while, the process has most of the pages it needs and settles down to run with relatively few page faults.

It can be seen that such locality is very important and potentially useful for VM design. But how do we measure such locality?

(3)

The working set

The working set is the set of pages a process is currently using.

Given a virtual time t, the working set W (t, ) of a process is defined to be the set of pages of that process that have been referenced in the last virtual time units (from virtual time t + 1 to t).

The virtual time unit is an OS defined unit, e,g., every memory reference.

(4)

The working set

The working set is the set of pages a process is currently using.

Example

1518 2324 1718 2418 1717 1524 1724 18

24 24

15 18 23 24 17 15 18

24 15

17 18 23 23 24 24 17 17 18 18 24 18 17 17 15 15 24 24 17 24 18

24 1524 24 15 18 15 18 23 18 23 24 23 24 17 24 17 18

18 24 24 18 17

18 17 17 15 17 15 24

24 17 17 24 18

24 1524 24 15 18 24 15 18 23 18 23 24 17

24 17 18

18 17 15 17 15 24

17 24 18

24 1524 24 15 18 24 15 18 23

18 23 24 17

18 24 17 15 17 15 24 17 15 24 18

2 3 4 5

window size page

refs

virtualtime

(5)

The working set

The working set is the set of pages a process is currently using.

workingsetsize

stable transient time

stable stable

transient transient

Stable period: working set size remains relatively constant due to locality of reference.

Transient period: process shifts locality, working set expands rapidly first and then drops to a stable level.

(6)

The working set

The working set is the set of pages a process is currently using.

The working set is an inherent property of a running process and is often used as a guiding principle for virtual memory and paging system management in OS.

(7)

Resident set and its management

The resident set of a process is the portion of it that is currently in memory (the number of physical frames it occupies). The

resident set is a runtime property of a process (do not confuse it with the working set).

The resident set management refers to deciding how much memory to allocate to a particular process.

Small resident set: page faults increase and cause thrashing, i.e., a program causing page faults every few instructions.

When thrashing occurs, the system is busy doing I/O rather than working on useful things.

Large resident set: due to locality, does not significantly improve page fault rates, wasting memory.

We want to allocate enough frames to a process, but no more!

(8)

Page replacement scope

When a process causes page fault, where to page in the requested new page?

Local page replacement:

replace pages only from the frames allocated to the process that causes the page fault.

Global page replacement: All unlocked pages in main memory can be candidate for replacement. (Potentially stealing other processes’

resident set.) Locked pages are pages that cannot be swapped out, e.g., some system

components.

10 A0 7 A1

5 A2

4 A3

6 A4

3 A5 9 B0 4 B1

6 B2

2 B3

5 B4

6 B5 12 B6 3 C1

5 C2

6 C3

age

load A6

10 A0 7 A1

5 A2

4 A3

6 A4

15 A6 9 B0 4 B1

6 B2

2 B3

5 B4

6 B5 12 B6 3 C1

5 C2

6 C3

age

10 A0 7 A1

5 A2

4 A3

6 A4

3 A5 9 B0 4 B1

6 B2

15 A6

5 B4

6 B5 12 B6 3 C1

5 C2

6 C3

age

local

replacement global replacement

(9)

Working set as a guide to resident set size

Local page replacement effectively correspond to allocating every process a fixed fraction of the memory. In general, global

replacement works better since it allows the resident set of a process to change dynamically.

The working set can be used as a guide to the allocate the resident set size: if the entire working set is in memory, then the process will run without causing many page faults until it shifts locality.

1 Monitor working set of each process.

2 Remove pages from a process’s resident set that are not in its working set.

3 A process may execute only if its working set is in memory.

(10)

Page fault frequency as an approximation to working set

Practically using working set is difficult:

Working set measurement is costly and hard.

Working set predication is also hard.

Optimal working set window size is unknown.

Instead, the page fault frequency (PFF) algorithm measures the number of page faults per second (possibly taking a running mean over past seconds as well).

A process’s resident set is expanded if its page fault rate is too high.

A process’s resident set is reduced if its page fault rate drops below certain threshold.

(11)

Multiprogramming level and load control

Load control decides how many processes to keep in memory (the degree of multiprogramming). This is a medium term scheduling issue (more on scheduling in later lectures).

CP U u ti li za ti o n

multiprogramming level

optimal

(number of processes)

idling thrashing

(12)

Multiprogramming level and load control

Load control decides how many processes to keep in memory (the degree of multiprogramming). This is a medium term scheduling issue (more on scheduling in later lectures).

If there are so many processes in memory that the system is

thrashing (i.e., the resident set of each process is too small to hold its working set), then suspend (swap out completely) some

processes.

This shows that even with paging, suspending processes is still needed, only now process suspension is used to reduce potential demand for memory, rather than to reclaim blocks of it for

immediate use.

(13)

Page size

What is the impact of the size of a page? Do we want smaller or larger pages?

Arguments for small pages:

Reduces internal fragmentation for the final page of a process.

Reduce unused program to be in memory (i.e., a small resident size is possible with small pages, but may not be possible with large pages).

Arguments for large pages:

Large page reduces the page table size.

Large page reduces I/O time during page transfer (e.g.,

loading 64 512-byte pages may take much longer than loading one 32KB page, the reason will be clear in later lectures).

(14)

Optimal page size?

We can analyze an optimal page size for the purpose of minimizing space wastage. Let the average process size be s bytes and the page size be p bytes. Assume each page table entry requires e bytes. Then the approximate number of pages needed per process is ps, the page table occupies sep bytes of space. The wasted

memory in the last page of the process due to internal fragmentation is p2. Thus total space overhead is: sep + p2.

The first term sep goes up if page size is small, while the second term p2 goes up if page size is large. The optimal value thus must lie in between. Take the first derivative with respect to p and equating it to 0, we have: pse2 + 12 = 0. The solution is: p = p

2se.

Most system nowadays have page size 4KB or 8KB. Also as main memory gets larger, the page size tends to get larger as well (but not linearly).

(15)

Virtual memory interface

Until now, our discussion assumed that the virtual memory system is transparent to processes and programmers. That is, all they see is a large virtual address space. That is the main benefit of VM.

However in some advanced systems, programmers have some

control over the memory map and can use it in nontraditional ways to enhance program behavior (such as the “mmap” and related

functions we’ve seen before).

Lots of “tricks” can be made possible by a few OS provided VM primitives exposed in the user space.

References

Related documents

Although no HP minerals have been previously reported in the Château-Renard meteorite, we have observed within the melt veins a number of HP minerals and report on them here for

[r]

For African Americans reaction to the 1883 decision reveals not only the continuity of black political participation in the public sphere beyond the Reconstruction years, but also

If the user selects to apply a 2.048MHz clock to the RSYSCLK pin, the user can use the Receive Blank Channel Select registers ( RBCS1:RBCS4 ) to determine which channels will have

This data element may contain the same information as ''Provider location address telephone number''.. Provider Business Mailing Address

We have designed absorbing boundary conditions and perfectly matched layers for some scalar second order partial differential operators: the Helmholtz equation and the wave

No significant relationship was found between the overall satisfaction levels for the specialist services and gender, age, number of partners, years as GP, practice size or

Analysis of a3 lox/- Dlx5/6-Cre, netrin-1 -/- double mutant mice provides genetic evidence for netrin1-α3β1 integrin interactions and demonstrates their necessity for