Lab 10 Paging NCHU System Network Lab Paging
Lab 10 Paging NCHU System & Network Lab
Paging • A memory management scheme that permit the physical-address space of a process to be noncontiguous • Physical memory is broken into fixed-sized blocks called frames • Logical memory is also broken into blocks of the same size called pages NCHU System & Network Lab
Paging • Basic method f physical address logical address f 0000. . 0000 d CPU p d f d target cont. f 1111. . 1111 p f page table NCHU System & Network Lab physical memory
Basic method • Address format page number page offset p d m-n n m size of logical address space = 2 m block size = 2 n bytes there are 2 m-n pages NCHU System & Network Lab
Hierarchical Paging logical address p 1 p 2 d outer-page table page of page table NCHU System & Network Lab physical memory
Hierarchical Paging • Address format page number p 1 10 page offset p 2 d 10 12 block size = 4 Kbytes = 212 bytes page of page table size = 1 block size, each entry need 4 bytes=>210 entries 210 * 4 Kbytes = 4 Gbytes (32 -bit machine) NCHU System & Network Lab
fopen #include <stdio. h> FILE *fopen(const char *filename, const char *mode); Mode: r - open for reading w - open for writing (file need not exist) a - open for appending (file need not exist) r+ - open for reading and writing, start at beginning w+ - open for reading and writing (overwrite file) a+ - open for reading and writing (append if file exists) Return : FILE pointer for success, 0 for error. NCHU System & Network Lab
Example • One memory states file – 2000 addresses ( 0 x 000 ~ 0 x 7 d 0 ) – Three frames, 256~511, 768~1023, 1536~1791 have data – Map them to continue logic address 0 x 000~0 x 2 ff • Basic method paging program • Input one logic address • Output physical address and its data NCHU System & Network Lab
Example Graph 000 logical address p d 1 a b 100 256 index 0 1 2 100 300 600 1 ff Phy_addr = 300 + ab page table 300 ab 3 ab content 3 ff 600 frame size = 256 bytes = 28 3 frames => logical address : 000 to 2 ff NCHU System & Network Lab 6 ff 7 d 0 physical memory
Example code NCHU System & Network Lab
Example Result NCHU System & Network Lab
Lab • A program that – use 2 Layer Hierarchical Paging method – one input files (have physical memory states) – frame size = 16 bytes – first layer have 3 entries – second layer need 3 pages, each page has 16 entries – Input logical address – Output physical address and its content NCHU System & Network Lab
Lab Graphzoom out p 1 p 2 d 0 a b 000 a 00 a index 020 0 1 2 000 020 040 000 1 a 0 1 ff 16 entries 300 040 3 ff outer page table 04 f page of page tables 600 1 a 0 16 bytes Phy_addr=1 a 0+00 b zoom out b 1 af 6 ff content NCHU System & Network Lab 7 d 0 physical memory
Reference • Advanced Programming in the UNIX Environment 2 nd Author : Richard Stevens, Stephen A. Rago, Publisher : Addison-Wesley • Beginning Linux Programming Author : Richard Stones, Neil Matthew Publisher : Wrox • Operating System Concepts 6 th edition Author : Abraham Silberschatz, Peter Baer Galvin, Greg Gagne Publisher : John Wiley & Sons, inc. NCHU System & Network Lab
- Slides: 14