Permissibility of a memory reference by an instruction can only bechecked at the time of execution of the instruction.

Sharing

Physical Organization

Moving information between the main memory and secondarymemory.

Relocation

Phenomenon by which a process may occupydifferent partitions during the course of its life.

Three types of addresses

Logical Address

Reference to a memory location independent of the currentassignment of the process to memory.

Relative Address

Type of logical address–

address is expressed as a locationrelative to some known point.

Physical Address/ Absolute Addres

Actual location in main memory.

Loading

Absolute Loading

Decision of where to load a module in the memory is made atcompile time.

Thus, a given module is always loaded into a specific location in mainmemory.

Relocatable Loading.

Decision is made at load time.

Thus a module can be loaded anywhere in the main memory.

But, is swapped back to the same memory.

Dynamic Run-Time loading

Decision is made at run-time.

Therefore, we can swap a process image into different locations atdifferent times.

Done by special processor hardware rather than software.

Base Register, Bounds Register, Adder, Comparator.

Memory Management Techniques

Fixed partitioning

Main memory is divided into a number of static partitions atsystem generation time.

Equal-size partitions

Unequal-size partitions

Pros

Simple to implement; little OS overhead

Cons

Inefficient : internal fragmentation

Maximum number of active processes–

fixed.

Placement Algorithm

One process queue per partition.

Single queue.

Fixed partitioning PlacementAlgorithm

Memory Management Techniques

Dynamic partitioning

Partitions are created dynamically

Each process is loaded into a partition of exactly the same size asthat process.

Pros

No internal fragmentation.

Cons

External fragmentation.

Counteract : by compaction.

But an overhead for the processor.

Placement Algorithm : (because compaction is time consuming)

Best-fit

First-fit.

Next-fit.

Dynamic partitioning

Dynamic partitioning

Memory Management Techniques

Paging

Main memory is divided into a number of equal-sized, relativelysmall frames.

Each process is divided into a number of equal-sized pages–

same length as a frame.

A process is loaded by loading all of its pages into availableframes.

Not necessarily be contiguous.

Possible thru the use of a page table for each process.

Logical address (page number, offset)---

Physical Address (framenumber, offset).

Pros

No external fragmentation

Cons

A small amount of internal fragmentation.

Address Translation in a Paging System

Program

Paging

Main Memory

Logical address

Register

Page Table

Page

Frame

Offset

P#

Frame #

Page Table Ptr

Page #

Offset

Frame #

Offset

+

Memory Management Techniques

Segmentation

Each process is divided into number of segments.

Need not be of same size.

A process is loaded by loading all of its segments into dynamicpartitions.

Need not be contiguous

Use segment table.

Difference with dynamic partitioning

A process may occupy more than one partition.

Partitions need not be contiguous.

Pros

No internal fragmentation.

Cons

External fragmentation : though less severe than dynamic partitioningbecause of the small size of the segments.

Hardware support

Base + d

Program

Segmentation

Main Memory

Virtual Address

Register

Segment Table

Segment

d

S#

Length Base

Seg Table Ptr

Seg #

Offset = d

Segment Table

+

+

Memory Management Techniques

Virtual memory

Similar to paging/segmentation except that it is not necessary toload all of the segments/pages of a process into main memory.

Nonresident pages/segments that are needed are brought in laterautomatically.

May require writing a page/segment out to disk if the memory is full.

Pros:

Large virtual address space.

More processes may be maintained in main memory.

A process may be larger than all of main memory.

Cons

Overhead of complex memory management.

Thrashing : The system spends most of its time swapping pieces ratherthan executing instructions.

Translation Lookaside Buffer

Every virtual memory reference causes twophysical memory access:

To fetch the appropriate page table entry.

To fetch the desired data.

Thus, the memory access time is doubled. Toovercome this:

Use a special high-speed cache for page tableentries–

Translation Lookaside Buffer

Similar to a memory cache.

Contains those page table entries–

most recently used.

Use of a Translation Lookaside Buffer

Virtual Memory

Virtual memory can be based on

Paging only

Virtual Address : Page Number + Offset

Page table entry : P(bit)+M(bit)+ Frame Number

Segmentation

Virtual Address : Segment Number + Offset

Segment table entry : P(bit)+M(bit)+ Length + Segment Base

Or, a combination of the two.

Virtual Address : Segment Number + PageNumber + Offset

Segment table entry : Length + Segment Base

Page table entry : P(bit)+M(bit)+ Frame Number

Memory Management in Linux

Linux usesdemand paged virtual memoryfor memorymanagement design.

It's a dynamic memory allocation technique that consists ofdeferring page frame allocation until the last possible moment, forexample, when a process attemps to access a page that is notpresent in RAM.

Basic unit of memory allcation–

page.

Page size : 212

(4096 bytes or 4KB).

Allocationof blocks in physical memory is as page frames

Protectionmechanism is page by page

Sharing isalso based on pages

Swapping controls

automatic movement through the memoryhierarchy.

Getting the Page size

The standard POSIX method

#include <unistd.h>

long sysconf (int name);

long page_size = sysconf(_SC_PAGESIZE);

Linux also provides

int getpagesize (void);

Returns the page size in bytes.

PAGE_SIZE macro

int page_size = PAGE_SIZE

Retrieves the page size at compile time.

Abstract view of memory management

Managing the Virtual Address Space inLinux

Each process : its own virtual address space.

In i386 arch, the virtual address is 32-bits wide.

Therefore, the total virtual memory that a virtual address canreference = 232

= 4GB.

Page Size = 212. Therefore, number of pages that a virtualaddress can reference = 220.

Assuming that each PTE is 4 bytes, how many pages areneeded to store the page table?

Two Level Page Table

The amount of memory devoted to page tables alone isquite high.

Therefore, page tables are stored in virtual memoryrather than main memory. This is achieved thru the useof a two-level hierarchical page table.

Root PageTable (4KB)

User PageTable (4MB)

User AddressSpace (4 GB)

Two-Level Page-Table Scheme

Hierarchical paging

Address translation scheme:

Virtual-> physical address translation

……is a three level process in Linux

Virtual address

4 parts:



Page directory offsetj.pgd



Page middle director offsetj.pmd



Page table offsetj.pte



Offset within pagej.offset

The physical address i for a virtual address jis :

i = PTE(PMD(PGD(j.pgd)+j.pmd)+j.pte)+j.offset.

•The x86(32-bit addressing) only supports a two level conversion of the address.

•This is dictated by the hardware’s MMU…

•This is accomplished by reducing each page middle directory to only asingle entry.

Segmentation in Linux

Linux uses the segmentation model in a limited way.

Each virtual address space is divided intotwo

segments:

User segment (3Gb)

to contain the applications code anddata. Addressable by the user.

Unmapped virtual addresses are simply not used.

Kernel segment (1Gb)

permanently mapped and associatedwith fixed physical memory addresses used by the kernel.