Question

I am reading Modern Operating Systems 3rd Edition by A.S Tanenbaum, and I've come to the chapter on virtual memory management. I've been stuck on a part for some time now, and I can't get my head around it. Either, it's a typo in the book, or I have misunderstood something.

Suppose we have a multi-level page table with two levels, where we map 32-bit virtual addresses to physical memory frames.

The fields for the page tables and the offset is

10 | 10 | 12

meaning we have a top level page table with 1024 entries, and a page size of 4096 bytes or 4KB. Entry 0 of the top level page table points to the text segment page table, entry 1 to the data segment, and the 1023 entry to the stack page table.

This is quoted from the book:

As an example, consider the 32-bit virtual address 0x00403004 (4,206,596 decimal), which is 12,292 bytes into the data. This virtual address corresponds to PT 1 = 1, PT2 = 2, and Offset = 4. The MMU first uses PT1 to index into the top-level page table and obtain entry 1, which corresponds to addresses 4M to 8M. It then uses PT2 to index into the second-level page table just found and extract entry 3, which corresponds to addresses 12288 to 16383 within its 4M chunk (i.e., absolute addresses 4,206,592 to 4,210,687).

When I translate the address to binary, I get 0000000001|0000000011|000000000100 which for me corresponds to PT1 = 1, PT2 = 3, Offset = 4.

  1. Am I missing something, or is this a typo in the book stating PT2 = 2, when it actually should be PT2 = 3? As the text later says, the MMU uses the PT2 index to extract entry 3.
  2. Where does the "12,292 bytes into the data" come from? How is that derived from the virtual address? I understand it has something to do with the offset, but I can't figure out how it's done. As far as I have understood, the physical address is derived as a combination of the frame number from the second page table, and the offset. I see that the 12,292 is a result of 3*4096+4 (PT2 entry * page size + offset). Is this correct?
Was it helpful?

Solution

1) I think this is a typo indeed, as 0000000001|0000000011|000000000100 binary = 4,206,596 decimal

2) The response is in the previous paragraph of the book :

Entry 0 of the top-level page table points to the page table for the program text, entry 1 points to the page table for the data, and entry 1023 points to the page table for the stack

So he is just saying that 0000000001|0000000011|000000000100 corresponds to 0000000011|000000000100 into the data. Indeed 0000000001 corresponds to the data in the top level page table, and 0000000011|000000000100 binary = 12,292 decimal.

OTHER TIPS

I didn't finish converting to binary out of despair and a little bit laziness but its clearer now thanks to you. Seeing it made things much more clear.

  1. it is a typo as the previous answerer stated. its without a doubt (Check US 4th edition)

  2. "12,292 bytes into the data" comes from substracting 222 (4MB) (Toplevel Page table entry size=4MB) from 4206596

TLDR: 4206596 - 222 (4MB) = 12,292

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top