<<

Chapter 4 and Asst.Prof.Dr. Supakit Nootyaskool IT-KMITL Object

• To discuss the principle of memory management.

• To understand the reason that memory partitions are importance for system organization.

• To describe the concept of Paging and Segmentation. 4.1 Difference in main memory in the system • The uniprogramming system (example in DOS) allows only a program to be present in memory at a time. All resources are provided to a program at a time. Example in a memory has a program and an OS running 1) (on Kernel space) 2) A running program (on space)

• The multiprogramming system is difference from the mentioned above by allowing programs to be present in memory at a time. All resource must be organize and sharing to programs. Example by two programs are in the memory . 1) Operating system (on Kernel space) 2) Running programs (on + running) 3) Programs are waiting signals to execute in CPU (on User space).

The multiprogramming system uses memory management to organize location to the programs 4.2 Memory management terms

Frame

Segment 4.2 Memory management terms

Frame Page

A fixed-lengthSegment of main memory. 4.2 Memory management terms

Frame Page

A fixed-length block of data that resides in secondary memory. A page of data may temporarily beSegment copied into a frame of main memory. A variable-lengthMemory management block of data that residesterms in secondary memory. A segment may temporarily be copied into an available region of main memory or the segment may be divided into pages which can be individuallyFrame copied into mainPage memory.

Segment The region of program

0x001

0xFFF 4.3 Memory management requirements • The various mechanisms and policies associated with memory management, including the following: Protection Sharing Logical organization Physical organization The main memory 4.3.1 Protection without a memory management Program ------Data • for other ------Stack processes should not be able to reference memory Program ------locations in a for Data reading or writing purposes ------Stack without permission.

• Memory referenced Program generated by a program must ------Data be checked at runtime. ------Stack 4.3.2 Relocation Program ------Data • Relocation is adjustment ------reference addresses in a Stack process to match a new location in main memory. Program • Example, a process requests ------a large data area. Data 1) A process is saved to disk ------Stack 2) Loading the process from disk to place in a new location in main memory. 4.3.3 Sharing Program ------Data • Allowing the processes to ------Stack access the same portion of Program main memory ------Data ------Stack

Program ------Data ------Stack 4.3.4-5 Logical & Physical Organization

• Physical organization is Program ------referential address in Data main memory or disk in ------real value as physical Disk Stack structure of the system. Program • Logical organization is ------referential address in Physical Data organization ------the main memory or Stack the disk by converting OS/ from a logical value, App which specific address Logical Program does not similar to organization ------physical structure of Data the system. ------Stack 4.4 Memory management terms

Fixed Dynamic Simple paging partitioning partitioning

Virtual Virtual Simple Memory Paging Segmentation 4.4.1 Fixed Partitioning

Two kinds of fixed partitioning 1) Dividing area in the memory in equal-sized partitions

2) Dividing area in the memory in unequal-sized partitions 4.4.1 Fixed Partitioning

Disadvantages 1) Number of running 7MB processes in the 7MB memory are 7MB limited. Example, 7MB three process use 7MB 7MB/each 7MB 2) No efficient space utilization. Example 12M-7M = 4M free 4.4.2 Dynamic Partitioning • Applications moving in/out the free space will be divided to small areas, which called Fragmentation • OS must shift processes to reduce the fragmentation that spends CPU time.

f

f f 4.4.2 Dynamic Partitioning • Partition area in the memory as the process requires. Example, P1 requires 20M, P2 requires 14M, and P3 require 18M Why is the relocation process spending

CPU time? Program ------Data ------Stack

Program ------Data ------Stack

Program ------Data ------Stack 4.4.3 Paging • It is logical organization by dividing all memory to be small part (fix sized) and assign number of each memory part called Frame number.

• A program running on memory must be divided into each frame.

• A program may be not placed closely frame number Windows– Checking page size

#include #include int main(void) { SYSTEM_INFO si; GetSystemInfo(&si); printf("The page size for this system is %u .\n", si.dwPageSize); return 0; } – Checking page size

#include #include /* sysconf(3) */ int main(void) { printf("The page size for this system is %ld bytes.\n", sysconf(_SC_PAGESIZE)); /* _SC_PAGE_SIZE is OK too. */

return 0; } Page sizes among architectures Architecture Smallest page size Larger page sizes 4 MiB in PSE mode, 2 MiB in 32-bit [18] 4 KiB PAE mode[19] 2 MiB, 1 GiB (only when the x86-64[18] 4 KiB CPU has PDPE1GB flag) 8 KiB, 64 KiB, 256 KiB, 1 MiB, IA-64 ()[20] 4 KiB 4 MiB, 16 MiB, 256 MiB[19] Power Architecture[21] 4KiB 64KiB, 16MiB, 16GiB SPARC v8 with SPARC 4 KiB 256 KiB, 16 MiB Reference MMU[22] 64 KiB, 512 KiB (optional), UltraSPARC Architecture 4 MiB, 32 MiB (optional), 8 KiB 2007[23] 256 MiB (optional), 2 GiB (optional), 16 GiB (optional) 64 KiB, 1 MiB ("section"), 16 MiB ("supersection") ARMv7[24] 4 KiB (defined by a particular implementation)

in page/segment

Segment uses concept similar to page but the segment is unequal-sized dividing the memory. Convert from Logical address to -- Paging Convert from Logical address to Physical address -- Segment 4.4.4 Virtual

Simple Paging Virtual Memory Paging - All the page of a - Not all the page of a process need to be in process must be in main memory for main memory for process to run. Page process to run, unless may be read in as need. overlays are used. - Reading a page into main memory may require writing a page out to disk. 4.4.5 Virtual Memory Paging

Simple Paging Virtual Memory Paging - All paging must be stored in - All paging store in both main main memory. memory and a disk. - Which part of paging need to process will be removed to paging area in main memory. 4.4.5 Virtual Memory Segmentation

Simple Segmentation Virtual Memory Segmentation - All segments must be stored - Segments store in both main in main memory. memory and a disk - Which part of segment need to process will be removed to segment area in main memory. Address translation—Paging system Address translation -- Segmentation Summary