SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

OS Components and Structure
OS Components and StructureOS Components and Structure
OS Components and Structuresathish sak
 
Modern operating system.......
Modern operating system.......Modern operating system.......
Modern operating system.......vignesh0009
 
Linux architecture
Linux architectureLinux architecture
Linux architecturemcganesh
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OSKumar Pritam
 
41 page replacement fifo
41 page replacement fifo41 page replacement fifo
41 page replacement fifomyrajendra
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating Systemsubhsikha
 
Processes and Processors in Distributed Systems
Processes and Processors in Distributed SystemsProcesses and Processors in Distributed Systems
Processes and Processors in Distributed SystemsDr Sandeep Kumar Poonia
 
Introduction of Memory Management
Introduction of Memory Management Introduction of Memory Management
Introduction of Memory Management Maitree Patel
 
Memory management
Memory managementMemory management
Memory managementcpjcollege
 
40 demand paging
40 demand paging40 demand paging
40 demand pagingmyrajendra
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory managementrprajat007
 
Thread scheduling in Operating Systems
Thread scheduling in Operating SystemsThread scheduling in Operating Systems
Thread scheduling in Operating SystemsNitish Gulati
 
Os structure
Os structureOs structure
Os structureMohd Arif
 

Was ist angesagt? (20)

OS Components and Structure
OS Components and StructureOS Components and Structure
OS Components and Structure
 
Memory management
Memory managementMemory management
Memory management
 
Modern operating system.......
Modern operating system.......Modern operating system.......
Modern operating system.......
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Distributed Operating System_1
Distributed Operating System_1Distributed Operating System_1
Distributed Operating System_1
 
process creation OS
process creation OSprocess creation OS
process creation OS
 
Paging.ppt
Paging.pptPaging.ppt
Paging.ppt
 
41 page replacement fifo
41 page replacement fifo41 page replacement fifo
41 page replacement fifo
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
 
Processes and Processors in Distributed Systems
Processes and Processors in Distributed SystemsProcesses and Processors in Distributed Systems
Processes and Processors in Distributed Systems
 
Introduction of Memory Management
Introduction of Memory Management Introduction of Memory Management
Introduction of Memory Management
 
Memory management
Memory managementMemory management
Memory management
 
40 demand paging
40 demand paging40 demand paging
40 demand paging
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory management
 
Memory management in linux
Memory management in linuxMemory management in linux
Memory management in linux
 
Unix case-study
Unix case-studyUnix case-study
Unix case-study
 
Thread scheduling in Operating Systems
Thread scheduling in Operating SystemsThread scheduling in Operating Systems
Thread scheduling in Operating Systems
 
Os structure
Os structureOs structure
Os structure
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 

Andere mochten auch

Andere mochten auch (8)

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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Kürzlich hochgeladen (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

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