Sie sind auf Seite 1von 3

11/6/2016

Piazza Question on the last question on HW#7 on Virtual memory

How does OS build the multi-level page table?


In the last question of HW 7, how do we assume that the OS builds the page table? As 8 bits are
allocated for indexing the first level page table, does the OS in the beginning itself allocate the 256 entry
table in main memory to keep the page table or does it incrementally allocate the words on growing page
table size?
Similarly, what about the second level tables and third level tables etc? Is it built incrementally for entry by
entry? Or even if there is one entry in the second level table, it allocates memory for all 256 entries
(assuming 8 bits indexing of second level table)?

Short answer:
>> does the OS in the beginning itself allocate the 256 entry table in main memory
Yes, the A table (which is one and the only top-level table) is built at the invocation of the program or
process as a full 256-entry table by the OS.
>> entry-by-entry?
No entry-by-entry at all. B-level tables are built as 256-entry tables and C-level tables are built as 16-entry
tables.

Detailed answer continued on next two pages ==============

Lengthy explanation:
OS is not a VLSI engineer to build tables location by location. It allocates memory space in the MM
for the table(s) and places pointer(s) or PPFN(s) in the entries of the tables. It does a little of this at
the invocation of the process and the rest is done on demand. All these tables are indexable (and
are not searched). Recall the Full-Length table discussion in our lecture. So it is never location by
location. We said that, if a new student joins USC and if he is from NY (New York state), then the
campus police will have to start (a little unwillingly) an entire 10***6 (1 million)-entry table because of
him. Imagine if his SSN is 000-99-9999. Using the 000 you go to the State Table (the 1st level table)
and pick up the pointer to the NY table and index it using 99-9999 to find his student ID. And the 999999 is the last location of the million entry table. So the Campus Police does not have an option to
build a 1-entry or a few-entry NY-table. It has to be a million-entry table even though only one NYstudent has joined USC.
Before and after the NY student joins USC:

When a process is invoked for the first time, the OS creates the top-level table of 256 entries
together with one 2nd level table of 256 entries and one third level table of 16-entries is created. Let
us assume that the very first page the code of that process has VPN = 75-76-8 (one of the 16 VPNs
given in the question). Then at the location 75 Hex in the top-level table, there will be a pointer to the
second level table. Using the pointer we can go to the 2nd level table and index it with the 2nd field of
the VPN namely 76 hex and find the pointer to the 3rd level table. Now using the 3rd field of the VPN,
namely 8, we index the 3rd level table to find the PPFN of the very first page of the code of the
program. And let us assume that the OS (who manages the main memory) has chosen to place this
PPF (Physical Page Frame) at FEDCB000 Hex (= meaning the PPFN is FEDCB). Then you will find
FEDCB as the content of the location 8 (entry 8) of the third-level table.

After the process is invoked, as the programs data and instruction accesses cause page faults, the
OS brings these pages into the MM. Depending on the Virtual Addresses (and their VPNs) of these
instruction and data accesses, the OS may have to build more 3rd level tables and more 2nd level
tables. A new 3rd level table may be built alone but if a new 2nd level table is built, then a new 3rd
level table is also necessarily built!

If a second student from NY joins USC, the Campus Police do not have to build another table. If
there is a jump instruction in the beginning of the code to the Virtual Address 74-76-9-420, then a
new code page needs to be brought as 74-76-9 is a different VPN. But no new table needs to be
formed as the PPFN for this VPN needs to be paced in the 9th entry of the 3rd level table.
But next, let us say the program accesses a data at A2-F5-6-894. Then page fault occurs and the
OS brings the data page corresponding to the A2-F5-6 and places it in the MM say at the physical
address FEDCC000 Hex. Then OS needs to build a 2nd level table and a 3rd level table, fill the entry
A2 in the top level table with a pointer to this new 2nd level table and fill the entry F5 in this new 2nd
level table with a pointer to the new 3rd level table, and fill the entry 6 in the new third level table with
the PPFN of the data page FEDCC.

Das könnte Ihnen auch gefallen