14
Linux Memory Management Operating System Muhammad Muzammil IS/17104/Aut-07/M Muhammad Zahid Majeed IS/17105/Aut-07/M Muhammad Ather Rasool IS/17115/Aut-07/M

Os Linux Documentation

Embed Size (px)

DESCRIPTION

OS Linux case Studey

Citation preview

Page 1: Os Linux Documentation

Linux Memory ManagementOperating System

Muhammad Muzammil IS/17104/Aut-07/M

Muhammad Ather Rasool IS/17115/Aut-07/M

Federal Urdu University of Arts, Science & Technology, Islamabad.

Page 2: Os Linux Documentation

Chapter n# 1: Intro

Introduction to Linux:

Linux is a UNIX like system that has gained popularity in recent years. Development begins in 1991. Ideas taken from MINIX. 9300 LOC of C & 950 LOC of Assembly Linux 2.0 issued in 1996 support 64 bit Architecture. 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.Linux system:Some written from scratch, other borrowed from other development projects and other created in collection with other team.Linux Distribution:Includes all standard components of Linux system, plus administrator tool (e.g. manage install and deinstall, creation of user accounts) Red Hat and ubuntu are most famous versions of Linux widely used Now in world.

UNIX

UNIX was developed at Bell Labs in the early 1970s. The first version was written by ken Thompson in assembler for the PDP-7

minicomputer This was soon followed by a version for the PDP-11 written in a new language call C that

was devised and implemented by Dennis Ritchie In 1974, Ritchie and Thompson published a landmark paper about UNIX (Ritchie and

Thompson, 1974), which stimulated many universities to ask Bell Labs for a copy of UNIX

MINIX

OS are complicated Unix are open source OS Use for educational purpose 11800 LOC of C & 800 LOC of Assembly

Page 3: Os Linux Documentation

Chapter # 2 Memory Management in Linux:

Makes use of three level page table structure, consisting of the following tables

• 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 has to be in the main memory for an active process

• Page middle directory

• May span multiple pages.

• Each entry in the page middle directory points to one page in the page table

• Page table

• May span multiple pages. Each page table entry refers to one virtual page of the process

• Each virtual address in Linux is made of four fields.

• The left-most field is used as an index into the page directory.

• The next field is used as an index into the page middle directory

• The third field servers as an index into the page table

• The forth field gives the offset within selected page of memory

• Linux page table structure is platform independent and was designed to accommodate the 64 bit Alpha processor (which has hardware support for three level paging)

• The Pentium/X86 architecture has two level paging hardware supports; Linux is accommodating the addressing schema by defining the size of the middle page directory as 1.

Linux has two components

1 Physical memory:

Allocate and free physical memory pages, group of pages, and small blocks of memory

Page 4: Os Linux Documentation

Physical memory is used for various purposes. kernel is loaded in memory and rest of memory is available for user pages , the buffer cache is holds all file system include files which are recently or in near future will be used, the paging cache include user pages which have record of pages which that are no longer needed and waited to replace

Linux support dynamic loaded modules, generally device drivers. Each must be allocated a contagious piece of kernel memory. For this entire placement buddy algorithm is used.

2 Virtual Memory:

William stalling lab 3-26 d: drive muz folder access write all these files.

Memory mapped into the address space of running processor.

Each Linux process on a 32 bit get 3 GB for virtual addressing Remaining 1 GB reserve for its Page Table and kernel data 1 GB is not visible when running in user mode. Linux also uses different linked lists of pages to facilitate an LRU-style algorithm. Linux divides physical memory into three "zones:" one for DMA (devices I/0) pages, one for

normal pages, and one for dynamically allocated memory. Pages move between "hot," "cold," and "free" lists. Frequently accessed pages will be on the "hot" list. Free pages will be on the "cold" or "free"

list In theory, paging eliminates the need for contiguous memory allocation, but DMA operation

accesses the address bus directly while transferring data and may only write into certain addresses. That’s why you need a buddy

Paging

Page fault:

During memory referencing, hole come the page fault occur.

Page Size:

Page size is fixed for example for Intel 4 KB, for Alpha 8 KB.

Page 5: Os Linux Documentation

Linux kernel is the page allocator. The allocator uses a buddy algorithm to keep track of available physical pages.

• Each process has its own page table

Page 6: Os Linux Documentation

• Each page table entry contains the frame number of the corresponding page in main memory

• A bit is needed to indicate whether the page is in main memory or not

Modify Bit inPage Table

• Modify bit is needed to indicate if the page has been altered since it was last loaded into main memory

If no change has been made, the page does not have to be written to the disk when it needs to be swapped out

• Page Tables

• The entire page table may take up too much main memory

• Page tables are also stored in virtual memory

• When a process is running, part of its page table is in main memory

Page 7: Os Linux Documentation

Buddy Algorithm

All 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 twoHalves (buddies), possibly repeatedly

When a block is released, the kernel attempts to merge together pairs of free buddy*****************Under processing*********************

Buddy Algorithm Problem:

Linux manages memory using the buddy algorithm. The algorithm leads to the internal fragmentation because if we want 65 page chunks w required 128 page chunks.

Page 8: Os Linux Documentation

For this problem to solve Linux has a se

cond memory allocation which manages smaller units separately.

Demand Paging:

Page 9: Os Linux Documentation

Linux is a demand paging with no preparing and no working set concept.

There is a system call in which user can give a hint that a certain page may be needed soon

Paging Policy:

Paging 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. Linux policy uses modified version of the standard clock (or second chance) algorithm. Under Linux a clock is used, and every page has an age that is adjusted on each pass of

the clock. Age is measure of youthfulness of pages. LRU policy used. Linux paging mechanism use swapping and partitions. Swapping is slower due to the extra overhead. Blocks are allocated from the swap devices according to a bitmap of used blocks, which is

maintained in physical memory at all times

Basic Replacement Algorithms

1 Clock Policy:

Attempt to get performance of LRU with low overhead of FIFO

Include a use bit with each page

Think of pages as circular buffer

• Keep a pointer to the buffer

Set the use bit when loaded or used

When we need to remove a page:

• Use pointer to scan all available pages

• Scan for page with use=0

• Set bit to 0 as we go by

Page 10: Os Linux Documentation

Performance close to LRU

Page 11: Os Linux Documentation

• Just prior to replacement of a page from the buffer with incoming page 727, the next frame pointer points at frame 2 (which contains page 45); the clock policy is now executed

• Because the use bit on page 45 in frame 2, this is not replaced, and the pointer advanced to frame 3, where again the use bit is 1. The use bit is set to 0 and frame pointer advanced to next frame, where the use bit is 0. Page 556 located in frame 4 gets replaced with page 727, use bit is set to 1 and next frame pointer advances to frame 5

Replacement Scope

• Scope of replacement policy can be:

• Local replacement policy – chooses only among the resident pages of the process that generated page fault in selecting a page to replace

• Global replacement policy – considers all unlocked pages in main memory as candidates for replacement, regardless of which process owns a particular page

• Global policies are more attractive because of the simplicity of implementation and minimal overhead