UNIT - 3 - OS Theory
UNIT - 3 - OS Theory
Memory Management
– Load time: Must generate relocatable code if memory location is not known at compile time
– Execution time: Binding delayed until run time if the process can be moved during its
execution from one memory segment to another
• Need hardware support for address maps (e.g., base and limit registers)
Compiled code
Source Code
29-03-2021 18CSC205J Operating Systems- Memory Management 15
Assembler
Assembly Code
Machine Code
• An address seen by the memory unit—that is, the one loaded into the
memory-address register of the memory—is commonly referred to as a
physical address.
23
Dynamic linking
• Static linking
• System libraries and program code seperately
• Some OS support only static linking
• Dynamic linking
• Linking is postponed until execution time
• Wastage of both disk space and main memory is
avoided
24
Swapping
• A process can be swapped temporarily out of memory to a backing store,
and then brought back into memory for continued execution
• Total physical memory space of processes can exceed physical memory
• This increases the degree of multiprogramming in a system
• Backing store – Normally its hard disk
25
CONTIGUOUS MEMORY
ALLOCATION
• For example, the operating system contains code and buffer space for device
drivers.
Fixed Partitioning
Variable Partitioning
• There are many solutions to this problem. The first-fit, best-fit, and worst-fit
strategies are the ones most commonly used to select a free hole from the set of
available holes.
Question
Given five memory partitions of 100Kb, 500Kb, 200Kb, 300Kb, 600Kb (in order), how would the
first-fit, best-fit, and worst-fit algorithms place processes of 212 Kb, 417 Kb, 112 Kb, and 426 Kb (in
order)? Which algorithm makes the most efficient use of memory?
• But because the space is not contiguous, so the process can not be stored.
3. It does not utilize the main memory effectively. It utilizes the main memory effectively.
Memory allocated to a process may be slightly larger External fragmentation exists when there is enough
than the requested memory. The difference between total memory space to satisfy a request but available
these two numbers is internal fragmentation. spaces are not contiguous.
First-fit and best-fit memory allocation does not First-fit and best-fit memory allocation suffers from
suffer from internal fragmentation. external fragmentation.
Systems with fixed-sized allocation units, such as the Systems with variable-sized allocation units, such as
single partitions scheme and paging suffer from the multiple partitions scheme and segmentation
internal fragmentation. suffer from external fragmentation.
Fig(b) shows the mapping of these pages to the free frames available and
the updated list of free frames available in the physical memory.
Page Table
• Page table is kept in main memory
• Page-table base register (PTBR) points to the page table
• Page-table length register (PTLR) indicates size of the page table
• Simple solution to this problem is to divide the page table into smaller pieces We can accomplish
this division in several ways
• A logical address (on 32-bit machine with 1K page size) is divided into:
• a page number consisting of 22 bits
• a page offset consisting of 10 bits
• Since the page table is paged, the page number is further divided into:
• a 12-bit page number
• a 10-bit page offset
• where p1 is an index into the outer page table, and p2 is the displacement within the page of the inner
page table
Hierarchical Page Tables
• Entry consists of the virtual address of the page stored in that real memory
location, with information about the process that owns that page
Inverted Page Table Architecture
Paging - ARM
• The paging scheme used by ARM processors uses a 2 level page table.
• The first level page table has 16kB size and each entry covers a region
of 1MB (sections).
• The second level page tables have 1kB size and each entry covers a
region of 4KB (pages).
• The TLB also supports 16MB sections and 64kB pages
Paging - ARM
• On ARMv4 and ARMv5 pages might also be divided into what the
manual calls 'subpages‘
• Example : for a 4KB page, 1KB subpages, and for a 64KB page, 16KB
subpages.
• The ARM processor supports 2 independent page tables.
• The first page table can be abbreviated from the full 16kB
• The second page table is always 16KB in size and is used for addresses
beyond the end of the first page table.
SEGMENTATION
Non-Contiguous Memory Allocation
Segmentation
• The programmer talks about “the stack,” “the math library,” and “the
main program” without caring what addresses in memory these
elements occupy.
• Libraries that are linked in during compile time might be assigned separate segments.
• The loader would take all these segments and assign them segment numbers.
• Segment table – maps two-dimensional physical addresses; each table entry has:
• base – contains the starting physical address where the segments reside in memory
• limit – specifies the length of the segment
• Segment-table base register (STBR) points to the segment table’s location in memory
• The 10 higher order bits reference the page directory – outermost page
table
• The innermost 10 bits refer the inner page table
• Lower order 12 bits refer the offset in the page
• 1 bit in page directory is Page-Size flag
• If set, indicates 4MB page rather than the default 4KB page
Intel IA-32 Paging Architecture
Intel IA-32 Page Address Extensions
• 32-bit address limits led Intel to create page address extension (PAE),
allowing 32-bit apps access to more than 4GB of memory space
• Paging went to a 3-level scheme
• Top two bits refer to a page directory pointer table
• Page-directory and page-table entries moved to 64-bits in size
• Net effect is increasing address space to 36 bits – 64GB of physical
memory
• Linux and MAC support PAE
• But, 32-bit versions of Windows desktop operating systems still provide
support for only 4 GB of physical memory, even if PAE is enabled.
Intel IA-32 Page Address Extensions
Intel x86-64
• Current generation Intel x86 architecture
• Support for larger physical and logical address spaces
• 64 bit-systems can address 264 of addressable memory (16 exabytes)
• In practice, only implement 48 bit addressing
• Page sizes of 4 KB, 2 MB, 1 GB
• Four levels of paging hierarchy
• Can also use PAE so virtual addresses are 48 bits and physical
addresses are 52 bits
Reference
• Abraham Silberschatz, Peter Baer Galvin, Greg Gagne, Operating
systems, 9th ed., John Wiley & Sons, 2013