Mari Sama-sama Present OS

download Mari Sama-sama Present OS

of 21

Transcript of Mari Sama-sama Present OS

  • 8/8/2019 Mari Sama-sama Present OS

    1/21

    8.4 LINUX MEMORYMANAGEMENT

    Present by:

    Mohamad Taufiq b. Mat Zakri CC08133

    Muhammad Izzat b. Ibrahim CC08110

    Muhammad Iman b. Abd. Razak CC08128

    Muhammad Isamudin b. Abd. Ghani CC08056

  • 8/8/2019 Mari Sama-sama Present OS

    2/21

    ` Since the early days of computing, there has been a

    need for more memory than exists physically in a

    system. Strategies have been developed to overcome

    this limitation and the most successful of these is virtual

    memory. Virtual memory makes the system appear to

    have more memory than it actually has by sharing it

    between competing processes as they need it.

    Memory Management

  • 8/8/2019 Mari Sama-sama Present OS

    3/21

    ` Large Address Spaces The operating system makes

    the system appear as if it has a larger amount of

    memory than it actually has. The virtual memory can be

    many times larger than the physical memory in the

    system,

    ` Protection Each process in the system has its own

    virtual address space. These virtual address spaces are

    completely separate from each other and so a processrunning one application cannot affect another. Also, the

    hardware virtual memory mechanisms allow areas of

    memory to be protected against writing. This protects

    code and data from being overwritten by roguea lications.

    Memory Management Provides:

  • 8/8/2019 Mari Sama-sama Present OS

    4/21

    ` Fair Physical Memory Allocation The memory

    management subsystem allows each running process in

    the system a fair share of the physical memory of the

    system,

    ` Shared Virtual MemoryAlthough virtual memory

    allows processes to have separate (virtual) address

    spaces, there are times when you need processes to

    share memory. Shared memory can also be used as anInter Process Communication (IPC) mechanism, with

    two or more processes exchanging information via

    memory common to all of them. Linux supports the Unix

    TMS

    ystem V shared memory IPC.

  • 8/8/2019 Mari Sama-sama Present OS

    5/21

    Kernel Memory AllocationProcess Virtual Memory

  • 8/8/2019 Mari Sama-sama Present OS

    6/21

    LINUX VIRTUAL MEMORY

    ` -Virtual Memory Addressing Page Directory An active process has a single page directory

    that is the size of one page. Each entry in the page directory

    points to one page of the page middle directory. The page

    directory must be in main memory for an active process. Page Middle Directory The page middle directorymay span

    multiple pages. Each entry in the page middle directory points

    to one page in the middle table.

    Page Table The page table may also span multiple page.

    Each page table entry refers to one virtual process.

  • 8/8/2019 Mari Sama-sama Present OS

    7/21

  • 8/8/2019 Mari Sama-sama Present OS

    8/21

  • 8/8/2019 Mari Sama-sama Present OS

    9/21

    ` Linux page table structure is platform independent and

    was designed to accommodate the 64-bit Alpha

    processor

    ` With 64-bit addresses, the use of only two levels of

    pages on the Alpha would result large page table and

    directories

    ` Extra level of indirection are optimized away at compile

    time, not at runtime

    ` Therefore, there is no performance overheadfor usinggeneric three levels design on platforms which supports

    only two levels in hardware

  • 8/8/2019 Mari Sama-sama Present OS

    10/21

    Linux Memory Management

    Page Allocation

  • 8/8/2019 Mari Sama-sama Present OS

    11/21

    Page Allocation Linux uses the Buddy algorithm to

    effectively allocate and deallocate blocks of pages.

    The page allocation code attempts to allocate ablock of one or more physical pages.

    Pages are allocated in blocks which are powers of2 in size.(ex: 1, 2, 4, 8, 12, )

  • 8/8/2019 Mari Sama-sama Present OS

    12/21

    Page Allocation (cont.) as there are enough free pages in the system to

    grant this request (nr_free_pages > min_free_pages)the allocation code will search the free_area for a

    block of pages of the size requested.

    Each element of the free_area has a map of theallocated and free blocks of pages for that sizedblock.

    Example : element 2 of the array has amemory map that describes free andallocated blocks each of 4 pages long.

  • 8/8/2019 Mari Sama-sama Present OS

    13/21

    Page Allocation (cont.) allocation algorithm first searches for blocks of

    pages of the size requested.

    follows the chain of free pages that is queued onthe list element of the free_area data structure.

    If no blocks of pages of the requested size arefree, blocks of the next size (which is twice that ofthe size requested) are looked for.

    This process continues until all of the free_areahas been searched or until a block of pages hasbeen found.

  • 8/8/2019 Mari Sama-sama Present OS

    14/21

    Page Allocation (cont.) Indicate the financial advantages for the customer

    If the block of pages found is larger than that

    requested it must be broken down until there is ablock of the right size.

    Because the blocks are each a power of 2 pagesbig then this breaking down process is easy as

    you simply break the blocks in half. The free blocks are queued on the appropriate

    queue and the allocated block of pages isreturned to the caller.

  • 8/8/2019 Mari Sama-sama Present OS

    15/21

    Page Allocation (cont.)

  • 8/8/2019 Mari Sama-sama Present OS

    16/21

    Page replacement algorithms

    Linux page replacement algorithm is based on the clock algorithm

    Clock is a more efficient version of FIFO than Second-chance because pages don't

    have to be constantly pushed to the back of the list

    but it performs the same general function as Second-Chance

    The clock algorithm keeps a circular list of pages in memory, with the "hand"

    (iterator) pointing to the oldest page in the list. When a page fault occurs and no empty frames exist, then the R (referenced) bit is

    inspected at the hand's location.

    If R is 0, the new page is put in place of the page the "hand" points to, otherwise the

    R bit is cleared.

    Then, the clock hand is incremented and the process is repeated until a page is

    replaced.

  • 8/8/2019 Mari Sama-sama Present OS

    17/21

  • 8/8/2019 Mari Sama-sama Present OS

    18/21

    Buddy allocator

    Allocate and deallocate in units of one or more pages.

    Allocate memory using power of two allocator

    If a block of the correct size is not currently available, thenone is formed by splitting the next larger block in two,

    forming two matched buddies. ( And if that larger size is

    not available, then the next largest available size is split,

    and so on. )

  • 8/8/2019 Mari Sama-sama Present OS

    19/21

  • 8/8/2019 Mari Sama-sama Present OS

    20/21

    Slab allocator

    Allocate smaller block of memory

    Consisting of one or more contiguous pages

    The kernel then creates separate caches for each type ofdata structure it might need from one or more slabs.

    Initially the caches are marked empty, and are marked full

    as they are used

  • 8/8/2019 Mari Sama-sama Present OS

    21/21