170 likes | 566 Vues
Linux Vs. Windows NT Memory Management Hitesh Kumar. Introduction. Linux and Windows NT use Virtual Memory with paging. The memory management is platform independent. These platforms provide the support for paging with varying levels of page tables.
E N D
Linux Vs. Windows NT Memory Management Hitesh Kumar
Introduction • Linux and Windows NT use Virtual Memory with paging. • The memory management is platform independent. • These platforms provide the support for paging with varying levels of page tables. • The platform chosen for explanation is Intel Pentium/x86.
Linux Memory Management • Linux uses two separate memory management schemes like SVR4 and Solaris. • These Two Schemes are: a. Virtual memory management for user process. b. Kernel memory management for the use of Kernel. • The complete 4GB memory(linear address space of Pentium /x86) is divided into two parts. • The first 0-3GB(0 x BFFF FFFF) is used for user process. • The next 3GB to 4GB part is used for the kernel.
4GB Kernel space 3GB User Space 0 Linux Address Space
Address Generation In x86 • x86 provides the support forboth Segmentation and Paging. • Maximum Segment Size is 4GB; the complete linear address space of the processor. • Smaller size segments are created by specifying limit field. • Logical Address 1. Logical address must be provided to locate a byte, which is the combination of segment selector and offset.
Continue 2. Segment Selector selects the segment descriptor, a data structure which contains the base address of the segment. • Linear Address 1.The offset is added into the base address to create the linear address of the byte. • Physical Address 1. If paging is not enabled then linear address is directly used to access the byte in the physical memory. 2. If paging is enabled then linear address is broken into 3 parts: Page Directory(10), Page Table(10), Offset(12). 3. The page size is 4KB.
Logical Address Selecter offset Linear Address Space Linear Address segment Lin Addr Dir Table offset Global Desc. Table Physical Address Space Segment Descriptor Page Phy Addr. Page Dir Page Table Entry Entry Segmentation and Paging In x86
How Linux Uses This? • Uses Flat Memory Model. • All the segments in the user space are of 3GB. • The segment in kernel space are of 1GB and start from 3GB. • Each process contains its own page directory and maps the full 4GB space. • The kernel mode is entered by switching the segments from user space to kernel space.
Continue • Linux uses three level page table structure: 1. PAGE GLOBAL DIRECTORY. 2. PAGE MIDDLE DIRECTORY. 3. PAGE TABLE. • The software handling middle level does nothing on x86. • Page Replacement Algorithm Linux uses second chance clock algorithm for page replacement, means uses one bit.
Physical Memory Management • Linux uses zone allocator to allocate the physical pages of memory. • Memory is divided into zones for different purposes like DMA. • Memory from each zone is allocated in 2n –paged size blocks , by using Buddy system .
Kernel Memory Management • Kernel does frequent memory allocation for small sized objects. • Only zone allocator is inefficient for this. • The idea of “Object Caching” is used, because most of the time is wasted in initialization and destruction of objects. • Slab allocator is used for dividing the 2n - paged blocks into small buffers.
Kmem slab Kmem bufctl Kmem bufctl Kmem bufctl buf buf buf unused Slab Layout
Windows NT Memory Management • Like Linux, it divides the memory into two parts. • 2GB is allocated for user space and 2GB is used for kernel space. • The address generation scheme is same as of Linux.
4GB Kernel space 2GB User Space 0 Windows NT Address Space
Page Frame States • Page-Frame States 1. Valid 2. Modified. 3. Standby 4. Free 5. Zeroed 6. Bad.
Page Table Page frame database Valid Modified Free Standby Valid Free PTE PTE PTE Page Frame Database