SlideShare une entreprise Scribd logo
1  sur  35
UNIX MEMORY
MANAGEMENT




              1
AGENDA
 Introduction
 History of UNIX
 Swapping
 Demand Paging
Page Replacement Algorithm
 Kernel Memory Allocator
 Conclusion

                              2
Introduction

 UNIX is a portable, multi-tasking and multi-user operating
  system.
   – Portable: runs on many different hardware architectures (Intel
     x86 and IA-64, Alpha, MIPS, HP PA-RISC, PowerPC, IBM
     S/390, SPARC, Motorola 680x0, etc.).
   – Preemptive multi-tasking: several programs can run at the
     same time (time slices, interrupts, and task switching).
   – Multi-user: many users can share the computer system at the
     same time.


                                                                  3
Other Features…

• Uses a simple, uniform file model which includes devices and
  access to other services in a flexible, hierarchical file system.
• Written in a high-level language (“C”) making it easy to
  read, understand, change and port.
• The command prompt is a simple user process, the Unix shell,
  which is also a convenient job programming language.
• Includes support for regular expressions which are convenient
  for complex searching.



                                                                  4
History of UNIX
• 1964 joint project between AT&T Bell Labs, GE, and MIT to
  develop a new OS.

• Goal : develop an OS that could provide computational
  power, data storage and the ability to share data among
  multiple users.

• Result: Multiplexed Information & Computer Service -
  MULTICS.



                                                          5
• 1969 Bell Labs withdraws from group.
• Two Bell Lab scientists, Ken Thompson and Dennis Ritchie,
  continue research. They were still left without a “Convenient
  interactive computing service”*.
• At the same time Ken Thompson wrote a game “space
  travel” in Fortran to run on GECOS OS.
• The spaceship was hard to control and it was expensive to
  run. He was told to get the game off his work computer.




                                                             6
• Thompson ported the game to a little used PDP-7 computer.
• Unics (later Unix) was born as a pun on Multics.
• Dennis Ritchie developed “B” . Then wrote “C” a compiled
  language.
• In 1973 entire OS ported to “C”.
• 1991 Linux 0.02 is first released to the public.
• 1994 Linux 1.0 is released.



                                                         7
Memory Management

 UNIX is machine independent so its memory management
  scheme will vary from one system to next.
 Early versions of UNIX used variable partitioning with no
  virtual memory scheme.
 Current implementations of UNIX make use of paged virtual
  memory.
 There are two memory management schemes :
       Paging System
       Kernal Memory Allocator



                                                         8
Virtual Memory




                 9
Memory Management policies


• Swapping
  – Easy to implement
  – Less system overhead


• Demand Paging
  – Greater Flexibility



                                     10
Swapping
• The process of moving some pages out of main memory and
  moving others in, is called swapping.
• A page fault occurs when the CPU tries to access a page that
  is not in main memory, thus forcing the CPU to wait for the
  page to be swapped in.
• Since moving data to and from disks takes a significant
  amount of time, the goal of the memory manager is to
  minimize the number of page faults.




                                                            11
• Swap Space - Disk memory used to hold data that is not in
  Real or File System memory. Swap space is most efficient
  when it is on a separate disk or partition, but sometimes it is
  just a large file in the File System.
• Allocation of both main memory and swap space is done
  first-fit.
• A page fault occurs when the CPU tries to access a page
  that is not in main memory, thus forcing the CPU to wait for
  the page to be swapped in.


                                                               12
• Since moving data to and from disks takes a significant
  amount of time, the goal of the memory manager is to
  minimize the number of page faults.
• When the size of a process' memory image increases (due to
  either stack expansion or data expansion), a new piece of
  memory big enough for the whole image is allocated.
• If no single piece of main memory is large enough, the
  process is swapped out such that it will be swapped back in
  with the new size.


                                                           13
• Decisions regarding which processes to swap in or swap out
  are made by the scheduler process (also known as the
  swapper).
• A process is more likely to be swapped out if it is idle or has
  been in main memory for a long time, or is large ; if no
  obvious candidates are found, other processes are picked by
  age.
• A process is more likely to be swapped in if its has been
  swapped out a long time, or is small.


                                                               14
15
Allocating Swap Space
Address     Unit
                   Allocate 100 unit
1         10000                            101        9900
      Map

                                   Allocate 50 unit



                   Allocate 100 unit
251         9850                          151         9750


                                                             16
Freeing Swap Space
  Address           Unit
                                50 unit free at 101
  251              9750                                  101    50

           Map                                           251   9750




Case 1: Free resources fill a hole,
        but not contiguous to any resources in the map


                                                                      17
Freeing Swap Space
    Address             Unit
                                 50 unit free at 101        101         50
     251             9750
                                                            251        9750
             Map
                                                  100 unit free at 1


                                                            1           150

Case 2: Free resources fill a hole,
                                                            251        9750
   and immediately precedes an entry in the map


                                                                              18
Freeing Swap Space
Address          Unit                              101              50
                         50 unit free at 101
    251         9750                               251           9750
          Map
                                           100 unit free at 1


1                150     Allocate 200 unit          1              150

451             9550                                251           9750

            300 unit free at 151          Case 3: Free resources fill a
                                          hole, and completely fills the
1          10000                          gap between entries in the
                                          map                              19
Demand Paging

• Demand paging to unix with BSD(Berkley system) which
  transferred memory pages instead of process to and from a
  secondary device.

• When a process needs a page and the page is not there, a
  page fault to the kernel occurs a frame of main memory is
  allocated, and the process is loaded into the frame by the
  kernel.



                                                          20
Page Table
   Page Frame   Age   Copy on Modify Reference   Valid   Protect
    Number             write


• frame # contains the physical frame where the virtual page
  is stored
• age is processor dependant, and is meant to maintain how
  long it has been since the page was accessed.
• Copy on Write store the copy on write bit, which is used in
  UNIX systems to, among other things, render fork efficient.


                                                              21
• Dirty is a single bit that indicates whether a page has been
  modified since last swapped in (the opposite of dirty is clean,
  and a clean page need not be written out to disk if
  swapped).
• Ref contains the usage information necessary for a CLOCK-
  style algorithm.
• Valid is the standard UNIX jargon for resident. A valid page
  is in main memory, an invalid one is swapped out.
• Protect contains the permission information for the page
  and is also hardware dependant.


                                                               22
Disk block descriptor

 Swap device Number Device Block No.      Type of storage


• The disk block descriptor contains the information mapping
  a virtual page to a spot on disk.
• The OS maintains a table of descriptors for each process.




                                                            23
• Device # is basically a pointer to the disk that this page was
  swapped to.
• Block # is the actual block that the page is stored on. This is
  why most UNIX systems prefer to have a separate swap
  partition, so that the block size can be set to the page size.
• Type specifies whether the page is new or pre-existing. This
  lets the OS know if it has to clear the frame first.




                                                               24
Page frame data table

     Page State   Reference   Logical    Block   Pf data
                   Count      device    number   pointer



• The page frame data table holds information about each
  physical frame of memory (indexed by frame number).
• This table is of primary importance for the replacement
  algorithm.

                                                            25
• Page state indicates whether or not the frame is available or
  has an associated page (i.e. whether its been allocated to a
  process or not).
• Ref. Count holds the number of processes that refer to this
  page (remember, processes can share the same physical
  page).
• Logical device contains the device number of the disk that
  holds a physical copy of the page.



                                                              26
• Block # holds the block number on that disk where the
  page data is located.

• Pfdata pointer is a pointer field that is used to thread a
  singly-linked list of free frames through the frame table. If
  the page is free, this points to the next free page (useful for
  free list-style allocation).



                                                                    27
Swap use table

             Reference      Page/storage
             count          unit number



• Reference Count : Number of page table entries that point
  to a page on the swap device.
• Page/storage unit number : Page identifier on storage unit



                                                               28
Page Replacement Algorithm

• The Page frame data table is used for page replacement.

• All of the available frames are linked together in a list of free
  frames available for bringing in pages.

• The two-handed clock algorithm uses the reference bit in the
  page table entry for each page in memory that is eligible
  (not locked) to be swapped out.

• This bit is set to 0 when when the page is first brought in and
  set to 1 when the page is refernced for a read or write .
                                                                 29
Two-Handed clock Page Replacement Algorithm




                                              30
• Two parameters determine the operation of the algorithm:

   – Scanrate: The rate at which the two hands scan through the
     page list, in pages per second.
   – Handspread: The gap between fronthand and backhand

• These two parameters have default values set at boot time
  based on the amount of physical memory.




                                               31
• The parameter varies linearly between the values slowscan
  and fastscan as the amount of free memory varies between
  the values lotsfree and minfree.

• The handspread parameter determines the gap between the
  fronthand and the backhand and therefore, together with
  scanrate,determines the window of oppurtunity to use a
  page before it is swapped out due to lack of use.



                                                              32
Kernal Memory Allocator
• Kernel memory allocator: provides buffers of memory to
  various kernel subsytems.

Evolution Criteria :
   – must be space-efficient i.e. minimize wastage.
   – Can be measured by utilization factor
   – must be fast
   – must have a simple programming interface
   – should not force to free the entire allocated area all at once
   – must guard against the wastage of memory
   – must be able to interact with the paging system
                                                                      33
Advantages
• easy to implement
• not restricted to memory allocation
• no wastage of space
• can release any part of the region
• allows reuse of memory by coalescing



                                         34
References
Books :
*********
1. Os Internals & design
                --- William Stallings
2. The design of the unix operating system
                --- Maurice J. Bach prentice hall




                                                    35

Contenu connexe

Tendances

Handheld operting system
Handheld operting systemHandheld operting system
Handheld operting systemAj Maurya
 
Operating Systems: Device Management
Operating Systems: Device ManagementOperating Systems: Device Management
Operating Systems: Device ManagementDamian T. Gordon
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategiesDr. Loganathan R
 
Operating system components
Operating system componentsOperating system components
Operating system componentsSyed Zaid Irshad
 
Memory management
Memory managementMemory management
Memory managementcpjcollege
 
Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43myrajendra
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentationusmankiyani1
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structuresMukesh Chinta
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.Muhammad SiRaj Munir
 
History of Operating system
History of Operating systemHistory of Operating system
History of Operating systemtarun thakkar
 
Presentation on Segmentation
Presentation on SegmentationPresentation on Segmentation
Presentation on SegmentationPriyanka bisht
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory managementrprajat007
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating SystemsRitu Ranjan Shrivastwa
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memorysgpraju
 

Tendances (20)

Unix case-study
Unix case-studyUnix case-study
Unix case-study
 
Handheld operting system
Handheld operting systemHandheld operting system
Handheld operting system
 
Operating Systems: Device Management
Operating Systems: Device ManagementOperating Systems: Device Management
Operating Systems: Device Management
 
Memory management
Memory managementMemory management
Memory management
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategies
 
Operating system components
Operating system componentsOperating system components
Operating system components
 
Kernel (OS)
Kernel (OS)Kernel (OS)
Kernel (OS)
 
Memory management
Memory managementMemory management
Memory management
 
Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43
 
CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentation
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structures
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.
 
Process state in OS
Process state in OSProcess state in OS
Process state in OS
 
History of Operating system
History of Operating systemHistory of Operating system
History of Operating system
 
Presentation on Segmentation
Presentation on SegmentationPresentation on Segmentation
Presentation on Segmentation
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory management
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
System calls
System callsSystem calls
System calls
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memory
 

En vedette

En vedette (9)

Unix Process management
Unix Process managementUnix Process management
Unix Process management
 
comparing windows and linux ppt
comparing windows and linux pptcomparing windows and linux ppt
comparing windows and linux ppt
 
Processes in unix
Processes in unixProcesses in unix
Processes in unix
 
Linux Introduction
Linux IntroductionLinux Introduction
Linux Introduction
 
Case study linux
Case study linuxCase study linux
Case study linux
 
Linux v/s Windows
Linux v/s WindowsLinux v/s Windows
Linux v/s Windows
 
Unix operating system
Unix operating systemUnix operating system
Unix operating system
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
 
UNIX Operating System
UNIX Operating SystemUNIX Operating System
UNIX Operating System
 

Similaire à Unix memory management

Manta: a new internet-facing object storage facility that features compute by...
Manta: a new internet-facing object storage facility that features compute by...Manta: a new internet-facing object storage facility that features compute by...
Manta: a new internet-facing object storage facility that features compute by...Hakka Labs
 
The Internet-of-things: Architecting for the deluge of data
The Internet-of-things: Architecting for the deluge of dataThe Internet-of-things: Architecting for the deluge of data
The Internet-of-things: Architecting for the deluge of databcantrill
 
Bringing the Unix Philosophy to Big Data
Bringing the Unix Philosophy to Big DataBringing the Unix Philosophy to Big Data
Bringing the Unix Philosophy to Big Databcantrill
 
INTRODUCTION TO PARALLEL PROCESSING
INTRODUCTION TO PARALLEL PROCESSINGINTRODUCTION TO PARALLEL PROCESSING
INTRODUCTION TO PARALLEL PROCESSINGGS Kosta
 
Introducing Plan9 from Bell Labs
Introducing Plan9 from Bell LabsIntroducing Plan9 from Bell Labs
Introducing Plan9 from Bell LabsAnant Narayanan
 
OS Slide Ch12 13
OS Slide Ch12 13OS Slide Ch12 13
OS Slide Ch12 13庭緯 陳
 
OpenStack & the Evolving Cloud Ecosystem
OpenStack & the Evolving Cloud EcosystemOpenStack & the Evolving Cloud Ecosystem
OpenStack & the Evolving Cloud EcosystemMark Voelker
 
The Rise of Cloud Computing Systems
The Rise of Cloud Computing SystemsThe Rise of Cloud Computing Systems
The Rise of Cloud Computing SystemsDaehyeok Kim
 
The building blocks of docker.
The building blocks of docker.The building blocks of docker.
The building blocks of docker.Chafik Belhaoues
 
CS403: Operating System : Lec 7 OS Properties.pptx
CS403: Operating System : Lec 7 OS Properties.pptxCS403: Operating System : Lec 7 OS Properties.pptx
CS403: Operating System : Lec 7 OS Properties.pptxAsst.prof M.Gokilavani
 
Xen and the Art of Virtualization
Xen and the Art of VirtualizationXen and the Art of Virtualization
Xen and the Art of VirtualizationSusheel Thakur
 
Disk Management through the Computer Management
Disk Management through the Computer ManagementDisk Management through the Computer Management
Disk Management through the Computer ManagementAnshGoyal32
 

Similaire à Unix memory management (20)

Manta: a new internet-facing object storage facility that features compute by...
Manta: a new internet-facing object storage facility that features compute by...Manta: a new internet-facing object storage facility that features compute by...
Manta: a new internet-facing object storage facility that features compute by...
 
The Internet-of-things: Architecting for the deluge of data
The Internet-of-things: Architecting for the deluge of dataThe Internet-of-things: Architecting for the deluge of data
The Internet-of-things: Architecting for the deluge of data
 
Bringing the Unix Philosophy to Big Data
Bringing the Unix Philosophy to Big DataBringing the Unix Philosophy to Big Data
Bringing the Unix Philosophy to Big Data
 
os
osos
os
 
Module5 secondary storage
Module5 secondary storageModule5 secondary storage
Module5 secondary storage
 
Factored operating systems
Factored operating systemsFactored operating systems
Factored operating systems
 
INTRODUCTION TO PARALLEL PROCESSING
INTRODUCTION TO PARALLEL PROCESSINGINTRODUCTION TO PARALLEL PROCESSING
INTRODUCTION TO PARALLEL PROCESSING
 
Os
OsOs
Os
 
Introducing Plan9 from Bell Labs
Introducing Plan9 from Bell LabsIntroducing Plan9 from Bell Labs
Introducing Plan9 from Bell Labs
 
OS Slide Ch12 13
OS Slide Ch12 13OS Slide Ch12 13
OS Slide Ch12 13
 
OpenStack & the Evolving Cloud Ecosystem
OpenStack & the Evolving Cloud EcosystemOpenStack & the Evolving Cloud Ecosystem
OpenStack & the Evolving Cloud Ecosystem
 
The Rise of Cloud Computing Systems
The Rise of Cloud Computing SystemsThe Rise of Cloud Computing Systems
The Rise of Cloud Computing Systems
 
Disk Architecture.pptx
Disk Architecture.pptxDisk Architecture.pptx
Disk Architecture.pptx
 
The building blocks of docker.
The building blocks of docker.The building blocks of docker.
The building blocks of docker.
 
CS403: Operating System : Lec 7 OS Properties.pptx
CS403: Operating System : Lec 7 OS Properties.pptxCS403: Operating System : Lec 7 OS Properties.pptx
CS403: Operating System : Lec 7 OS Properties.pptx
 
Xen and the Art of Virtualization
Xen and the Art of VirtualizationXen and the Art of Virtualization
Xen and the Art of Virtualization
 
Unixfs
UnixfsUnixfs
Unixfs
 
18CSC205J-UNIT-5.pptx
18CSC205J-UNIT-5.pptx18CSC205J-UNIT-5.pptx
18CSC205J-UNIT-5.pptx
 
NASA's Movement Towards Cloud Computing
NASA's Movement Towards Cloud ComputingNASA's Movement Towards Cloud Computing
NASA's Movement Towards Cloud Computing
 
Disk Management through the Computer Management
Disk Management through the Computer ManagementDisk Management through the Computer Management
Disk Management through the Computer Management
 

Plus de Tech_MX

Virtual base class
Virtual base classVirtual base class
Virtual base classTech_MX
 
Theory of estimation
Theory of estimationTheory of estimation
Theory of estimationTech_MX
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
String & its application
String & its applicationString & its application
String & its applicationTech_MX
 
Statistical quality__control_2
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2Tech_MX
 
Stack data structure
Stack data structureStack data structure
Stack data structureTech_MX
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application Tech_MX
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applicationsTech_MX
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2Tech_MX
 
Set data structure
Set data structure Set data structure
Set data structure Tech_MX
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating SystemTech_MX
 
Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Tech_MX
 
Motherboard of a pc
Motherboard of a pcMotherboard of a pc
Motherboard of a pcTech_MX
 
More on Lex
More on LexMore on Lex
More on LexTech_MX
 
MultiMedia dbms
MultiMedia dbmsMultiMedia dbms
MultiMedia dbmsTech_MX
 
Merging files (Data Structure)
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)Tech_MX
 
Memory dbms
Memory dbmsMemory dbms
Memory dbmsTech_MX
 

Plus de Tech_MX (20)

Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Uid
UidUid
Uid
 
Theory of estimation
Theory of estimationTheory of estimation
Theory of estimation
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
String & its application
String & its applicationString & its application
String & its application
 
Statistical quality__control_2
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
Spss
SpssSpss
Spss
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2
 
Set data structure
Set data structure Set data structure
Set data structure
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating System
 
Parsing
ParsingParsing
Parsing
 
Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)
 
Motherboard of a pc
Motherboard of a pcMotherboard of a pc
Motherboard of a pc
 
More on Lex
More on LexMore on Lex
More on Lex
 
MultiMedia dbms
MultiMedia dbmsMultiMedia dbms
MultiMedia dbms
 
Merging files (Data Structure)
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)
 
Memory dbms
Memory dbmsMemory dbms
Memory dbms
 

Dernier

ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 

Dernier (20)

YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 

Unix memory management

  • 2. AGENDA  Introduction  History of UNIX  Swapping  Demand Paging Page Replacement Algorithm  Kernel Memory Allocator  Conclusion 2
  • 3. Introduction  UNIX is a portable, multi-tasking and multi-user operating system. – Portable: runs on many different hardware architectures (Intel x86 and IA-64, Alpha, MIPS, HP PA-RISC, PowerPC, IBM S/390, SPARC, Motorola 680x0, etc.). – Preemptive multi-tasking: several programs can run at the same time (time slices, interrupts, and task switching). – Multi-user: many users can share the computer system at the same time. 3
  • 4. Other Features… • Uses a simple, uniform file model which includes devices and access to other services in a flexible, hierarchical file system. • Written in a high-level language (“C”) making it easy to read, understand, change and port. • The command prompt is a simple user process, the Unix shell, which is also a convenient job programming language. • Includes support for regular expressions which are convenient for complex searching. 4
  • 5. History of UNIX • 1964 joint project between AT&T Bell Labs, GE, and MIT to develop a new OS. • Goal : develop an OS that could provide computational power, data storage and the ability to share data among multiple users. • Result: Multiplexed Information & Computer Service - MULTICS. 5
  • 6. • 1969 Bell Labs withdraws from group. • Two Bell Lab scientists, Ken Thompson and Dennis Ritchie, continue research. They were still left without a “Convenient interactive computing service”*. • At the same time Ken Thompson wrote a game “space travel” in Fortran to run on GECOS OS. • The spaceship was hard to control and it was expensive to run. He was told to get the game off his work computer. 6
  • 7. • Thompson ported the game to a little used PDP-7 computer. • Unics (later Unix) was born as a pun on Multics. • Dennis Ritchie developed “B” . Then wrote “C” a compiled language. • In 1973 entire OS ported to “C”. • 1991 Linux 0.02 is first released to the public. • 1994 Linux 1.0 is released. 7
  • 8. Memory Management  UNIX is machine independent so its memory management scheme will vary from one system to next.  Early versions of UNIX used variable partitioning with no virtual memory scheme.  Current implementations of UNIX make use of paged virtual memory.  There are two memory management schemes :  Paging System  Kernal Memory Allocator 8
  • 10. Memory Management policies • Swapping – Easy to implement – Less system overhead • Demand Paging – Greater Flexibility 10
  • 11. Swapping • The process of moving some pages out of main memory and moving others in, is called swapping. • A page fault occurs when the CPU tries to access a page that is not in main memory, thus forcing the CPU to wait for the page to be swapped in. • Since moving data to and from disks takes a significant amount of time, the goal of the memory manager is to minimize the number of page faults. 11
  • 12. • Swap Space - Disk memory used to hold data that is not in Real or File System memory. Swap space is most efficient when it is on a separate disk or partition, but sometimes it is just a large file in the File System. • Allocation of both main memory and swap space is done first-fit. • A page fault occurs when the CPU tries to access a page that is not in main memory, thus forcing the CPU to wait for the page to be swapped in. 12
  • 13. • Since moving data to and from disks takes a significant amount of time, the goal of the memory manager is to minimize the number of page faults. • When the size of a process' memory image increases (due to either stack expansion or data expansion), a new piece of memory big enough for the whole image is allocated. • If no single piece of main memory is large enough, the process is swapped out such that it will be swapped back in with the new size. 13
  • 14. • Decisions regarding which processes to swap in or swap out are made by the scheduler process (also known as the swapper). • A process is more likely to be swapped out if it is idle or has been in main memory for a long time, or is large ; if no obvious candidates are found, other processes are picked by age. • A process is more likely to be swapped in if its has been swapped out a long time, or is small. 14
  • 15. 15
  • 16. Allocating Swap Space Address Unit Allocate 100 unit 1 10000 101 9900 Map Allocate 50 unit Allocate 100 unit 251 9850 151 9750 16
  • 17. Freeing Swap Space Address Unit 50 unit free at 101 251 9750 101 50 Map 251 9750 Case 1: Free resources fill a hole, but not contiguous to any resources in the map 17
  • 18. Freeing Swap Space Address Unit 50 unit free at 101 101 50 251 9750 251 9750 Map 100 unit free at 1 1 150 Case 2: Free resources fill a hole, 251 9750 and immediately precedes an entry in the map 18
  • 19. Freeing Swap Space Address Unit 101 50 50 unit free at 101 251 9750 251 9750 Map 100 unit free at 1 1 150 Allocate 200 unit 1 150 451 9550 251 9750 300 unit free at 151 Case 3: Free resources fill a hole, and completely fills the 1 10000 gap between entries in the map 19
  • 20. Demand Paging • Demand paging to unix with BSD(Berkley system) which transferred memory pages instead of process to and from a secondary device. • When a process needs a page and the page is not there, a page fault to the kernel occurs a frame of main memory is allocated, and the process is loaded into the frame by the kernel. 20
  • 21. Page Table Page Frame Age Copy on Modify Reference Valid Protect Number write • frame # contains the physical frame where the virtual page is stored • age is processor dependant, and is meant to maintain how long it has been since the page was accessed. • Copy on Write store the copy on write bit, which is used in UNIX systems to, among other things, render fork efficient. 21
  • 22. • Dirty is a single bit that indicates whether a page has been modified since last swapped in (the opposite of dirty is clean, and a clean page need not be written out to disk if swapped). • Ref contains the usage information necessary for a CLOCK- style algorithm. • Valid is the standard UNIX jargon for resident. A valid page is in main memory, an invalid one is swapped out. • Protect contains the permission information for the page and is also hardware dependant. 22
  • 23. Disk block descriptor Swap device Number Device Block No. Type of storage • The disk block descriptor contains the information mapping a virtual page to a spot on disk. • The OS maintains a table of descriptors for each process. 23
  • 24. • Device # is basically a pointer to the disk that this page was swapped to. • Block # is the actual block that the page is stored on. This is why most UNIX systems prefer to have a separate swap partition, so that the block size can be set to the page size. • Type specifies whether the page is new or pre-existing. This lets the OS know if it has to clear the frame first. 24
  • 25. Page frame data table Page State Reference Logical Block Pf data Count device number pointer • The page frame data table holds information about each physical frame of memory (indexed by frame number). • This table is of primary importance for the replacement algorithm. 25
  • 26. • Page state indicates whether or not the frame is available or has an associated page (i.e. whether its been allocated to a process or not). • Ref. Count holds the number of processes that refer to this page (remember, processes can share the same physical page). • Logical device contains the device number of the disk that holds a physical copy of the page. 26
  • 27. • Block # holds the block number on that disk where the page data is located. • Pfdata pointer is a pointer field that is used to thread a singly-linked list of free frames through the frame table. If the page is free, this points to the next free page (useful for free list-style allocation). 27
  • 28. Swap use table Reference Page/storage count unit number • Reference Count : Number of page table entries that point to a page on the swap device. • Page/storage unit number : Page identifier on storage unit 28
  • 29. Page Replacement Algorithm • The Page frame data table is used for page replacement. • All of the available frames are linked together in a list of free frames available for bringing in pages. • The two-handed clock algorithm uses the reference bit in the page table entry for each page in memory that is eligible (not locked) to be swapped out. • This bit is set to 0 when when the page is first brought in and set to 1 when the page is refernced for a read or write . 29
  • 30. Two-Handed clock Page Replacement Algorithm 30
  • 31. • Two parameters determine the operation of the algorithm: – Scanrate: The rate at which the two hands scan through the page list, in pages per second. – Handspread: The gap between fronthand and backhand • These two parameters have default values set at boot time based on the amount of physical memory. 31
  • 32. • The parameter varies linearly between the values slowscan and fastscan as the amount of free memory varies between the values lotsfree and minfree. • The handspread parameter determines the gap between the fronthand and the backhand and therefore, together with scanrate,determines the window of oppurtunity to use a page before it is swapped out due to lack of use. 32
  • 33. Kernal Memory Allocator • Kernel memory allocator: provides buffers of memory to various kernel subsytems. Evolution Criteria : – must be space-efficient i.e. minimize wastage. – Can be measured by utilization factor – must be fast – must have a simple programming interface – should not force to free the entire allocated area all at once – must guard against the wastage of memory – must be able to interact with the paging system 33
  • 34. Advantages • easy to implement • not restricted to memory allocation • no wastage of space • can release any part of the region • allows reuse of memory by coalescing 34
  • 35. References Books : ********* 1. Os Internals & design --- William Stallings 2. The design of the unix operating system --- Maurice J. Bach prentice hall 35