SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Multi core-architecture
Multi core-architectureMulti core-architecture
Multi core-architecture
Piyush Mittal
 
Processes in unix
Processes in unixProcesses in unix
Processes in unix
miau_max
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
Piyush Rochwani
 

Mais procurados (20)

Distributed file system
Distributed file systemDistributed file system
Distributed file system
 
Storage Structure in OS
Storage Structure in OSStorage Structure in OS
Storage Structure in OS
 
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
 
Shared-Memory Multiprocessors
Shared-Memory MultiprocessorsShared-Memory Multiprocessors
Shared-Memory Multiprocessors
 
Distributed operating system(os)
Distributed operating system(os)Distributed operating system(os)
Distributed operating system(os)
 
UNIX Operating System
UNIX Operating SystemUNIX Operating System
UNIX Operating System
 
Unit 4 ca-input-output
Unit 4 ca-input-outputUnit 4 ca-input-output
Unit 4 ca-input-output
 
Operating system components
Operating system componentsOperating system components
Operating system components
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
 
Demand paging
Demand pagingDemand paging
Demand paging
 
Kernel (OS)
Kernel (OS)Kernel (OS)
Kernel (OS)
 
Multi core-architecture
Multi core-architectureMulti core-architecture
Multi core-architecture
 
Memory organization (Computer architecture)
Memory organization (Computer architecture)Memory organization (Computer architecture)
Memory organization (Computer architecture)
 
Memory management
Memory managementMemory management
Memory management
 
Distributed File Systems
Distributed File Systems Distributed File Systems
Distributed File Systems
 
Distributed Operating System_1
Distributed Operating System_1Distributed Operating System_1
Distributed Operating System_1
 
Processes in unix
Processes in unixProcesses in unix
Processes in unix
 
Operating Systems: Virtual Memory
Operating Systems: Virtual MemoryOperating Systems: Virtual Memory
Operating Systems: Virtual Memory
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 

Destaque (7)

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

Semelhante a Unix memory management

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
Mark Voelker
 
Xen and the Art of Virtualization
Xen and the Art of VirtualizationXen and the Art of Virtualization
Xen and the Art of Virtualization
Susheel Thakur
 

Semelhante a 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
 

Mais de Tech_MX

Virtual base class
Virtual base classVirtual base class
Virtual base class
Tech_MX
 
Theory of estimation
Theory of estimationTheory of estimation
Theory of estimation
Tech_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 application
Tech_MX
 
Statistical quality__control_2
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2
Tech_MX
 
Stack data structure
Stack data structureStack data structure
Stack data structure
Tech_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 & applications
Tech_MX
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2
Tech_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 System
Tech_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 pc
Tech_MX
 
More on Lex
More on LexMore on Lex
More on Lex
Tech_MX
 
MultiMedia dbms
MultiMedia dbmsMultiMedia dbms
MultiMedia dbms
Tech_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 dbms
Tech_MX
 

Mais 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
 

Último

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
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
heathfieldcps1
 

Último (20)

Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
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
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
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
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

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