os202

Mohammad Saddam Mashuri's OS202


Project maintained by saddamonpc Hosted on GitHub Pages — Theme by mattgraham

HOME

Top 10 List of Week 05

Why hello there! I’m thankful you have the time to read my top 10 of week 5 of this course. This week topic is Virtual Memory. Please do realize that this top 10 are my opinion and may not be the same with yours.

The way I grade this top 10 list are by 3 categories:

* how important it is,

* how simple it is,

* and how relevant the topic is to the operating system course.

Whew, it’s the calm before the storm. Right now, it’s around a week before the mid terms and THANKFULLY we only have to prepare for 4 subjects! (Thanks to the OS course not having a mid terms, but the usual assignments). Anyway, this week is going to be something less harder, but it’s still hard nonetheless! I’ll try my best to summarize some of the subtopics here.

Please enjoy your stay here, and good luck to my other mates doing this course!

  1. Virtual Memory: Definition
    Back to the fundamentals. Virtual Memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory. This is a technique that is used in both hardware and software. Essentially, It maps memory addresses used by a program, called virtual addresses, into physical addresses in computer memory.

  2. Virtual Address Space (VAS)
    This is similar to point no. 1 on week 4 of the top 10 list. To reiterate, the address space allows the OS to create an easy to use abstraction of physical memory. While virtual address space (VAS) is the set of ranges of virtual addresses that an operating system makes available to a process. Which means that, each time a process is run on an OS, the OS creates a new process and a new VAS for this process. This gives various benefits, one of which is process isolation, which protects each process from other processes on the OS.

  3. Demand Paging
    Demand paging loads a page in memory on-demand or when a page fault occurs. Demand paging is a method of virtual memory management. To achieve this process, a page table implementation is used. The page table maps logical memory to physical memory. One of the advantages of demand paging is that memory would be used more efficiently, and we can have a large virtual memory.

  4. Page Fault
    A page fault happens when a program tries to access a block of memory that is not stored in the physical memory, or RAM. Most page faults are handled without problems. However, an invalid page fault may cause a program to freeze or crash. Preventive measures, like page fault handling, should be implemented into a program, as page faults are quite common in the OS.

  5. Page Replacement Algorithms
    In an OS that uses paging for memory management, a page replacement algorithm is needed to decide which page needs to be replaced when new page comes in. Here are some algorithms listed below:
    • Basic Page Replacement
      If no frame is free, we find one that is not currently being used and free it. Free the frame by writing its contents to swap space and changing the page table to indicate that the page is no longer in memory.
    • First In First Out (FIFO)
      This is the simplest page replacement algorithm. In this algorithm, the OS keeps track of all pages in the memory in a queue, when a page must be replaced, the oldest page is chosen.
    • Optimal Page Replacement
      This algorithm replaces the page that will not be used for the longest period of time.
    • Least Recently Used (LRU)
      LRU replacement associates with each page the time of that page’s last use. LRU chooses the page that has not been used for the longest period of time, when a page needs to be replaced.

      There are other page replacement algorithms, such as LRU-Approximation Page Replacement, Counting-Based Page Replacement, and etc. They could not be summarized here, as they are quite complex, and are best learned straight from the book (first source).
  6. Allocation of Frames
    Virtual memory is implemented using demand paging. Demand paging supports the development of frame allocation algorithm. Frame allocation algorithms are used if you have multiple processes and it helps decide how many frames to allocate to each process. There are two common algorithms to allocate frames to a process:
    • Equal allocation
      Each process gets equal number of frames.
    • Proportional allocation
      Frames are allocated to each process according to the process size.
  7. Memory API
    Memory allocation interfaces that are provide in UNIX systems, are quite simple. There are two types of memory that are allocated. The first is called stack memory, and allocations and deallocations of it are managed implicitly by the programmer. The second one is called, heap memory. This is used for long-lived memory, where all allocations and deallocations are explicitly handled by the programmer.

  8. Thrashing
    When a page fault and swapping occur frequently at a high rate, then the OS need to spend more time to swap the pages. This state is called thrashing. When thrashing occur, the CPU performance is reduced. The current best practice to handle thrashing, is to include enough physical memory, whenever possible, to avoid thrashing.

  9. Allocating Kernel Memory
    When a process running in user mode requests additional memory, pages are allocated from the list of free page frames maintained by the kernel. Therefore, strategies are needed for managing free memory that is assigned to kernel processes:
    • Buddy System
      An algorithm in which a larger memory block is divided into small parts (a segment using a power-of-2 allocator) to satisfy the request of the user.
    • Slab Allocation
      This algorithm eliminates the fragmentation caused by allocations and deallocations. In slab allocation, memory chunks suitable to fit data objects of certain type or size are pre-allocated. The cache stores these one or more slabs.
  10. Copy on Write (COW)
    Copy on write is a resource management technique. The idea is that if multiple callers ask for resources, then give them pointers to the same resource. This function can be maintained until a caller tries to modify its “copy” of the resource. All of this happens transparently to the callers. One common use of the COW concept is in the maintenance of instant snapshot on database servers.

That’s it for this week’s top 10 list. How is it? Do you agree with it? Or maybe something is missing or doesn’t seem right? Well, maybe take a second to give me a feedback and contact me through github. Thank you for reading!

Sources:
Abraham Silberschatz - Operating System Concepts -Wiley (2018)
http://pages.cs.wisc.edu/~remzi/OSTEP/
http://dictionary.sensagent.com/Virtual%20address%20space/en-en/
https://www.tutorialandexample.com/what-is-demand-paging/
https://techterms.com/definition/page_fault
https://en.wikipedia.org/wiki/Page_replacement_algorithm