-
memory management
-
memory paging (דפדוף)
-
memory management unit (MMU)
-
virtual memory
-
mapping
- bitmap
- linked lists
- free list
- quick fit
-
page fault frequency (PFF)
-
reference string
-
- is the number of frames allocated to the process
- is the set of pages in memory after processing
-
distance string
-
- if no such exists, then
-
-
Bélády’s anomaly
-
thrashing
-
fragmentation (ריסוק)
- external fragmentation
- internal fragmentation
-
Memory segmentation
- segment table
-
swapping
- ”Moving a process between main memory and a backing store. A process may be swapped out to free main memory temporarily and then swapped back in to continue execution.” (Galvin, 2018)
- swap space - “Secondary storage backing-store space used to store pages that are paged out of memory.” (Galvin, 2018)
-
page replacement
- local and global replacement
- page replacement algorithms
-
locality of reference (aka the principle of locality)
- temporal locality
- spatial locality
- memory locality (or data locality)
virutal memory
- virutal memory
- page (or memory page or virtual page)
- “a fixed-length contiguous block of virtual memory, described by a single entry in a page table” (Wikipedia)
- page frame
- ”the smallest fixed-length contiguous block of physical memory into which memory pages are mapped by the operating system.” (Wikipedia)
-
memory paging (or paging)
-
-
page table entry (PTE) contains:
- page frame number
- present/absent bit
- 1 = in memory
- 0 = on disk (then CPU generates a page fault exception)
- protection bits
- read/write/execute permissions
- reference bit
- modified bit
- caching disabled/enabled
-
page frame number (PFN) (which is the physical page number)
-
page frame
-
dirty bit
-
-
- tradeoffs:
- small pages: reduced internal fragmentation; better memory utilization;
- large pages: smaller page table; faster I/O; better TLB usage;
- optimal page size formula:
- process size
- page table entry size
- tradeoffs:
- (set by the ISA)
-
-
-
(set by the actual RAM installed)
-
translation lookaside buffer (TLB) - cache for page table
-
copy-on-write (COW) (or implicit sharing or shadowing)
-
hard miss
-
page walk
-
page fault
- Minor page fault
- Major page fault
- segmentation fault
-
inverted page table (IPT)
-
demand paging
-
shared library
-
position-independent code (PIC)
-
paging daemon
memory allocation
- allocation algorithms:
- first fit - first hole that is big enough to hold the process
- pros: fast
- cons:
- next fit - similar to ‘first fit’ but it starts searching from where the last allocation ended
- pros:
- cons:
- best fit - smallest hole that is still big enough for the process
- pros:
- cons: external fragmentation
- worse fit - largest available hole
- pros:
- cons:
- quick fit -
- pros:
- cons:
- first fit - first hole that is big enough to hold the process
- buddy memory allocation
page replacement algorithms
- theoretically optimal (OPT)
- not recently used (NRU)
(R,M) = (referenced, modified)- initially: (R,M)=(0,0)
- periodically: for each page :
- on write:
- on read/write:
- on page fault:
- classify pages into:
- Evict a page from lowest nonempty class
- classify pages into:
- FIFO
- second-chance (FIFO + reference bit R)
- loop: p = head(Q)
- if R(p) = 0:
- dequeue Q
- evict p
- break
- else if R(p) = 1:
- move p to tail of Q
- if R(p) = 0:
- loop: p = head(Q)
- clock
- like second-chance but with circular list with pointer hand
- least recently used (LRU)
- on reference to page :
- update
- on page fault:
- evict (‘temporal locality’)
- on reference to page :
- not frequently used (NFU)
- each page has -bit counter,
- At each clock interrupt:
- For every page :
- For every page :
- on page fault: evict
- (Problem: NFU accumulates counts forever. So it does not forget old history. Thus, NFU approximates frequency, not recency.)
- The aging algorithm (“improved NFU”)
- At each clock tick:
- on page fault: evict
- At each clock tick:
- working set
- pages referenced by the most recent memory references up to time .
- For small , the working set grows quickly. For large , it stabilizes.
- approximation for references:
-
- working set window (in seconds of CPU time)
- current virtual time of the process
- virtual time counts the CPU time actually used by the process
-
- algorithm:
- on reference to page :
- update
- on page fault:
- for each page in memory:
- if , then set and
- else if
- if , then evict the page
- if , then keep the page
- if no page is evicted
- if some pages had (so all pages have ), then:
- evict the page with the largest age
- if all pages have , then:
- evict a page at random
- if some pages had (so all pages have ), then:
- for each page in memory:
- on reference to page :
- pages referenced by the most recent memory references up to time .
- WSClocktodo
- if R=1, then:
- virtual-time(p)=current virtual time
- R=0
- advance head
- else if R=0, then:
- age = current virtual time - time of last use
- if age >
- if M=0, evict page
- else,
-
else if age
- if R=1, then:
Linux
- address space:
- text segement
- data segment
- initialized data
- uninitialized data, which is called the block starting symbol (abbreviated to
.bssorbss. origin: BSS from Block Started by Symbol)- initialized to zero after loading
- stack
References
- Galvin, Abraham Silberschatz; Greg Gagne; Peter B. (2018). Operating System Concepts. Wiley Global Education US.