Memory management

Vishal Singh
Vishal Singhsoftware development consultant
Operating System-Memory
      Management

          by
      Vishal Singh
     (Vishalchd11@yahoo.com)
Why Memory management ?
1. To ensure protection of different
   processes from each other (so that
   they do not interfere with each other’s
   operations).
2. To place the programs in memory
   (such that memory is utilized to its
   fullest extent.
Logical vs. physical address
               space
► A logical address is the address of an
 instruction or data as used by a program.

► A physical address is the effective memory
 address of an instruction or data i.e. it is the
 address obtained after binding of logical
 addresses has been done.
Program relocation
Relocation register
► Relocation register is a special register in
  the CPU used for program relocation means
  mapping of logical addresses used by the
  program to physical addresses of the
  system’s main memory
Storage Allocation and
    Management Techniques
The Storage allocation can be of two types:

 (i) Contiguous storage allocation.

 (ii) Non-contiguous storage allocation.
Contiguous Storage Allocation
► Contiguous storage allocation implies that a
  program’s data and instructions are assured
  to occupy a single contiguous memory area.
► It is further subdivided into Fixed-partition
  storage allocation strategy and variable-
  partition storage allocation strategy.
1. Fixed-partition contiguous
       storage allocation

► processes with small address space use
 small partitions and processes with large
 address space use large partitions. This is
 known as fixed partition contiguous storage
 allocation.
Memory management
2. Variable - partition
contiguous storage allocation

This notion is derived from parking of vehicles on
the sides of streets where the one who manages
to enter will get the space. Two vehicles can
leave a space between them that cannot be used
by any vehicle. This means that whenever a
process needs memory, a search for the space
needed by it, is done. If contiguous space is
available to accommodate that process, then the
process is loaded into memory.
External Fragmentation
► This phenomenon of entering and leaving
 the memory can cause the formation of
 unusable memory holes (like the unused
 space between two vehicles). This is
 known as External Fragmentation.
Three strategies that can be used to
 allocate memory to Variable - partition
They are the following:

1. Best - Fit
2. Worst - fit
3. First - fit
Best - Fit - chooses a partition that is smallest and whose
     size is greater than equal to k. It leaves small-sized
     unusable partitions or holes.
First - fit - chooses the first partition whose
    size is greater than equal to k.
Worst - fit - chooses the largest partition and
   allocates it to process p. It can leave bigger
   unusable partitions.
Compaction means to move the processes in the
memory in such a way that scattered pieces of
unused (free) memory can be placed together so
that any other process demanding contiguous
memory for it can use it.
Non-contiguous Storage
          Allocation
► To resolve the problem     of external
 fragmentation and to enhance the
 degree of multiprogramming to a
 greater extent, it was decided to sacrifice
 the simplicity of allocating contiguous
 memory to every process. It was decided to
 have a non-contiguous physical address
 space of a process so that a process could
 be allocated memory wherever it was
 available.
Non-contiguous Storage Allocation
There are 2 techniques for non-contiguous
allocation:
1. Paging
2. Segmentation
1. Paging
► In this approach,physical memory is
 divided into fixed-size blocks called
 frames and the logical memory is
 divided into the fixed-sized blocks
 called pages. The size of a page is
 same as that of frame. The key idea of
 this method is to place the pages of a
 process into the available frames of
 memory, whenever, this process is to be
 executed. The address mapping is done
 by Page table.
Paging example
It works as:
Translate logical address 13 = 01101 in
   binary
Offset = 01 in binary or 1 in decimal
Page no. = 011 in binary or 3 in decimal
Physical address = pageframe*pagesize +
   offset i.e. 2*4+1 = 9 (which is the real
   address of page containing character “n”
   in the main memory)
Problem with paging
► It uses a page table per process for
  translating logical to physical address
  space. A basic issue associated with the
  use of page table is, that the look up in the
  page table should be very fast (which is
  generally slow), as it is done on every
  memory reference.
► So to make the look up time less, caching
  is used. In this case, the specific cache
  device is called a translation look aside
  buffer (TLB).
Translation look aside buffer (TLB).
► The TLB contains a set of entries, each of
  which contains a page number, the
  corresponding frame number, and the
  protection bits.
► So if we use TLB, then mapping is done
  by TLB and we generally find the entry in
  TLB but in case the entry is not found in
  TLB than we have a TLB miss and finally
  we go to page table.
Segmentation
► segmentation is another technique for the
  noncontiguous storage allocation. It is different
  from paging as it supports users’ view of his
  program.
► For a programmer it might be more relevant to
  divide the logical address space of his program
  into variable sized segments (with respect to his
  view of main program, subroutines, data, etc.)
  than to divide it into fixed size pages. Such
  variable sized segments, which are a collection
  of logically related information, are the basis of
  segmentation technique.
Segmentation example
Virtual Memory

► Virtual memory is a technique of executing
  program instructions that may not fit entirely in
  system memory. This is done by calling
  instructions as and when the application requires
  it. Virtual memory is implemented by using
  secondary storage to augment the main
  memory. Data is transferred from secondary to
  main storage as and when necessary and the
  data modified is written back to the secondary
  storage according to a predetermined algorithm.
Swapping
► Swapping is the technique of temporarily
  removing inactive programs from the main
  memory of a computer system. An
  inactive program is one that is neither
  executing nor performing an I/O operation.
► This may also happen when it is desired to
  place a higher-priority process in the
  memory. A lower priority process may be
  swapped out so that higher-priority
  process may be loaded and executed.
Memory management
Demand Paging
► In virtual memory system, demand paging is a
  type of swapping in which pages of programs
  are not copied from disk to main memory until
  they are needed for execution.
► In demand paging, virtual address (logical
  address) is accessed by CPU, the
  corresponding page number is looked up in the
  page table and if it shows that currently this
  page is not in main memory, then this page must
  be brought into the main-memory.
► A page  fault occurs when an invalid
 page is addressed. Page fault must be
 followed by swapping-in the page
 (demanded just now by the CPU) from
 disk to main-memory or a trap should be
 generated to the operating system if the
 page being demanded is not within the
 logical address space of the process. To
 determine whether the reference to the
 requested page is within the logical
 address space or not, an internal table
 may be consulted
Memory management
Memory management
Pure Demand Paging
► Pure demand paging is the form of
 demand paging in which not even a
 single page is loaded into memory,
 initially. Thus, the very first instruction
 causes a page fault in this case. This kind
 of demand paging may significantly
 decrease the performance of a computer
 system by generally increasing the
 effective access time of memory.
Page Replacement
► Once the main memory fills up, a page
  must be swapped out to make room for
  any pages to be swapped in. This is
  known as page replacement.
► We have page replacement algorithms for
  page replacement purpose, which are as
  follows:
1.   The optimal page replacement
     algorithm
2.   The first-in, first-out (FIFO) page
     replacement algorithm
3.   The second chance page replacement
     algorithm
4.   The least recently used (LRU) page
     replacement algorithm
5.   Simulating LRU in Software (Not frequently
     used algorithm)
6.   The Working Set Page Replacement
     Algorithm
1 de 35

Recomendados

Paging and segmentation por
Paging and segmentationPaging and segmentation
Paging and segmentationPiyush Rochwani
66.7K visualizações32 slides
Memory management ppt por
Memory management pptMemory management ppt
Memory management pptManishaJha43
1.5K visualizações64 slides
Memory Organization por
Memory OrganizationMemory Organization
Memory OrganizationKamal Acharya
31.6K visualizações53 slides
Memory Management in OS por
Memory Management in OSMemory Management in OS
Memory Management in OSvampugani
8.2K visualizações25 slides
Operating system memory management por
Operating system memory managementOperating system memory management
Operating system memory managementrprajat007
5.8K visualizações23 slides
Virtual memory por
Virtual memoryVirtual memory
Virtual memoryAnuj Modi
37.2K visualizações15 slides

Mais conteúdo relacionado

Mais procurados

Demand paging por
Demand pagingDemand paging
Demand pagingTrinity Dwarka
22.9K visualizações39 slides
Operating System-Memory Management por
Operating System-Memory ManagementOperating System-Memory Management
Operating System-Memory ManagementAkmal Cikmat
15.4K visualizações15 slides
Memory management por
Memory managementMemory management
Memory managementMuhammad Fayyaz
34.4K visualizações25 slides
Virtual Memory por
Virtual MemoryVirtual Memory
Virtual MemoryArchith777
1.3K visualizações24 slides
Virtual memory por
Virtual memoryVirtual memory
Virtual memoryaaina_katyal
6.7K visualizações14 slides
Process management os concept por
Process management os conceptProcess management os concept
Process management os conceptpriyadeosarkar91
17K visualizações87 slides

Mais procurados(20)

Demand paging por Trinity Dwarka
Demand pagingDemand paging
Demand paging
Trinity Dwarka22.9K visualizações
Operating System-Memory Management por Akmal Cikmat
Operating System-Memory ManagementOperating System-Memory Management
Operating System-Memory Management
Akmal Cikmat15.4K visualizações
Memory management por Muhammad Fayyaz
Memory managementMemory management
Memory management
Muhammad Fayyaz34.4K visualizações
Virtual Memory por Archith777
Virtual MemoryVirtual Memory
Virtual Memory
Archith7771.3K visualizações
Virtual memory por aaina_katyal
Virtual memoryVirtual memory
Virtual memory
aaina_katyal6.7K visualizações
Process management os concept por priyadeosarkar91
Process management os conceptProcess management os concept
Process management os concept
priyadeosarkar9117K visualizações
Memory management por cpjcollege
Memory managementMemory management
Memory management
cpjcollege7.6K visualizações
Memory management por Mohammad Sadiq
Memory managementMemory management
Memory management
Mohammad Sadiq3.1K visualizações
Operating system paging and segmentation por hamza haseeb
Operating system paging and segmentationOperating system paging and segmentation
Operating system paging and segmentation
hamza haseeb3.6K visualizações
Presentation on Segmentation por Priyanka bisht
Presentation on SegmentationPresentation on Segmentation
Presentation on Segmentation
Priyanka bisht5.3K visualizações
Paging and Segmentation in Operating System por Raj Mohan
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating System
Raj Mohan82.8K visualizações
File system structure por sangrampatil81
File system structureFile system structure
File system structure
sangrampatil813K visualizações
OS - Process Concepts por Mukesh Chinta
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
Mukesh Chinta23.9K visualizações
Mass Storage Structure por Vimalanathan D
Mass Storage StructureMass Storage Structure
Mass Storage Structure
Vimalanathan D7.4K visualizações
CPU Scheduling Algorithms por Shubhashish Punj
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
Shubhashish Punj99.5K visualizações
Chapter 12 - Mass Storage Systems por Wayne Jones Jnr
Chapter 12 - Mass Storage SystemsChapter 12 - Mass Storage Systems
Chapter 12 - Mass Storage Systems
Wayne Jones Jnr8.6K visualizações
Virtual Memory por sanjana mun
Virtual MemoryVirtual Memory
Virtual Memory
sanjana mun3.3K visualizações
Interrupts por Urwa Shanza
InterruptsInterrupts
Interrupts
Urwa Shanza15K visualizações
Memory Management in OS por Kumar Pritam
Memory Management in OSMemory Management in OS
Memory Management in OS
Kumar Pritam1.2K visualizações

Destaque

Virtual Memory and Paging por
Virtual Memory and PagingVirtual Memory and Paging
Virtual Memory and PagingEmery Berger
17.9K visualizações96 slides
Os Swapping, Paging, Segmentation and Virtual Memory por
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memorysgpraju
141.2K visualizações52 slides
The Internals of "Hello World" Program por
The Internals of "Hello World" ProgramThe Internals of "Hello World" Program
The Internals of "Hello World" ProgramNational Cheng Kung University
15.3K visualizações74 slides
Data structure lecture 1 por
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1Samsil Arefin
806 visualizações14 slides
Linkers And Loaders por
Linkers And LoadersLinkers And Loaders
Linkers And LoadersSatpal Parmar
11.1K visualizações16 slides
Program Structure in GNU/Linux (ELF Format) por
Program Structure in GNU/Linux (ELF Format)Program Structure in GNU/Linux (ELF Format)
Program Structure in GNU/Linux (ELF Format)Varun Mahajan
7.9K visualizações29 slides

Destaque(20)

Virtual Memory and Paging por Emery Berger
Virtual Memory and PagingVirtual Memory and Paging
Virtual Memory and Paging
Emery Berger17.9K visualizações
Os Swapping, Paging, Segmentation and Virtual Memory por sgpraju
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memory
sgpraju141.2K visualizações
Data structure lecture 1 por Samsil Arefin
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1
Samsil Arefin806 visualizações
Linkers And Loaders por Satpal Parmar
Linkers And LoadersLinkers And Loaders
Linkers And Loaders
Satpal Parmar11.1K visualizações
Program Structure in GNU/Linux (ELF Format) por Varun Mahajan
Program Structure in GNU/Linux (ELF Format)Program Structure in GNU/Linux (ELF Format)
Program Structure in GNU/Linux (ELF Format)
Varun Mahajan7.9K visualizações
04 Cache Memory por Jeanie Delos Arcos
04  Cache  Memory04  Cache  Memory
04 Cache Memory
Jeanie Delos Arcos25.2K visualizações
Paging por guest53a712
PagingPaging
Paging
guest53a7124.7K visualizações
Software Testing por Vishal Singh
Software TestingSoftware Testing
Software Testing
Vishal Singh2.1K visualizações
Software engineering introduction por Vishal Singh
Software engineering introductionSoftware engineering introduction
Software engineering introduction
Vishal Singh3.7K visualizações
8 memory management strategies por Dr. Loganathan R
8 memory management strategies8 memory management strategies
8 memory management strategies
Dr. Loganathan R44.7K visualizações
Virtual memory por Shashank Shetty
Virtual memoryVirtual memory
Virtual memory
Shashank Shetty10.9K visualizações
Virtual memory por aaina_katyal
Virtual memoryVirtual memory
Virtual memory
aaina_katyal13.3K visualizações
Coding por Vishal Singh
CodingCoding
Coding
Vishal Singh13.3K visualizações
Knowledge Representation in Artificial intelligence por Yasir Khan
Knowledge Representation in Artificial intelligence Knowledge Representation in Artificial intelligence
Knowledge Representation in Artificial intelligence
Yasir Khan39.1K visualizações
Knowledge representation in AI por Vishal Singh
Knowledge representation in AIKnowledge representation in AI
Knowledge representation in AI
Vishal Singh88.9K visualizações
Software Requirement Specification por Vishal Singh
Software Requirement SpecificationSoftware Requirement Specification
Software Requirement Specification
Vishal Singh19.2K visualizações
Issues in knowledge representation por Sravanthi Emani
Issues in knowledge representationIssues in knowledge representation
Issues in knowledge representation
Sravanthi Emani60.3K visualizações
Computer memory por Xấu Điên
Computer memoryComputer memory
Computer memory
Xấu Điên83.9K visualizações

Similar a Memory management

Ch9 OS por
Ch9 OSCh9 OS
Ch9 OSC.U
2.8K visualizações54 slides
OSCh9 por
OSCh9OSCh9
OSCh9Joe Christensen
1.3K visualizações54 slides
OS_Ch9 por
OS_Ch9OS_Ch9
OS_Ch9Supriya Shrivastava
746 visualizações54 slides
Paging +Algorithem+Segmentation+memory management por
Paging +Algorithem+Segmentation+memory managementPaging +Algorithem+Segmentation+memory management
Paging +Algorithem+Segmentation+memory managementkazim Hussain
744 visualizações40 slides
UNIT-2 OS.pptx por
UNIT-2 OS.pptxUNIT-2 OS.pptx
UNIT-2 OS.pptxssusera387fd1
6 visualizações57 slides
Virtual Memory por
Virtual MemoryVirtual Memory
Virtual Memoryvampugani
2.6K visualizações31 slides

Similar a Memory management(20)

Ch9 OS por C.U
Ch9 OSCh9 OS
Ch9 OS
C.U2.8K visualizações
OSCh9 por Joe Christensen
OSCh9OSCh9
OSCh9
Joe Christensen1.3K visualizações
Paging +Algorithem+Segmentation+memory management por kazim Hussain
Paging +Algorithem+Segmentation+memory managementPaging +Algorithem+Segmentation+memory management
Paging +Algorithem+Segmentation+memory management
kazim Hussain744 visualizações
UNIT-2 OS.pptx por ssusera387fd1
UNIT-2 OS.pptxUNIT-2 OS.pptx
UNIT-2 OS.pptx
ssusera387fd16 visualizações
Virtual Memory por vampugani
Virtual MemoryVirtual Memory
Virtual Memory
vampugani2.6K visualizações
Chapter 9 OS por C.U
Chapter 9 OSChapter 9 OS
Chapter 9 OS
C.U1.3K visualizações
Os unit 2 por Arnav Chowdhury
Os unit 2Os unit 2
Os unit 2
Arnav Chowdhury516 visualizações
Os unit 3 por SandhyaTatekalva
Os unit 3Os unit 3
Os unit 3
SandhyaTatekalva667 visualizações
Memory management Assignment Help por JosephErin
Memory management Assignment HelpMemory management Assignment Help
Memory management Assignment Help
JosephErin467 visualizações
Opetating System Memory management por Johan Granados Montero
Opetating System Memory managementOpetating System Memory management
Opetating System Memory management
Johan Granados Montero2.6K visualizações
Operating system Memory management por Shashank Asthana
Operating system Memory management Operating system Memory management
Operating system Memory management
Shashank Asthana4.2K visualizações
Chapter 8 - Main Memory por Wayne Jones Jnr
Chapter 8 - Main MemoryChapter 8 - Main Memory
Chapter 8 - Main Memory
Wayne Jones Jnr9.4K visualizações
Ch8 por tech2click
Ch8Ch8
Ch8
tech2click1.2K visualizações
virtual memory por Abeer Naskar
virtual memoryvirtual memory
virtual memory
Abeer Naskar1.2K visualizações
Memory Management por sangrampatil81
Memory ManagementMemory Management
Memory Management
sangrampatil8175 visualizações
Bab 4 por n k
Bab 4Bab 4
Bab 4
n k969 visualizações
Operating system por Hussain Ahmady
Operating systemOperating system
Operating system
Hussain Ahmady189 visualizações
Virtual Memory Management por Rahul Jamwal
Virtual Memory ManagementVirtual Memory Management
Virtual Memory Management
Rahul Jamwal150 visualizações

Último

Career Building in AI - Technologies, Trends and Opportunities por
Career Building in AI - Technologies, Trends and OpportunitiesCareer Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and OpportunitiesWebStackAcademy
51 visualizações44 slides
Peripheral artery diseases by Dr. Garvit.pptx por
Peripheral artery diseases by Dr. Garvit.pptxPeripheral artery diseases by Dr. Garvit.pptx
Peripheral artery diseases by Dr. Garvit.pptxgarvitnanecha
135 visualizações48 slides
Introduction to Physiotherapy and Electrotherapy por
Introduction to Physiotherapy and ElectrotherapyIntroduction to Physiotherapy and Electrotherapy
Introduction to Physiotherapy and ElectrotherapySreeraj S R
67 visualizações10 slides
DISTILLATION.pptx por
DISTILLATION.pptxDISTILLATION.pptx
DISTILLATION.pptxAnupkumar Sharma
82 visualizações47 slides
Introduction to AERO Supply Chain - #BEAERO Trainning program por
Introduction to AERO Supply Chain  - #BEAERO Trainning programIntroduction to AERO Supply Chain  - #BEAERO Trainning program
Introduction to AERO Supply Chain - #BEAERO Trainning programGuennoun Wajih
135 visualizações78 slides
What is Digital Transformation? por
What is Digital Transformation?What is Digital Transformation?
What is Digital Transformation?Mark Brown
46 visualizações11 slides

Último(20)

Career Building in AI - Technologies, Trends and Opportunities por WebStackAcademy
Career Building in AI - Technologies, Trends and OpportunitiesCareer Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and Opportunities
WebStackAcademy51 visualizações
Peripheral artery diseases by Dr. Garvit.pptx por garvitnanecha
Peripheral artery diseases by Dr. Garvit.pptxPeripheral artery diseases by Dr. Garvit.pptx
Peripheral artery diseases by Dr. Garvit.pptx
garvitnanecha135 visualizações
Introduction to Physiotherapy and Electrotherapy por Sreeraj S R
Introduction to Physiotherapy and ElectrotherapyIntroduction to Physiotherapy and Electrotherapy
Introduction to Physiotherapy and Electrotherapy
Sreeraj S R67 visualizações
DISTILLATION.pptx por Anupkumar Sharma
DISTILLATION.pptxDISTILLATION.pptx
DISTILLATION.pptx
Anupkumar Sharma82 visualizações
Introduction to AERO Supply Chain - #BEAERO Trainning program por Guennoun Wajih
Introduction to AERO Supply Chain  - #BEAERO Trainning programIntroduction to AERO Supply Chain  - #BEAERO Trainning program
Introduction to AERO Supply Chain - #BEAERO Trainning program
Guennoun Wajih135 visualizações
What is Digital Transformation? por Mark Brown
What is Digital Transformation?What is Digital Transformation?
What is Digital Transformation?
Mark Brown46 visualizações
JRN 362 - Lecture Twenty-Two por Rich Hanley
JRN 362 - Lecture Twenty-TwoJRN 362 - Lecture Twenty-Two
JRN 362 - Lecture Twenty-Two
Rich Hanley39 visualizações
Women From 1850 To 1950 Essay por Amy Williams
Women From 1850 To 1950 EssayWomen From 1850 To 1950 Essay
Women From 1850 To 1950 Essay
Amy Williams39 visualizações
GSoC 2024 .pdf por ShabNaz2
GSoC 2024 .pdfGSoC 2024 .pdf
GSoC 2024 .pdf
ShabNaz245 visualizações
Education of marginalized and socially disadvantages segments.pptx por GarimaBhati5
Education of marginalized and socially disadvantages segments.pptxEducation of marginalized and socially disadvantages segments.pptx
Education of marginalized and socially disadvantages segments.pptx
GarimaBhati552 visualizações
STRATEGIC MANAGEMENT MODULE 1_UNIT1 _UNIT2.pdf por Dr Vijay Vishwakarma
STRATEGIC MANAGEMENT MODULE 1_UNIT1 _UNIT2.pdfSTRATEGIC MANAGEMENT MODULE 1_UNIT1 _UNIT2.pdf
STRATEGIC MANAGEMENT MODULE 1_UNIT1 _UNIT2.pdf
Dr Vijay Vishwakarma136 visualizações
Presentation_NC_Future now 2006.pdf por Lora
Presentation_NC_Future now 2006.pdfPresentation_NC_Future now 2006.pdf
Presentation_NC_Future now 2006.pdf
Lora 38 visualizações
MercerJesse3.0.pdf por jessemercerail
MercerJesse3.0.pdfMercerJesse3.0.pdf
MercerJesse3.0.pdf
jessemercerail183 visualizações
PRELIMS ANSWER.pptx por souravkrpodder
PRELIMS ANSWER.pptxPRELIMS ANSWER.pptx
PRELIMS ANSWER.pptx
souravkrpodder56 visualizações
Geology of Ethiopia and the Horn Chapter 2 GeES 1011.pptx por behailugetu
Geology of Ethiopia and the Horn Chapter 2 GeES 1011.pptxGeology of Ethiopia and the Horn Chapter 2 GeES 1011.pptx
Geology of Ethiopia and the Horn Chapter 2 GeES 1011.pptx
behailugetu36 visualizações
BUSINESS ETHICS UNIT II.pdf por Dr Vijay Vishwakarma
BUSINESS ETHICS UNIT II.pdfBUSINESS ETHICS UNIT II.pdf
BUSINESS ETHICS UNIT II.pdf
Dr Vijay Vishwakarma38 visualizações
Research Methodology (M. Pharm, IIIrd Sem.)_UNIT_IV_CPCSEA Guidelines for Lab... por RAHUL PAL
Research Methodology (M. Pharm, IIIrd Sem.)_UNIT_IV_CPCSEA Guidelines for Lab...Research Methodology (M. Pharm, IIIrd Sem.)_UNIT_IV_CPCSEA Guidelines for Lab...
Research Methodology (M. Pharm, IIIrd Sem.)_UNIT_IV_CPCSEA Guidelines for Lab...
RAHUL PAL45 visualizações
Meet the Bible por Steve Thomason
Meet the BibleMeet the Bible
Meet the Bible
Steve Thomason83 visualizações

Memory management

  • 1. Operating System-Memory Management by Vishal Singh (Vishalchd11@yahoo.com)
  • 2. Why Memory management ? 1. To ensure protection of different processes from each other (so that they do not interfere with each other’s operations). 2. To place the programs in memory (such that memory is utilized to its fullest extent.
  • 3. Logical vs. physical address space ► A logical address is the address of an instruction or data as used by a program. ► A physical address is the effective memory address of an instruction or data i.e. it is the address obtained after binding of logical addresses has been done.
  • 5. Relocation register ► Relocation register is a special register in the CPU used for program relocation means mapping of logical addresses used by the program to physical addresses of the system’s main memory
  • 6. Storage Allocation and Management Techniques The Storage allocation can be of two types: (i) Contiguous storage allocation. (ii) Non-contiguous storage allocation.
  • 7. Contiguous Storage Allocation ► Contiguous storage allocation implies that a program’s data and instructions are assured to occupy a single contiguous memory area. ► It is further subdivided into Fixed-partition storage allocation strategy and variable- partition storage allocation strategy.
  • 8. 1. Fixed-partition contiguous storage allocation ► processes with small address space use small partitions and processes with large address space use large partitions. This is known as fixed partition contiguous storage allocation.
  • 10. 2. Variable - partition contiguous storage allocation This notion is derived from parking of vehicles on the sides of streets where the one who manages to enter will get the space. Two vehicles can leave a space between them that cannot be used by any vehicle. This means that whenever a process needs memory, a search for the space needed by it, is done. If contiguous space is available to accommodate that process, then the process is loaded into memory.
  • 11. External Fragmentation ► This phenomenon of entering and leaving the memory can cause the formation of unusable memory holes (like the unused space between two vehicles). This is known as External Fragmentation.
  • 12. Three strategies that can be used to allocate memory to Variable - partition They are the following: 1. Best - Fit 2. Worst - fit 3. First - fit
  • 13. Best - Fit - chooses a partition that is smallest and whose size is greater than equal to k. It leaves small-sized unusable partitions or holes.
  • 14. First - fit - chooses the first partition whose size is greater than equal to k.
  • 15. Worst - fit - chooses the largest partition and allocates it to process p. It can leave bigger unusable partitions.
  • 16. Compaction means to move the processes in the memory in such a way that scattered pieces of unused (free) memory can be placed together so that any other process demanding contiguous memory for it can use it.
  • 17. Non-contiguous Storage Allocation ► To resolve the problem of external fragmentation and to enhance the degree of multiprogramming to a greater extent, it was decided to sacrifice the simplicity of allocating contiguous memory to every process. It was decided to have a non-contiguous physical address space of a process so that a process could be allocated memory wherever it was available.
  • 18. Non-contiguous Storage Allocation There are 2 techniques for non-contiguous allocation: 1. Paging 2. Segmentation
  • 19. 1. Paging ► In this approach,physical memory is divided into fixed-size blocks called frames and the logical memory is divided into the fixed-sized blocks called pages. The size of a page is same as that of frame. The key idea of this method is to place the pages of a process into the available frames of memory, whenever, this process is to be executed. The address mapping is done by Page table.
  • 21. It works as: Translate logical address 13 = 01101 in binary Offset = 01 in binary or 1 in decimal Page no. = 011 in binary or 3 in decimal Physical address = pageframe*pagesize + offset i.e. 2*4+1 = 9 (which is the real address of page containing character “n” in the main memory)
  • 22. Problem with paging ► It uses a page table per process for translating logical to physical address space. A basic issue associated with the use of page table is, that the look up in the page table should be very fast (which is generally slow), as it is done on every memory reference. ► So to make the look up time less, caching is used. In this case, the specific cache device is called a translation look aside buffer (TLB).
  • 23. Translation look aside buffer (TLB). ► The TLB contains a set of entries, each of which contains a page number, the corresponding frame number, and the protection bits. ► So if we use TLB, then mapping is done by TLB and we generally find the entry in TLB but in case the entry is not found in TLB than we have a TLB miss and finally we go to page table.
  • 24. Segmentation ► segmentation is another technique for the noncontiguous storage allocation. It is different from paging as it supports users’ view of his program. ► For a programmer it might be more relevant to divide the logical address space of his program into variable sized segments (with respect to his view of main program, subroutines, data, etc.) than to divide it into fixed size pages. Such variable sized segments, which are a collection of logically related information, are the basis of segmentation technique.
  • 26. Virtual Memory ► Virtual memory is a technique of executing program instructions that may not fit entirely in system memory. This is done by calling instructions as and when the application requires it. Virtual memory is implemented by using secondary storage to augment the main memory. Data is transferred from secondary to main storage as and when necessary and the data modified is written back to the secondary storage according to a predetermined algorithm.
  • 27. Swapping ► Swapping is the technique of temporarily removing inactive programs from the main memory of a computer system. An inactive program is one that is neither executing nor performing an I/O operation. ► This may also happen when it is desired to place a higher-priority process in the memory. A lower priority process may be swapped out so that higher-priority process may be loaded and executed.
  • 29. Demand Paging ► In virtual memory system, demand paging is a type of swapping in which pages of programs are not copied from disk to main memory until they are needed for execution. ► In demand paging, virtual address (logical address) is accessed by CPU, the corresponding page number is looked up in the page table and if it shows that currently this page is not in main memory, then this page must be brought into the main-memory.
  • 30. ► A page fault occurs when an invalid page is addressed. Page fault must be followed by swapping-in the page (demanded just now by the CPU) from disk to main-memory or a trap should be generated to the operating system if the page being demanded is not within the logical address space of the process. To determine whether the reference to the requested page is within the logical address space or not, an internal table may be consulted
  • 33. Pure Demand Paging ► Pure demand paging is the form of demand paging in which not even a single page is loaded into memory, initially. Thus, the very first instruction causes a page fault in this case. This kind of demand paging may significantly decrease the performance of a computer system by generally increasing the effective access time of memory.
  • 34. Page Replacement ► Once the main memory fills up, a page must be swapped out to make room for any pages to be swapped in. This is known as page replacement. ► We have page replacement algorithms for page replacement purpose, which are as follows:
  • 35. 1. The optimal page replacement algorithm 2. The first-in, first-out (FIFO) page replacement algorithm 3. The second chance page replacement algorithm 4. The least recently used (LRU) page replacement algorithm 5. Simulating LRU in Software (Not frequently used algorithm) 6. The Working Set Page Replacement Algorithm