OS & Paging
CS-446/646
C. Papachristos
Robotic Workers (RoboWork) Lab
University of Nevada, Reno
OS & Paging
Remember: “Swapping”(/“Paging”)
“Swapping”(/“Paging”) from the OS perspective:
Dirty vs Clean Pages
CS446/646 C. Papachristos
OS & Paging
Restarting Fault-ing Instructions
CS446/646 C. Papachristos
OS & Paging
“Swapping”(/“Paging”) Challenges
1) How to resume a Process after a Fault?
2) Page Replacement Policy
CS446/646 C. Papachristos
OS & Paging
Locality
CS446/646 C. Papachristos
OS & Paging
Working Set Model (more later)
CS446/646 C. Papachristos
OS & Paging
Working Set Model (more later)
CS446/646 C. Papachristos
OS & Paging
“Swapping”(/“Paging”) Challenges (continued)
2-a) What to fetch?
CS446/646 C. Papachristos
OS & Paging
Page Replacement
2-b) What to evict?
The Page Replacement Algorithm determines how this is done
CS446/646 C. Papachristos
OS & Paging
Selecting Physical Pages
CS446/646 C. Papachristos
OS & Paging
First-In First-Out (FIFO) Page Replacement
CS446/646 C. Papachristos
Phys Page | 1 | 2 | 3 | 4 | 1 | 2 | 5 | 1 | 2 | 3 | 4 | 5 |
0 | 1 | 1 | 1 | 4 | 4 | 4 | 5 | | | 5 | 5 | ✔ |
1 | | 2 | 2 | 2 | 1 | 1 | 1 | ✔ | | 3 | 3 | |
2 | | | 3 | 3 | 3 | 2 | 2 | | ✔ | 2 | 4 | |
OS & Paging
First-In First-Out (FIFO) Page Replacement
CS446/646 C. Papachristos
Phys Page | 1 | 2 | 3 | 4 | 1 | 2 | 5 | 1 | 2 | 3 | 4 | 5 |
0 | 1 | 1 | 1 | 1 | ✔ | | 5 | 5 | 5 | 5 | 4 | 4 |
1 | | 2 | 2 | 2 | | ✔ | 2 | 1 | 1 | 1 | 1 | 5 |
2 | | | 3 | 3 | | | 3 | 3 | 2 | 2 | 2 | 2 |
3 | | | | 4 | | | 4 | 4 | 4 | 3 | 3 | 3 |
OS & Paging
Belady’s Anomaly
CS446/646 C. Papachristos
OS & Paging
Optimal Page Replacement
CS446/646 C. Papachristos
Phys Page | 1 | 2 | 3 | 4 | 1 | 2 | 5 | 1 | 2 | 3 | 4 | 5 |
0 | 1 | 1 | 1 | 1 | ✔ | | 1 | ✔ | | | 5 | ✔ |
1 | | 2 | 2 | 2 | | ✔ | 2 | | ✔ | | 2 | |
2 | | | 3 | 3 | | | 3 | | | ✔ | 3 | |
3 | | | | 4 | | | 5 | | | | 4 | |
OS & Paging
Belady’s Algorithm
CS446/646 C. Papachristos
OS & Paging
Least Recently Used (LRU) Page Replacement
CS446/646 C. Papachristos
Phys Page | 1 | 2 | 3 | 4 | 1 | 2 | 5 | 1 | 2 | 3 | 4 | 5 |
0 | 1 | 1 | 1 | 1 | ✔ | | 1 | ✔ | | 1 | 1 | 5 |
1 | | 2 | 2 | 2 | | ✔ | 2 | | ✔ | 2 | 2 | 2 |
2 | | | 3 | 3 | | | 5 | | | 5 | 4 | 4 |
3 | | | | 4 | | | 4 | | | 3 | 3 | 3 |
OS & Paging
Least Recently Used (LRU) Page Replacement
CS446/646 C. Papachristos
OS & Paging
CS446/646 C. Papachristos
OS & Paging
CS446/646 C. Papachristos
OS & Paging
CS446/646 C. Papachristos
OS & Paging
CS446/646 C. Papachristos
OS & Paging
CS446/646 C. Papachristos
OS & Paging
CS446/646 C. Papachristos
OS & Paging
CS446/646 C. Papachristos
OS & Paging
CS446/646 C. Papachristos
OS & Paging
Other Page Replacement Algorithms
Random Eviction
Least Frequently Used (LFU)
Most Frequently Used (MFU)
CS446/646 C. Papachristos
OS & Paging
“Swapping”(/“Paging”) Methods
Naïve Page Replacement:
CS446/646 C. Papachristos
OS & Paging
“Swapping”(/“Paging”) Methods
Page Buffering
CS446/646 C. Papachristos
OS & Paging
Fixed vs Variable Space
How to determine how much Memory to allow for each Process?
1) Fixed Space Algorithms
2) Variable Space Algorithms
CS446/646 C. Papachristos
OS & Paging
Working Set (WS) Model
Memory usage
Definition
CS446/646 C. Papachristos
OS & Paging
Working Set (WS) Size
Definition
CS446/646 C. Papachristos
OS & Paging
Working Set (WS) Size
Example: gcc Working Set
CS446/646 C. Papachristos
OS & Paging
Working Set Problems
Problems
CS446/646 C. Papachristos
OS & Paging
Working Set Changes across Phases
CS446/646 C. Papachristos
OS & Paging
CS446/646 C. Papachristos
OS & Paging
An “Indirect” Approach: Page Fault Frequency (PFF)
Definition
CS446/646 C. Papachristos
OS & Paging
Thrashing
Thrashing
CS446/646 C. Papachristos
OS & Paging
Reasons for Thrashing
CS446/646 C. Papachristos
80/20 Rule has broken
OS & Paging
Thrashing & Multiprogramming
CS446/646 C. Papachristos
OS & Paging
Dealing with Thrashing
CS446/646 C. Papachristos
OS & Paging
CS446/646 C. Papachristos
OS & Paging
Complications of “Swapping”(/“Paging”)
C. Papachristos
OS & Paging
CS446/646 C. Papachristos
OS & Paging
The User-Level Perspective
Memory-Mapped Files
CS446/646 C. Papachristos
OS & Paging
The User-Level Perspective
The mmap() System Call
void *mmap (void *addr, size_t len, int prot,
int flags, int fd, off_t offset);
CS446/646 C. Papachristos
OS & Paging
The User-Level Perspective
More Virtual Memory System Calls
int msync(void *addr, size_t len, int flags);
int munmap(void *addr, size_t len)
int mprotect(void *addr, size_t len, int prot)
int mincore(void *addr, size_t len, char *vec)
CS446/646 C. Papachristos
OS & Paging
The User-Level Perspective
Exposing information of Page Faults to the User-Level
CS446/646 C. Papachristos
struct sigaction {
union { /* signal handler */
void (*sa_handler)(int);
void (*sa_sigaction)(int, siginfo_t *, void *);
};
sigset_t sa_mask; /* signal mask to apply */
int sa_flags;
};
int sigaction (int sig,
const struct sigaction *act,
struct sigaction *oact);
OS & Paging
The User-Level Perspective
Exposing information of Page Faults to the User-Level
Example: OpenBSD/i386 siginfo
CS446/646 C. Papachristos
struct sigcontext {
int sc_gs; int sc_fs; int sc_es; int sc_ds;
int sc_edi; int sc_esi; int sc_ebp; int sc_ebx;
int sc_edx; int sc_ecx; int sc_eax;
int sc_eip; int sc_cs; /* instruction pointer */
int sc_eflags; /* condition codes, etc. */
int sc_esp; int sc_ss; /* stack pointer */
int sc_onstack; /* sigstack state to restore */
int sc_mask; /* signal mask to restore */
int sc_trapno;
int sc_err;
};
OS & Paging
The User-Level Perspective
User-Level Virtual Memory “Tricks”
Combination of mprotect()/sigaction() very powerful
CS446/646 C. Papachristos
Next Lecture Reading Preparation
Operating Systems – Three Easy Pieces (https://pages.cs.wisc.edu/~remzi/OSTEP/)
Virtualization
CS446/646 C. Papachristos
Time for Questions !
CS-446/646
CS446/646 C. Papachristos