· web viewmemory hierarchy. in cpu the memory organisation is performed as->one process uses...

19
MEMORY HIERARCHY In CPU the Memory Organisation is performed as- >One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically allocated. Memory is divided as - Main Memory /Primary Memory(RAM/ROM) -stores only currently instructions data -relatively Expensive -relatively small capacity -High performance -requires careful management Secondary Memory (disk) -stores actively needed data -cheap -large capacity -slow Cache memory -present in processor -stores present data that has to be accessed

Upload: others

Post on 02-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically

MEMORY HIERARCHY

In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically allocated.

Memory is divided as -Main Memory /Primary Memory(RAM/ROM)-stores only currently instructions data-relatively Expensive-relatively small capacity-High performance-requires careful managementSecondary Memory (disk)-stores actively needed data-cheap-large capacity-slowCache memory-present in processor-stores present data that has to be accessed

Page 2:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically

MEMORY MAMAGEMENT STRATEGIES

1)FETCH Strategies->It demands the data & decides which piece of data to load next in the memory managemet.2)PLACEMENT Strategies->It decides where in main memory to store the fetched data.3)REPLACEMENT Strategies->It decides which data to remove(Unwanted data)from main memory to make more space.

Memory Allocation Techniques Ways of organizing prog. In memory-

The Main memory must accommodate both OS & user processes, hence we need to allocate memory (main) in best (most efficient) possible way-Main memory is usually partitioned into 2 parts: OS & USER processes (Fixed / Variable)

We usually want several processes to reside in the memory at the same time. We therefore need to consider how to allocate available memory to the processes that are in the input queue waiting to be brought into memory

Page 3:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically

CONTIGUOUS Memory Allocation-Program/process as a unit is completely stored-In Contiguous memory allocation, each process is contained in single section of memory that is contiguous to the section containing the next process.- It is a classical memory allocation model that assigns a process consecutive memory blocks ( memory blocks having consecutive addresses).-The program must exist as a single block of contiguous (sequence)address.-Sometimes it is impossible to find large enough block ie difficult to find space.-Low overhead problem may occur.- Centralized in nature-Implemented with the help of Partitioning method-eg : arrayADVANTAGE-Address translation & access will be very easy.DISADAVNTAGE-It will always suffer from external fragmentation ie sometime process may requore a space which is in total available but still cannot be allocated because it is not available contiguously.

NON-CONTIGOUS Memory Allocation-Programs are distributed in memory-The program is divided into chunks called segments.-Each segment can be placed in different parts of memory.-Easier to find “holes” (free space) in which segments will fit.-Overhead problem can be solved here.-Decentralized in nature-Implemented with the help of -Paging / Segementation / Virtual memory -eg : linked listADVANTAGE-It is Independent of external fragementation.DISADVANTAGE-Access will be very slow (linear pattern to access large part).

Page 4:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically

Memory PROTECTIONSuppose we have 2 different kinds of processes- OS & User Area-Then protection means that User should not be able to access or interfere with the OS memory areaIt is implemented with the help of FENCE ADDRESSAfter verifying fence address if it is found that the process is illegal & it is trying to access htat OS Area than that request will be terminated.User Area Process can’t use other process memory location

CPU will generate address for any processThat address is compared with the fence addressDECISION MAKING BLOCKIf CPU generated address >= Fence address Then it is allowed to access the Physical MemoryOtherwise Trap or Error state will generate

Suppose ---OS: 0-499Fence address:500-1000 (500 say)CPU :600 address generatedSo 600>500 it is allowed to access the Physical Memory

This is how Fence Address is used to provide protection in the memory managementIt is basically a concept that seprates the OS Area with User Area.

BASE & LIMIT REGISTERS

P1 should not access memory of P2 & vice versa…Base + Limit = Relocation Register

Each process has a seprate address space.Protection can be achieved using a base register & a limit registerOnly the operating system( in Kernel) mode can set the base & limit registersIf the CPU requests an absolute memory location M, the hardware verifies that Base<= M < base+limitOtherwise If this is not a case the hardware generates a trap to Operating System

Page 5:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically
Page 6:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically

MEMORY PARTITIONINGIt is a simple method which is used as contiguous memory allocation in Operating SystemMemory is divided into 2 parts - Resident OS / User

Partitioning:1)FIXED : Multiprogramming with fixed tasks (MFT)2)VARIABLE : Multiprogramming with variable tasks (MVT)

M.F.T (Multiprogramming with fixed tasks)

When one process try to access the memory space of another process for this there is a protection mechanism-LBR: (Lower Bound Register) – minimum address that a process can accessUBR: (Upper Bound Register) – maximum address that a process can accessFor a process : LBR <Memory< UBL

Drawbacks:

Page 7:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically
Page 8:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically

FRAGMENTATIONFragmentation occurs in a dynamic memory allocation system when most of the free blocks are too small to satisfy any request. It is generally termed as inability to use the available memory.

Page 9:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically

EXTERNAL FRAGEMENTATION INTERNAL FRAGEMENTATION

In such situation processes are loaded and removed from the memory. As a result of this, free holes exists to satisfy a request but is non contiguous i.e. the memory is fragmented into large no. Of small holes. This phenomenon is known as External Fragmentation.

Also, at times the physical memory is broken into fixed size blocks and memory is allocated in unit of block sizes. The memory allocated to a space may be slightly larger than the requested memory. The difference between allocated and required memory is known as Internal fragmentation i.e. the memory that is internal to a partition but is of no use.

Arises when unable to accomodate a process of size even we have sufficient size of memory but it is not contiguous

Total memory space is enough to stasify a request but is non contiguous so it cannot be used.

Arises when a process of size smaller than allocated partition is placed that partition, that leaves behind small amount of unused memory.

Memory block assigned to process is bigger. Some portion of memory is left unused as it cannot be used by another process.

The unused spaces formed b/w non contiguous memory fragments are too small to serve a new process. This is called external fragmentation.

The diff b/w memory allocated & required memory is called Internal Fragmentation.

It occurs when a Dynamic Memory Allocation technique is used.

It occurs when a Fixed Size Memory Allocation technique is used.

It refers to the unused memory blocks that are too small to handle a request.

It occurs when main memory is divided into fixed size blocks regardless of the size of the process.

It can be prevented by mechanisms such as segmentation & paging. Here a logical contiguous virtual space is given while in reality the files are spiltted into parts & placed here & there.

It can be prevented by allocating memory to process dynamically. (having partitions of several sizes & assigning a program based on best fit) However still it is not fully eliminated.

Page 10:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically

M.V.T

The no. of partitions that are created depends upon the jobs/processes to be executed.As there is No unused partition spaceThere is no Internal Fragmentation in M.V.T since the partitions are not decided earlier.But there may be a chance of External Fragmentation.

Page 11:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically

PAGING A solution to fragmentation problem is Paging. Paging is a memory management mechanism that allows the physical address space of a process to be non-contagious. Here physical memory is divided into blocks of equal size called Pages. The pages belonging to a certain process are loaded into available memory frames.

There is no External Fragmentation but there is a chance of Internal Fragmentation Maximum Internal fragmentation in any frame = (P-1) P = page sizeSuppose the size of the page is 10, process request to access memory 14:Logical Address = (frame no, offset)

Page TableA Page Table is the data structure used by a virtual memory system in a computer operating system to store the mapping between virtual address and physical addresses. There is a mapping ie Page table that maps which page no. is stored at which frame

Virtual address is also known as Logical address and is generated by the CPU. While Physical address is the address that actually exists on memory.

Page 12:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically

Logical Address generated by CPU is divided into-

Page Number (p) Page offset (d)No. of bits required to represent the pages in Logical Address space

No. of bits required to represent particular word in a page / page size of Logical Address Space

Physical Address is divided into-

Frame Number (f) Frame offset (d)No. of bits required to represent the frame of physical Address Space

No. of bits required to represent particular word in a Frame / Frame size of Logical Address Space

CPU will generate Logical Address into 2 diff parts – p (Page Number) & d (Page offset)Then that p (Page Number) is checked in the page mapped table containing page no. & corresponding frame no. From this the corresponding frame no. is find out – we add d (Page offset) in Frame Number (f). Hence we get our desired physical address.

Page 13:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically

TLB = h/w cache memory containing very few page table entries (frequently used)Using this Page table to frame mapping time is reduced.

Page 14:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically

Segmentation

Segmentation is another memory management scheme that supports the user-view of memory. Segmentation allows breaking of the virtual address space of a single process into segments that may be placed in non-contiguous areas of physical memory.

If d<limit => add ‘d’ to base address

Page 15:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically

Segmentation with PagingBoth paging and segmentation have their advantages and disadvantages, it is better to combine these two schemes to improve on each. The combined scheme is known as 'Page the Elements'. Each segment in this scheme is divided into pages and each segment is maintained in a page table. So the logical address is divided into following 3 parts : Segment numbers(S) / Page number (P)/The displacement or offset number (D)

Page 16:  · Web viewMEMORY HIERARCHY. In CPU the Memory Organisation is performed as->One Process uses entire memory space >Each process gets its own partition in memory Dynamically or Statically