23
VIRTUAL VIRTUAL MEMORY MEMORY By By Thi Nguyen Thi Nguyen

VIRTUAL MEMORY

Embed Size (px)

DESCRIPTION

VIRTUAL MEMORY. By Thi Nguyen. Motivation. In early time, the main memory was not large enough to store and execute complex program as higher level languages became popular. In 1961, virtual memory was proposed to solve the problem of storage allocation. Definition. - PowerPoint PPT Presentation

Citation preview

VIRTUAL VIRTUAL MEMORYMEMORY

ByBy

Thi NguyenThi Nguyen

MotivationMotivation

In early time, the main memory was not In early time, the main memory was not large enough to store and execute large enough to store and execute complex program as higher level complex program as higher level languages became popular. languages became popular.

In 1961, virtual memory was proposed to In 1961, virtual memory was proposed to solve the problem of storage allocation.solve the problem of storage allocation.

DefinitionDefinition

Virtual memory is a memory management Virtual memory is a memory management system that gives a computer the system that gives a computer the appearance of having more main memory appearance of having more main memory than it really has.than it really has.

AdvantagesAdvantages

Main memory is used more efficiently. Main memory is used more efficiently. Only those portions of an executing Only those portions of an executing program that are in use occupy main program that are in use occupy main memory.memory.

Programs that are bigger than main Programs that are bigger than main memory can still be executedmemory can still be executed

Implementation of Virtual Implementation of Virtual MemoryMemory

The virtual memory abstraction is The virtual memory abstraction is implemented by using secondary storage implemented by using secondary storage to augment the processor's main memory. to augment the processor's main memory.

Data is transferred from secondary to main Data is transferred from secondary to main storage when necessary and the data storage when necessary and the data replaced is written back to the secondary replaced is written back to the secondary storage. storage.

Implementation of Virtual Implementation of Virtual MemoryMemory

If the data swapped is designated a fixed If the data swapped is designated a fixed size, this swapping is called size, this swapping is called paging.paging.

if variable sizes are permitted and the data if variable sizes are permitted and the data is split along logical lines, it is called is split along logical lines, it is called segmentation.segmentation.

Some operating systems combine Some operating systems combine segmentation and paging. segmentation and paging.

PagingPaging

In a simple paging system view,In a simple paging system view, user programs consists of fixed-length blocks user programs consists of fixed-length blocks

called pages.called pages. Main memory consists of fixed-length blocks Main memory consists of fixed-length blocks

called frames.called frames.

When an operating system loads a user When an operating system loads a user program into memory, it loads each page program into memory, it loads each page into any available frame.into any available frame.

Page TablePage Table

To keep track of the location of each page To keep track of the location of each page in the memory, the operating system in the memory, the operating system builds a one-dimensional array called builds a one-dimensional array called Page Table. Page Table.

Page Page NumberNumber

Frame Frame NumberNumber Valid bitValid bit

00 00 00

11 00 00

22 22 11

33 55 11

• 0 means not in memory

MapperMapper

The mapper is the part of the operating system The mapper is the part of the operating system that translates the logical page number that translates the logical page number generated by the program into the physical page generated by the program into the physical page frame number where the main memory holds the frame number where the main memory holds the page.page.

This translation is accomplished by using page This translation is accomplished by using page table. If the page table reveals that the page is table. If the page table reveals that the page is not resident in the main memory, the mapper not resident in the main memory, the mapper issues a issues a page faultpage fault to the operating system so to the operating system so that execution is suspended on the process until that execution is suspended on the process until the desired page can be read in from the the desired page can be read in from the secondary storage and placed in main memory. secondary storage and placed in main memory.

Page inPage in

The corresponding operation of reading The corresponding operation of reading them in again later when one of the pages them in again later when one of the pages is referenced is called a is referenced is called a page inpage in..

Page outPage out

The operation of writing one inactive page, The operation of writing one inactive page, or a cluster of inactive memory pages to or a cluster of inactive memory pages to disk is called a disk is called a page outpage out..

AdvantagesAdvantages

Paging is effective because programs Paging is effective because programs typically only use a small proportion of typically only use a small proportion of their virtual memory pages actively at any their virtual memory pages actively at any one a time. one a time.

Allows a program that is too big to fit into Allows a program that is too big to fit into memory to be executedmemory to be executed

DisadvantagesDisadvantages

Once the memory is allocated for modules Once the memory is allocated for modules they cannot vary in size. This restriction they cannot vary in size. This restriction results in either wastage or shortage of results in either wastage or shortage of memory.memory.

In paging system, stack is put at the top of In paging system, stack is put at the top of its logical address space; data and code its logical address space; data and code are put at the bottom. The gap between are put at the bottom. The gap between them requires a page table that is too big.them requires a page table that is too big.

SegmentationSegmentation

the program is divided into functional the program is divided into functional segments such as code segment, stack segments such as code segment, stack segment, data segment…segment, data segment…

SegmentationSegmentation

some computer systems have their main some computer systems have their main memory divided into many independent memory divided into many independent address spaces. Each of these address address spaces. Each of these address spaces is called a spaces is called a segmentsegment. The address . The address of each segment begins with 0 and of each segment begins with 0 and segments may be compiled separately. segments may be compiled separately.

SegmentationSegmentation

Each segment in the program can be Each segment in the program can be transferred into segments in main transferred into segments in main memory. However, it may happen that the memory. However, it may happen that the program segment is too big to fit in main program segment is too big to fit in main memory segment. memory segment.

Segmentation with PagingSegmentation with Paging

Some operating systems allow for the Some operating systems allow for the combination of segmentation with paging. combination of segmentation with paging. If the size of a segment exceeds the size If the size of a segment exceeds the size of main memory, the segment may be of main memory, the segment may be divided into equal size pages. divided into equal size pages.

Segmentation with PagingSegmentation with Paging

Each segment has its own page table.Each segment has its own page table. The used gap in the address space would The used gap in the address space would

not be represented by any page table.not be represented by any page table.

Virtual AddressVirtual Address

The address consists of three parts: The address consists of three parts: (1) segment number (1) segment number (2) the page within the segment (2) the page within the segment (3) the offset within the page. (3) the offset within the page.

The segment number is used to find the The segment number is used to find the segment descriptor and the address within segment descriptor and the address within the segment is used to find the page frame the segment is used to find the page frame and the offset within that page. and the offset within that page.

Comparison between Paging and Comparison between Paging and SegmentationSegmentation

SEGMENTATIONSEGMENTATION Involves Involves

programmerprogrammer Separate compilingSeparate compiling Separate Separate

protectionprotection Shared codeShared code

PAGINGPAGING Transparent to Transparent to

programmerprogrammer No separate compilingNo separate compiling No separate protectionNo separate protection No shared codeNo shared code