Operating Systm Term Papere

Embed Size (px)

Citation preview

  • 8/4/2019 Operating Systm Term Papere

    1/30

    1

    TERM PAPER CSE316

    MEMORY MANAGEMENTIN LINUX & UNIX

    Submitted to: Submitted by:

    MR.MANISH KUMAR SURENDR

    MCA 2nd SEM

    *roll no D3804B51

    *Regd. no 10806601

  • 8/4/2019 Operating Systm Term Papere

    2/30

    1

    ACKNOWLEDGMENT

    I have the honor to express our gratitude to our Prof. Mr. Manish Kumar

    for their timely help, support encouragement, valuable comments, suggestions

    and many innovative ideas in carrying out this project. It is great for me to gain

    out of their experience.

    I also owe overwhelming debt to my classmates for their constant

    encouragement and support throughout the execution of this project.

    Above all, consider it a blessing of theAlmighty Godthat i have been able tocomplete this project. His contribution towards every aspect of ours throughoutour life would always be the supreme and unmatched.

    SURENDRA SINGH

  • 8/4/2019 Operating Systm Term Papere

    3/30

    1

    TABLE OF CONTENTSUNIX :INTRODUCTION.

  • 8/4/2019 Operating Systm Term Papere

    4/30

    1

    UNIX: INTRODUCTION

    Unix is popular operating system, developed by AT&T in 1969 and it has been very important to

    the development of the Internet. It is a multi-processing, multi-user, family of operating systems

    that run on a variety of architechtures. UNIX allows more than one user to access a computersystem at the same time.

    A widely used Open Source Unix-like operating system kernel. Linux was first released by its

    inventor Linus Torvalds in 1991. Combining the Linux kernel with the GNU software forms thebasis of the operating system family generally known as 'Linux'. There are distributions ofGNU/Linux for almost every available type of computer hardware from desktop machines to

    IBM mainframes. The inner workings of GNU/Linux are open and available for anyone to

    examine and change as long as they make their changes available to the public, as set out in theterms of the GNU General Public License. Because of its robustness and availability, Linux has

    won popularity in the Open Source community as well as among commercial application

    developers.

    Here is more input:

    Unix requires a more powerful hardware configuration. It will work in large mainframecomputers but will not work in an x86 based personal computer. Linux however, (which

    is built on the concept of Unix) has small hardware requirements and it will work on both

    a large mainframe computer and an x86 based personal computer.

    Unix is an Operating System developed in olden days in which the kernel, the heart of the

    OS, interacts directly with the hardware. (note: this is the definition of what a kernel is).

    Because UNIX treats everything as a file, it provides greater security for users. An

  • 8/4/2019 Operating Systm Term Papere

    5/30

    1

    example of a UNIX distribution is posix. (note: actually POSIX is a set of standards for

    interoperability of applications between UNIX and UNIX-like systems). Linux uses a the

    UNIX architecture as its basis and provides more facilities and applications. Linux couldbe considered to be a GUI to the UNIX core. (note: this is plain wrong. GNU/ Linux was

    rewritten from scratch using UNIX as a guide. GNOME and KDE are GUIs for

    GNU/Linux). Examples of Linux distributions are Redhat, Fedora, Susee, Mandriva, andUbuntu. Solaris OS also uses the UNIX kernal almost all UNIX commands will work on

    solaris in addition to 500 Solaris specific commands. (note: Solaris is also a rewrite of

    UNIX for x86, and does not use any original UNIX code). Both UNIX and LINUX areOpen source. (note: UNIX is proprietary, Linux is open source)

    Unix is the foundation for a number of operating systems, with Linux being the most

    popular one. Novell and Free BSD are 2 other commonly used Unix varients.(note:

    Again, the BSD family are based on another rewrite of UNIX for x86, UNIX is not theirfoundation in the sense implied here)

    UNIX is an operating system created in the early days of computers. More recently,Linux was created as an open-source, freeware operating system. (note: Linux is free

    software, not freeware. Free software is open source that insists any developer reusingcode releases their own work as free software. Freeware is proprietary software

    distributed at no cost [gratis]) It is "UNIX-LIKE", meaning that it uses many UNIX

    constructs but also departs from traditional UNIX in many ways. Like UNIX, Linux isfaster than many of the other commercially available operating systems. (note: This is a

    sweeping generalization and depends on the hardware used, and what servers and

    applications are running) It appears to also be far more robust than any of the Microsoft

    products. Linux is being used in many time critical applications because of it's speed. It isalso used in many applications that need to maintain uptime because Linux, like UNIX,

    can run for months at a time without rebooting. While the typical method of solvingMicrosoft problems is to "reboot", that particular requirement does not seem to beappropriate in a Linux/Unix environment. While UNIX has created a windows-like work

    environment, Linux has improved greatly on that concept. Linux has become a real

    player in the consumer operating system market... and it's free. While you may want topay for a Linux distribution, the actual code is free and you are allowed to load it on as

    many machines as you want. You can get Linux for free if you wish to load it across the

    internet.

    HISTORY

    Since it began to escape from AT&T's Bell Laboratories in the early 1970's, the success of the UNIXoperating system has led to many different versions: recipients of the (at that time free) UNIX systemcode all began developing their own different versions in their own, different, ways for use andsale. Universities, research institutes, government bodies and computer companies all began using thepowerful UNIX system to develop many of the technologies which today are part of a UNIX system.

  • 8/4/2019 Operating Systm Term Papere

    6/30

    1

    Computer aided design, manufacturing control systems, laboratory simulations, even the Internetitself, all began life with and because of UNIX systems. Today, without UNIX systems, the Internetwould come to a screeching halt. Most telephone calls could not be made, electronic commerce wouldgrind to a halt and there would have never been "Jurassic Park"!

    By the late 1970's, a ripple effect had come into play. By now the under- and post-graduate studentswhose lab work had pioneered these new applications of technology were attaining management anddecision-making positions inside the computer system suppliers and among its customers. And theywanted to continue using UNIX systems.

    Soon all the large vendors, and many smaller ones, were marketing their own, diverging, versions ofthe UNIX system optimized for their own computer architectures and boasting many differentstrengths and features. Customers found that, although UNIX systems were available everywhere,they seldom were able to interwork or co-exist without significant investment of time and effort tomake them work effectively. The trade mark UNIX was ubiquitous, but it was applied to a multitude ofdifferent, incompatible products.

    In the early 1980's, the market for UNIX systems had grown enough to be noticed by industryanalysts and researchers. Now the question was no longer "What is a UNIX system?" but "Is a UNIXsystem suitable for business and commerce?"

    Throughout the early and mid-1980's, the debate about the strengths and weaknesses of UNIXsystems raged, often fuelled by the utterances of the vendors themselves who sought to protect theirprofitable proprietary system sales by talking UNIX systems down. And, in an effort to furtherdifferentiate their competing UNIX system products, they kept developing and adding features of theirown.

    In 1984, another factor brought added attention to UNIX systems. A group of vendors concernedabout the continuing encroachment into their markets and control of system interfaces by the largercompanies, developed the concept of "open systems."

    Open systems were those that would meet agreed specifications or standards. This resulted in theformation of X/Open Company Ltd whose remit was, and today in the guise of The Open Group

    remains, to define a comprehensive open systems environment. Open systems, they declared, wouldsave on costs, attract a wider portfolio of applications and competition on equal terms. X/Open chosethe UNIX system as the platform for the basis of open systems.

    Although UNIX was still owned by AT&T, the company did little commercially with it until the mid-1980's. Then the spotlight of X/Open showed clearly that a single, standard version of the UNIXsystem would be in the wider interests of the industry and its customers. The question now was,"which version?".

    In a move intended to unify the market in 1987, AT&T announced a pact with Sun Microsystems, theleading proponent of the Berkeley derived strain of UNIX. However, the rest of the industry viewed thedevelopment with considerable concern. Believing that their own markets were under threat theyclubbed together to develop their own "new" open systems operating system. Their new organizationwas called the Open Software Foundation (OSF). In response to this, the AT&T/Sun faction formedUNIX International.

    The ensuing "UNIX wars" divided the system vendors between these two camps clustered around thetwo dominant UNIX system technologies: AT&T's System V and the OSF system called OSF/1. In themeantime, X/Open Company held the center ground. It continued the process of standardizing theAPIs necessary for an open operating system specification.

    In addition, it looked at areas of the system beyond the operating system level where a standardapproach would add value for supplier and customer alike, developing or adopting specifications for

  • 8/4/2019 Operating Systm Term Papere

    7/30

    1

    languages, database connectivity, networking and mainframe interworking. The results of this workwere published in successive X/Open Portability Guides.

    XPG 4 was released in October 1992. During this time, X/Open had put in place a brand programbased on vendor guarantees and supported by testing. Since the publication of XPG4, X/Open hascontinued to broaden the scope of open systems specifications in line with market requirements. Asthe benefits of the X/Open brand became known and understood, many large organizations beganusing X/Open as the basis for system design and procurement. By 1993, over $7 billion had beenspent on X/Open branded systems. By the start of 1997 that figure has risen to over $23 billion. Todate, procurements referencing the Single UNIX Specification amount to over $5.2 billion.

    In early 1993, AT&T sold it UNIX System Laboratories to Novell which was looking for a heavyweightoperating system to link to its NetWare product range. At the same time, the company recognized thatvesting control of the definition (specification) and trademark with a vendor-neutral organizationwould further facilitate the value of UNIX as a foundation of open systems. So the constituent parts ofthe UNIX System, previously owned by a single entity are now quite separate

    In 1995 SCO bought the UNIX Systems business from Novell, and UNIX system source code andtechnology continues to be developed by SCO.

    In 1995 X/Open introduced the UNIX 95 brand for computer systems guaranteed to meet the SingleUNIX Specification. The Single UNIX Specification brand program has now achieved critical mass:vendors whose products have met the demanding criteria now account for the majority of UNIXsystems by value.

    For over ten years, since the inception of X/Open, UNIX had been closely linked with open systems.X/Open, now part of The Open Group, continues to develop and evolve the Single UNIX Specificationand associated brand program on behalf of the IT community. The freeing of the specification of theinterfaces from the technology is allowing many systems to support the UNIX philosophy of small,often simple tools , that can be combined in many ways to perform often complex tasks. The stabilityof the core interfaces preserves existing investment, and is allowing development of a rich set ofsoftware tools. The Open Source movement is building on this stable foundation and is creating aresurgence of enthusiasm for the UNIX philosophy. In many ways Open Source can be seen as the

    true delivery of Open Systems that will ensure it continues to go from strength to strength.

    1969 The Beginning The history of UNIX starts back in 1969, when Ken Thompson, DennisRitchie and others started working on the "little-used PDP-7 in a corner" atBell Labs and what was to become UNIX.

    1971 First Edition It had a assembler for a PDP-11/20, file system, fork(), roff and ed. It wasused for text processing of patent documents.

    1973 Fourth Edition It was rewritten in C. This made it portable and changed the history ofOS's.

    1975 Sixth Edition UNIX leaves home. Also widely known as Version 6, this is the first to bewidely available out side of Bell Labs. The first BSD version (1.x) wasderived from V6.

    1979 Seventh Edition It was a "improvement over all preceding and following Unices" [Bourne].

    It had C, UUCP and the Bourne shell. It was ported to the VAX and thekernel was more than 40 Kilobytes (K).

    1980 Xenix Microsoft introduces Xenix. 32V and 4BSD introduced.

    1982 System III AT&T's UNIX System Group (USG) release System III, the first publicrelease outside Bell Laboratories. SunOS 1.0 ships. HP-UX introduced.Ultrix-11 Introduced.

    1983 System V Computer Research Group (CRG), UNIX System Group (USG) and a third

    group merge to become UNIX System Development Lab. AT&T announcesUNIX System V, the first supported release. Installed base 45,000.

    1984 4.2BSD University of California at Berkeley releases 4.2BSD, includes TCP/IP, new

    http://www.opensource.org/http://www.opensource.org/
  • 8/4/2019 Operating Systm Term Papere

    8/30

    1

    signals and much more. X/Open formed.

    1984 SVR2 System V Release 2 introduced. At this time there are 100,000 UNIXinstallations around the world.

    1986 4.3BSD 4.3BSD released, including internet name server. SVID introduced. NFSshipped. AIX announced. Installed base 250,000.

    1987 SVR3 System V Release 3 including STREAMS, TLI, RFS. At this time there are

    750,000 UNIX installations around the world. IRIX introduced.1988 POSIX.1 published. Open Software Foundation (OSF) and UNIX

    International (UI) formed. Ultrix 4.2 ships.

    1989 AT&T UNIX Software Operation formed in preparation for spinoff of USL.Motif 1.0 ships.

    1989 SVR4 UNIX System V Release 4 ships, unifying System V, BSD and Xenix.Installed base 1.2 million.

    1990 XPG3 X/Open launches XPG3 Brand. OSF/1 debuts. Plan 9 from Bell Labs ships.

    1991 UNIX System Laboratories (USL) becomes a company - majority-ownedby AT&T. Linus Torvalds commences Linux development. Solaris 1.0debuts.

    1992 SVR4.2 USL releases UNIX System V Release 4.2 (Destiny). October - XPG4 Brandlaunched by X/Open. December 22nd Novell announces intent to acquireUSL. Solaris 2.0 ships.

    1993 4.4BSD 4.4BSD the final release from Berkeley. June 16 Novell acquires USL

    Late1993

    SVR4.2MP Novell transfers rights to the "UNIX" trademark and the Single UNIXSpecification to X/Open. COSE initiative delivers "Spec 1170" to X/Openfor fasttrack. In December Novell ships SVR4.2MP , the final USL OEMrelease of System V

    1994 Single UNIXSpecification

    BSD 4.4-Lite eliminated all code claimed to infringe on USL/Novell. As thenew owner of the UNIX trademark, X/Open introduces the Single UNIXSpecification (formerly Spec 1170), separating the UNIX trademark fromany actual code stream.

    1995 UNIX 95 X/Open introduces the UNIX 95 branding programme for implementationsof the Single UNIX Specification. Novell sells UnixWare business line toSCO. Digital UNIX introduced. UnixWare 2.0 ships. OpenServer 5.0debuts.

    1996 The Open Group forms as a merger of OSF and X/Open.

    1997 Single UNIXSpecification,Version 2

    The Open Group introduces Version 2 of the Single UNIX Specification,including support for realtime, threads and 64-bit and larger processors.The specification is made freely available on the web. IRIX 6.4, AIX 4.3and HP-UX 11 ship.

    1998 UNIX 98 The Open Group introduces the UNIX 98 family of brands, including Base,

    Workstation and Server. First UNIX 98 registered products shipped bySun, IBM and NCR. The Open Source movement starts to take off withannouncements from Netscape and IBM. UnixWare 7 and IRIX 6.5 ship.

    1999 UNIX at 30 The UNIX system reaches its 30th anniversary. Linux 2.2 kernel released.The Open Group and the IEEE commence joint development of a revisionto POSIX and the Single UNIX Specification. First LinuxWorld conferences.Dot com fever on the stock markets. Tru64 UNIX ships.

    2001 Single UNIXSpecification,Version 3

    Version 3 of the Single UNIX Specification unites IEEE POSIX, The OpenGroup and the industry efforts. Linux 2.4 kernel released. IT stocks face ahard time at the markets. The value of procurements for the UNIX brandexceeds $25 billion. AIX 5L ships.

    2003 ISO/IEC9945:2003

    The core volumes of Version 3 of the Single UNIX Specification areapproved as an international standard. The "Westwood" test suite ship forthe UNIX 03 brand. Solaris 9.0 E ships. Linux 2.6 kernel released.

  • 8/4/2019 Operating Systm Term Papere

    9/30

    1

    UNIX: Memory Management

    Memory Management is the key behind the idea of sharing. In

    order to increase performance and have several processes in memory at a

    time, you have to find a way to share the memory.

    This Memory consists of large array of words or bytes, each

    having its own address.

    UNIX uses two methods for Memory Management:

    Swapping

  • 8/4/2019 Operating Systm Term Papere

    10/30

    1

    Paging

    What is swapping?

    What is paging?

  • 8/4/2019 Operating Systm Term Papere

    11/30

    1

    Method 1: Swapping Memory

    Processes need to be in memory to be executed.

    These processes can be put temporarily out of memory

    then brought back into memory for continued execution.

    (Swap)

    Allocation of Main Memory and Swap Memory is done

    first. If the size of a process increases it does not fragment it

    relocates itself as a whole image into another part of

    memory.

  • 8/4/2019 Operating Systm Term Papere

    12/30

    1

    If there is no piece of memory large enough then the

    process is swapped out till it can be swapped back in with a

    new size.

    Scheduler Process decides what processes are swapped

    in and out.

    This swapper will wake up once every 4 seconds to

    check the processes going in and out.

    If the process is idle, been in main memory too long, or

    is too large - it will most likely be swapped out.

    If a process is small or been swapped out for a long time

    it will most likely be swapped in.

    If processes do not need to be swapped at all the

    process table will search for worthwhile processes to take

    its place.

    Many UNIX systems use this kind of swapping method.

    However, Berkeley designed systems depend on Paging for

    memory management.

  • 8/4/2019 Operating Systm Term Papere

    13/30

    1

    Method 2: Paging

    Paging allows for non contiguous address spacing.

    Phys Memory is broken into fixed blocks: Frames

    Log Memory is broken into fixed blocks: Pages

    When a process executes, the pages are loaded into any

    available memory frames from the backing store.

    This backing store then is divided into the fixed blocks so that

    they are the same size as the memory frames.

    A Page table exists between Logical and Physical memory

    which contains base addresses for each page in the physical

    memory.

  • 8/4/2019 Operating Systm Term Papere

    14/30

    1

    Berkeley Paging Methods:

    Berkeley introduced something called demand-paged-virtual-

    memory system, which eliminated external fragmentation.

    Swapping was kept minimal because more than one job could

    be kept in main memory.

    Paging allows execution with only parts of a process in

    memory.

    Demand Paging:

    1. 1. When a process needs a page and the page is not present - a

    page fault to the kernel occurs.

    2. 2. A frame of memory is then allocated.

    3. 3. The proper disk page is read into a frame.

    Interaction and Thrashing:

    CPU scheduling, memory swapping, and paging all interact

    together. If the priority is lower in a process, it is more likely that its

    paged will be paged/swapped entirely out.

    Having priority preferences like this guards against overworking

    the CPU. (Thrashing).

  • 8/4/2019 Operating Systm Term Papere

    15/30

    1

    LINUX: INTRODUCTIONThe creation of Linux

    Linus Torvalds in 2002

    In 1991, in Helsinki, Linus Torvalds began a project that later became the Linux kernel. It was

    initially a terminal emulator, which Torvalds used to access the large UNIX servers of the

    university. He wrote the program specifically for the hardware he was using and independent ofan operating system because he wanted to use the functions of his new PC with an 80386

    processor. Development was done onMinix using theGNU C compiler, which is still the main

    choice for compiling Linux today (although the code can be built with other compilers, such asthe Intel C Compiler).[citation needed]

    As Torvalds wrote in his bookJust for Fun[6] , he eventually realized that he had written an

    operating system kernel. On 25 August 1991, he announced this system in aUsenet posting to

    the newsgroup"comp.os.minix.":[7]

    Hello everybody out there using minix -

    I'm doing a (free) operating system (just a hobby, won't be big and professional likegnu) for 386(486) AT clones. This has been brewing since april, and is starting to get

    ready. I'd like any feedback on things people like/dislike in minix, as my OS

    resembles it somewhat (same physical layout of the file-system (due to practicalreasons) among other things).

    http://en.wikipedia.org/wiki/1991http://en.wikipedia.org/wiki/Helsinkihttp://en.wikipedia.org/wiki/Linus_Torvaldshttp://en.wikipedia.org/wiki/Linux_kernelhttp://en.wikipedia.org/wiki/Minixhttp://en.wikipedia.org/wiki/Minixhttp://en.wikipedia.org/wiki/GNU_Compiler_Collectionhttp://en.wikipedia.org/wiki/GNU_Compiler_Collectionhttp://en.wikipedia.org/wiki/GNU_Compiler_Collectionhttp://en.wikipedia.org/wiki/Intel_C_Compilerhttp://en.wikipedia.org/wiki/Wikipedia:Citation_neededhttp://en.wikipedia.org/wiki/Wikipedia:Citation_neededhttp://en.wikipedia.org/wiki/Just_for_Funhttp://en.wikipedia.org/wiki/Just_for_Funhttp://en.wikipedia.org/wiki/History_of_Linux#cite_note-fun-5http://en.wikipedia.org/wiki/Just_for_Funhttp://en.wikipedia.org/wiki/Usenethttp://en.wikipedia.org/wiki/Usenethttp://en.wikipedia.org/wiki/Newsgrouphttp://en.wikipedia.org/wiki/Newsgrouphttp://en.wikipedia.org/wiki/History_of_Linux#cite_note-groups.google.co.uk-6http://en.wikipedia.org/wiki/File:Linus_Torvalds.jpeghttp://en.wikipedia.org/wiki/File:Linus_Torvalds.jpeghttp://en.wikipedia.org/wiki/1991http://en.wikipedia.org/wiki/Helsinkihttp://en.wikipedia.org/wiki/Linus_Torvaldshttp://en.wikipedia.org/wiki/Linux_kernelhttp://en.wikipedia.org/wiki/Minixhttp://en.wikipedia.org/wiki/GNU_Compiler_Collectionhttp://en.wikipedia.org/wiki/Intel_C_Compilerhttp://en.wikipedia.org/wiki/Wikipedia:Citation_neededhttp://en.wikipedia.org/wiki/Just_for_Funhttp://en.wikipedia.org/wiki/History_of_Linux#cite_note-fun-5http://en.wikipedia.org/wiki/Usenethttp://en.wikipedia.org/wiki/Newsgrouphttp://en.wikipedia.org/wiki/History_of_Linux#cite_note-groups.google.co.uk-6
  • 8/4/2019 Operating Systm Term Papere

    16/30

    1

    I've currently portedbash(1.08) and gcc(1.40), and things seem to work. This impliesthat I'll get something practical within a few months, and I'd like to know what

    features most people would want. Any suggestions are welcome, but I won't promise

    I'll implement them :-)

    Linus ([email protected])

    PS. Yes it's free of any minix code, and it has a multi-threaded fs. It is NOT

    portable (uses 386 task switching etc), and it probably never will support anything

    other than AT-harddisks, as that's all I have :-(.

    Controversy over Linux

    Linux has been surrounded by controversy repeatedly since its inception.

    "Linux is obsolete"

    In 1992 Andrew S. Tanenbaum, recognized computer scientist and author of the Minix

    microkernel system, wrote a Usenet article on the newsgroup comp.os.minix with the title

    "Linux is obsolete,"[16] which marked the beginning of a famous debate about the structure of thethen-recent Linux kernel. Among the most significant criticisms were that:

    The kernel was monolithic and thus old-fashioned.

    The lack ofportability, due to the use of exclusive features of the Intel 386 processor. "Writing anew operating system that is closely tied to any particular piece of hardware, especially a weird

    one like the Intel line, is basically wrong."[

    There wasn't strict control of the source code by any individual person.

    Linux employed a set of features which were useless (Tanenbaum believed that multithreadedfile

    systems were simply a "performance hack").

    Tanenbaum's prediction that Linux would become outdated within a few years and replaced by

    GNU Hurd (which he considered to be more modern) proved incorrect. Linux has been ported toall major platforms and its open development model has led to an exemplary pace of

    development. In contrast, GNU Hurd has not yet reached the level of stability that would allow it

    to be used on a production server.

    http://en.wikipedia.org/wiki/Bashhttp://en.wikipedia.org/wiki/GNU_Compiler_Collectionhttp://en.wikipedia.org/wiki/Andrew_S._Tanenbaumhttp://en.wikipedia.org/wiki/Minixhttp://en.wikipedia.org/wiki/Microkernelhttp://en.wikipedia.org/wiki/History_of_Linux#cite_note-15http://en.wikipedia.org/wiki/Monolithic_kernelhttp://en.wikipedia.org/wiki/Portinghttp://en.wikipedia.org/wiki/History_of_Linux#cite_note-16http://en.wikipedia.org/wiki/History_of_Linux#cite_note-16http://en.wikipedia.org/wiki/File_systemhttp://en.wikipedia.org/wiki/File_systemhttp://en.wikipedia.org/wiki/File_systemhttp://en.wikipedia.org/wiki/GNU_Hurdhttp://en.wikipedia.org/wiki/Bashhttp://en.wikipedia.org/wiki/GNU_Compiler_Collectionhttp://en.wikipedia.org/wiki/Andrew_S._Tanenbaumhttp://en.wikipedia.org/wiki/Minixhttp://en.wikipedia.org/wiki/Microkernelhttp://en.wikipedia.org/wiki/History_of_Linux#cite_note-15http://en.wikipedia.org/wiki/Monolithic_kernelhttp://en.wikipedia.org/wiki/Portinghttp://en.wikipedia.org/wiki/History_of_Linux#cite_note-16http://en.wikipedia.org/wiki/File_systemhttp://en.wikipedia.org/wiki/File_systemhttp://en.wikipedia.org/wiki/GNU_Hurd
  • 8/4/2019 Operating Systm Term Papere

    17/30

    1

    Linux Memory Management

    Linux uses segmentation + pagination, which simplifies notation.

    Segments

    Linux uses only 4 segments:

    2 segments (code and data/stack) for KERNEL SPACE from

    [0xC000 0000] (3 GB) to [0xFFFF FFFF] (4 GB)

    2 segments (code and data/stack) for USER SPACE from [0] (0

    GB) to [0xBFFF FFFF] (3 GB)

    __

    4 GB--->| | || Kernel | | Kernel Space (Code + Data/Stack)

    | | __|

    3 GB--->|----------------| __

    | | |

    | | |

    2 GB--->| | |

    | Tasks | | User Space (Code + Data/Stack)

    | | |

    1 GB--->| | || | |

    |________________| __|

    0x00000000

    Kernel/User Linear addresses

  • 8/4/2019 Operating Systm Term Papere

    18/30

    1

    7.2 Specific i386 implementation

    Again, Linux implements Pagination using 3 Levels of Paging, but in

    i386 architecture only 2 of them are really used:

    ------------------------------------------------------------------

    L I N E A R A D D R E S S

    ------------------------------------------------------------------

    \___/ \___/ \_____/

    PD offset PF offset Frame offset

    [10 bits] [10 bits] [12 bits]

    | | |

    | | ----------- |

    | | | Value |----------|---------

    | | | | |---------| /|\ | |

    | | | | | | | | |

    | | | | | | | Frame offset |

    | | | | | | \|/ |

    | | | | |---------||_________| PHYSICAL ADDRESS

    | | \|/ | | x 4096 | || CR3 |-------->| | | |

    |_____| | ....... | | ....... |

    | | | |

    Page Directory Page File

  • 8/4/2019 Operating Systm Term Papere

    19/30

    1

    Linux i386 Paging

    Linux Page Tables

    Figure 3.3: Three Level Page Tables

  • 8/4/2019 Operating Systm Term Papere

    20/30

    1

    7.3 Memory Mapping

    Linux manages Access Control with Pagination only, so different Tasks

    will have the same segment addresses, but different CR3 (register used

    to store Directory Page Address), pointing to different Page Entries.

    In User mode a task cannot overcome 3 GB limit (0 x C0 00 00 00), so

    only the first 768 page directory entries are meaningful (768*4MB =3GB).

    When a Task goes in Kernel Mode (by System call or by IRQ) the other

    256 pages directory entries become important, and they point to the

    same page files as all other Tasks (which are the same as the Kernel).

    Note that Kernel (and only kernel) Linear Space is equal to Kernel

    Physical Space, so:

    ________________ _____

    |Other KernelData|___ | | |

    |----------------| | |__| |

    | Kernel |\ |____| Real Other |

    3 GB --->|----------------| \ | Kernel Data |

    | |\ \ | |

    | __|_\_\____|__ Real || Tasks | \ \ | Tasks |

    | __|___\_\__|__ Space |

    | | \ \ | |

    | | \ \|----------------|

    | | \ |Real KernelSpace|

  • 8/4/2019 Operating Systm Term Papere

    21/30

    1

    |________________| \|________________|

    Logical Addresses Physical Addresses

    Linear Kernel Space corresponds to Physical Kernel Space translated 3

    GB down (in fact page tables are something like { "00000000",

    "00000001" }, so they operate no virtualization, they only report

    physical addresses they take from linear ones).

    Notice that you'll not have an "addresses conflict" between Kernel and

    User spaces because we can manage physical addresses with Page

    Tables.

    7.4 Low level memory allocation

    Boot Initialization

    We start from kmem_cache_init (launched by start_kernel [init/main.c]

    at boot up).

    |kmem_cache_init

    |kmem_cache_estimate

    kmem_cache_init [mm/slab.c]

    kmem_cache_estimate

    Now we continue with mem_init (also launched by

    start_kernel[init/main.c])

    |mem_init

    |free_all_bootmem

    |free_all_bootmem_core

    mem_init [arch/i386/mm/init.c]

  • 8/4/2019 Operating Systm Term Papere

    22/30

    1

    free_all_bootmem [mm/bootmem.c]

    free_all_bootmem_core

    Run-time allocation

    Under Linux, when we want to allocate memory, for example during

    "copy_on_write" mechanism (see Cap.10), we call:

    |copy_mm

    |allocate_mm = kmem_cache_alloc

    |__kmem_cache_alloc

    |kmem_cache_alloc_one

    |alloc_new_slab|kmem_cache_grow

    |kmem_getpages

    |__get_free_pages

    |alloc_pages

    |alloc_pages_pgdat

    |__alloc_pages

    |rmqueue

    |reclaim_pages

    Functions can be found under:

    copy_mm [kernel/fork.c]

    allocate_mm [kernel/fork.c]

    kmem_cache_alloc [mm/slab.c]

    __kmem_cache_alloc

    kmem_cache_alloc_one alloc_new_slab

    kmem_cache_grow

    kmem_getpages

    __get_free_pages [mm/page_alloc.c]

    alloc_pages [mm/numa.c]

  • 8/4/2019 Operating Systm Term Papere

    23/30

    1

    alloc_pages_pgdat

    __alloc_pages [mm/page_alloc.c]

    rm_queue

    reclaim_pages [mm/vmscan.c]

    TODO: Understand Zones

    7.5 Swap

    Overview

    Swap is managed by the kswapd daemon (kernel thread).

    kswapd

    As other kernel threads, kswapd has a main loop that wait to wake up.

    |kswapd

    |// initialization routines

    |for (;;) { // Main loop

    |do_try_to_free_pages

    |recalculate_vm_stats

    |refill_inactive_scan|run_task_queue

    |interruptible_sleep_on_timeout // we sleep for a new swap request

    |}

    kswapd [mm/vmscan.c]

    do_try_to_free_pages

    recalculate_vm_stats [mm/swap.c]

    refill_inactive_scan [mm/vmswap.c]

    run_task_queue [kernel/softirq.c]

    interruptible_sleep_on_timeout [kernel/sched.c]

  • 8/4/2019 Operating Systm Term Papere

    24/30

    1

    The Linux Page Cache

    Figure 3.6: The Linux Page Cache

    When do we need swapping?

    Swapping is needed when we have to access a page that is not in

    physical memory.

    Linux uses ''kswapd'' kernel thread to carry out this purpose. When the

    Task receives a page fault exception we do the following:

    | Page Fault Exception

    | cause by all these conditions:

  • 8/4/2019 Operating Systm Term Papere

    25/30

    1

    | a-) User page

    | b-) Read or write access

    | c-) Page not present

    |

    |-----------> |do_page_fault

    |handle_mm_fault

    |pte_alloc

    |pte_alloc_one

    |__get_free_page = __get_free_pages

    |alloc_pages

    |alloc_pages_pgdat

    |__alloc_pages|wakeup_kswapd // We wake up kernel thread

    kswapd

    Page Fault ICA

    do_page_fault [arch/i386/mm/fault.c]

    handle_mm_fault [mm/memory.c]

    pte_alloc pte_alloc_one [include/asm/pgalloc.h]

    __get_free_page [include/linux/mm.h]

    __get_free_pages [mm/page_alloc.c]

    alloc_pages [mm/numa.c]

    alloc_pages_pgdat

    __alloc_pages

    wakeup_kswapd [mm/vmscan.c]

  • 8/4/2019 Operating Systm Term Papere

    26/30

    1

    FIGURES

  • 8/4/2019 Operating Systm Term Papere

    27/30

    1

  • 8/4/2019 Operating Systm Term Papere

    28/30

    1

  • 8/4/2019 Operating Systm Term Papere

    29/30

    1

  • 8/4/2019 Operating Systm Term Papere

    30/30