Linux Memory ManagementCase Study :                            Operating SystemMuhammad  Ather  Rasool    IS/17115/Aut-07/MMuhammad Muzammil         IS/17104/Aut-07/MMuhammad Zahid Majeed     IS/17105/Aut-07/MFederal Urdu university of Arts, Science & Technology,.
Introduction:Linux is a UNIX like system that has gained popularity in recent years.Development begins in 1991.Two different GUI (GNOME & KDE) for Linux.In early days, Linux development revolved around central OS kernel.Linux kernel:  Is an entirely original piece of SW developed from scratch by the Linux community.
Components of Linux MemoryTwo ComponentsPhysical memory:kernel is loaded in memoryrest of memory is available for user pages Allocate and free physical memory pagesVirtual Memory: Each Linux process on a 32 bit get 3 GB for virtual addressingRemaining 1 GB reserve for its Page Table and kernel dataFrequently accessed pages will be on the "hot" listFree pages will be on the "cold" or "free" list
PagingPage Size: Intel 4 KB, Alpha 8 KBLinux kernel is the page allocatorEach process has its own page tableThe entire page table may take up too much main memoryPage tables are also stored in virtual memoryWhen a process is running, part of its page table is in main memory
Fetch PolicyLinux use a demand paging With no preparing And no working set conceptThere is a system call in which user can give a hint that a certain page may be needed soonDemand paging
Linux Memory ManagementThree level page table structurePage directoryPage middle directoryPage table6
7Fig 1
Placement PolicyAll page frames are grouped into 10 lists of blocks that contain groups of 1, 2, 4, 8, 16, 32,64, 128, 256, and 512 contiguous page frames respectively If a small area is needed and only a larger area is available, the larger area is split into two Halves (buddies), possibly repeatedlyWhen a block is released, the kernel attempts to merge together pairs of free buddyBuddy Algorithm
Buddy Algorithm problemLinux manages memory using the buddy algorithm. The algorithm leads to the internal fragmentation because if we want 65 page chunks w required 128 page chunksFor this problem to solve Linux has a second memory allocation which manages smaller units separately
Fig 2:Buddy Algorithm
Replacement PolicyPaging system  can divided into two sections First policy algorithm decides which pages to write out to disk, and when to write them.Second the paging mechanism carries out the transfer and pages data back into physical memory when they are needed again.Under Linux a clock is used, and every page has an age that is adjusted on each pass of the clockAge is measure of youthfulness of pages
Clock Algorithm – Another Implementation of Second ChanceOrder pages in circular list“Hand” of the clock points to the page to be replaced currentlyWhen required to evict a pageIf page pointed to has R=0, then evict itIf R=1, then reset R and move hand forwardClock algorithm can be used with NRU (decision based on both R and M bits)
Fig 3: Clock Algorithm for replacement
Replacement ScopeLocal replacement policy – chooses only among the resident pages of the process that generated page fault in selecting a page to replaceGlobal replacement policy – considers all unlocked pages in main memory as candidates for replacement, regardless of which process owns a particular pageGlobal policies are more attractive because of the simplicity of implementation and minimal overhead
ReferencesPicture:Fig 1:operating System 4th Edition by William StallingFig 2:Modern  operating Systems 2nd Edition by A Tanenbaum.Fig 3:operating System 4th Edition by William StallingText:Modern  operating Systems 2nd Edition by A Tanenbaum.operating System 4th Edition by William Stalling
G4 Group

Os Linux

  • 1.
    Linux Memory ManagementCaseStudy : Operating SystemMuhammad Ather Rasool IS/17115/Aut-07/MMuhammad Muzammil IS/17104/Aut-07/MMuhammad Zahid Majeed IS/17105/Aut-07/MFederal Urdu university of Arts, Science & Technology,.
  • 2.
    Introduction:Linux is aUNIX like system that has gained popularity in recent years.Development begins in 1991.Two different GUI (GNOME & KDE) for Linux.In early days, Linux development revolved around central OS kernel.Linux kernel: Is an entirely original piece of SW developed from scratch by the Linux community.
  • 3.
    Components of LinuxMemoryTwo ComponentsPhysical memory:kernel is loaded in memoryrest of memory is available for user pages Allocate and free physical memory pagesVirtual Memory: Each Linux process on a 32 bit get 3 GB for virtual addressingRemaining 1 GB reserve for its Page Table and kernel dataFrequently accessed pages will be on the "hot" listFree pages will be on the "cold" or "free" list
  • 4.
    PagingPage Size: Intel4 KB, Alpha 8 KBLinux kernel is the page allocatorEach process has its own page tableThe entire page table may take up too much main memoryPage tables are also stored in virtual memoryWhen a process is running, part of its page table is in main memory
  • 5.
    Fetch PolicyLinux usea demand paging With no preparing And no working set conceptThere is a system call in which user can give a hint that a certain page may be needed soonDemand paging
  • 6.
    Linux Memory ManagementThreelevel page table structurePage directoryPage middle directoryPage table6
  • 7.
  • 8.
    Placement PolicyAll pageframes are grouped into 10 lists of blocks that contain groups of 1, 2, 4, 8, 16, 32,64, 128, 256, and 512 contiguous page frames respectively If a small area is needed and only a larger area is available, the larger area is split into two Halves (buddies), possibly repeatedlyWhen a block is released, the kernel attempts to merge together pairs of free buddyBuddy Algorithm
  • 9.
    Buddy Algorithm problemLinuxmanages memory using the buddy algorithm. The algorithm leads to the internal fragmentation because if we want 65 page chunks w required 128 page chunksFor this problem to solve Linux has a second memory allocation which manages smaller units separately
  • 10.
  • 11.
    Replacement PolicyPaging system can divided into two sections First policy algorithm decides which pages to write out to disk, and when to write them.Second the paging mechanism carries out the transfer and pages data back into physical memory when they are needed again.Under Linux a clock is used, and every page has an age that is adjusted on each pass of the clockAge is measure of youthfulness of pages
  • 12.
    Clock Algorithm –Another Implementation of Second ChanceOrder pages in circular list“Hand” of the clock points to the page to be replaced currentlyWhen required to evict a pageIf page pointed to has R=0, then evict itIf R=1, then reset R and move hand forwardClock algorithm can be used with NRU (decision based on both R and M bits)
  • 13.
    Fig 3: ClockAlgorithm for replacement
  • 14.
    Replacement ScopeLocal replacementpolicy – chooses only among the resident pages of the process that generated page fault in selecting a page to replaceGlobal replacement policy – considers all unlocked pages in main memory as candidates for replacement, regardless of which process owns a particular pageGlobal policies are more attractive because of the simplicity of implementation and minimal overhead
  • 15.
    ReferencesPicture:Fig 1:operating System4th Edition by William StallingFig 2:Modern operating Systems 2nd Edition by A Tanenbaum.Fig 3:operating System 4th Edition by William StallingText:Modern operating Systems 2nd Edition by A Tanenbaum.operating System 4th Edition by William Stalling
  • 16.