240 likes | 516 Views
University College of Science Mohanlal Sukhadia University. A presentation on : Memory management Presented By : Prithvipal Singh Ranawat, Punit Kumar, Punita Acharya. MEMORY MANAGEMENT. Memory management under Linux has two components:-
E N D
University College of ScienceMohanlalSukhadia University A presentation on : Memory management Presented By : Prithvipal Singh Ranawat, Punit Kumar, Punita Acharya
MEMORY MANAGEMENT Memory management under Linux has two components:- Allocating and freeing physical memory: pages and small blocks of memory. The second handles virtual memory.
Management Of Physical MemoryPAGE ALLOCATOR The primary physical- memory manager in the Linux kernel is the page allocator . Allocator is responsible for allocating or freeing all physical pages. Allocator uses a buddy-heap algorithm to keep track of available physical pages.
BUDDY HEAP A buddy heap allocator pairs adjacent unit of allocatable memory. Two small freed allocated partner regions are combined to form a larger region. A larger free region will be subdivided into two partners to satisfy the request ,when small memory request can’t be satisfied by allocation of an existing small free region.
SPLITTING OF MEMORY IN BUDDY HEAP 16 KB 8KB 8KB 8KB 4KB 4KB
All memory allocation in the Linux kernel occur either Statically or Dynamically . Several specialized memory management subsystems use the underlying page allocator to manage their own pool of memory are :- VIRTUAL MEMORY SYSTEM. THE KMALLOC VARIABLE-LENGTH ALLOCATOR. THE KERNELS TWO PERSISTENT DATA CACH :- BUFFER CACHE. PAGE CACHE.
KMALLOC It is analogous to the ‘C’ language’s malloc function. It is an additional allocator for arbitrary size request. Kmalloc service allocates entire page on demand ,but splits them into smaller piece.
BUFFER CACHE It is the Kernel’s main cache for block-oriented devices. Buffer cache is the main mechanism through which I/O to these devices is performed.
PAGE CACHE The native disk-based file system and the NFS network file system use the PAGE CACHE. It can cache the networked data.
Virtual Memory • Creation of the pages. • Loading of the pages in to memory. • The virtual memory manager maintain two views : • A set of separate region • A set of the pages
A set of separate region • It is a logical view, describing instructions that the VM system has received. • Each region is described by vm_area_struct, defines the property of region. • They are linked by Balanced Binary tree to allow fast searching.
A set of the pages • This view is stored in the HW page tables. • It gives the current location of each page. • It is managed by the kernel’s software- interrupt handlers.
Virtual Memory Region • Properties : • Backing store for the region. • Reaction to write. • Backing store for the region :- It describes that where the page come for a region.
2) Reaction to write :- • Mapping of region in process’s address space • It can be private or shared. If a process writes to a privately mapped region, than the pager detects that a copy-on-write is necessary to keep the changes local to the process. If a process writes to a shared region in updating of the object mapped into the region, so that the changes will be visible immediately to any other process that is mapping that object.
Lifetime of a Virtual Address Space • Creation of a new virtual address space in two situations :- • Process runs a new program with exec( ). • On creation of a new process by the fork( ).
1. Process runs a new program withexec ( ). It is easy. When a prog. Is executed, the process is executed, the process is given a new, completely empty virtual address space. It is up to the routines for loading the prog. To populate the address space with virtual memory regions.
2. On creation of a new process by the fork ( ). It involves creating a complete copy of the existing process’s virtual address space. Kernel copies the parent process’s vm_area_struct, then creat a new set page table for child.rrr
Swapping and Paging • Swapping :- It is a technique in which processes are swapped in or out of main memory to the disk. • Paging :- The paging system divided into tw section: • Policy Algorithm • Paging Mechanism
Policy Algorithm :- It decides which pages to write out to disk and when to write them. • Paging Mechanism :- It carries out the transfer and pages data back into physical memory when they are needed again.
Kernel Virtual Memory The page-table entire that map to these kernel pages are marked as protected, so the pages are not visible or modifiable when the processor is running in user mode.
Execution & loading of user programs Triggered by exec() system call Verifying the permission right.
No single routine in Linux for loading a new program. • Invokes a new program • Change in standard format for Linux binary files.
Mapping of programs into memory Pages of file mapped into regions of virtual memory. Loader sets the initial memory mapping for the program to start. Pages loaded using demand paging. Example:- ELF format.
Static & dynamic linking Static linking: not efficient Dynamic linking: more efficient.