简体   繁体   中英

Getting size of the page table for a system with a tiny amount of memory, only a few total pages

I'm asked to make a Page Table inside Memory under these conditions.

  1. We have 16 bits Virtual Address
  2. Memory size is 512 words
  3. page size is 128 Bytes

So I tried doing this :

  1. 2^16 / 2^7 = 2^9 Pages
  2. 2^9 * 4 = 2^11 Bytes = 2KB Page Table Size, assuming each entry is 4 Bytes.

So the problem is here : main Memory is 512 words = 2048Bytes = 2KB, that means the whole memory is Page Table, Am I right? if not, could you please tell what I did wrong here?

This system has either 8 or 16 pages, depending on the definition of word. Usually, on a 16-bit system, word = 2 bytes, not 4, so I'm going to assume that is the case, but YMMV. This would mean that main memory is 1KB (not 2KB).

Yet because there are only 8 pages, that means that a normal page table entry would only need a few bits (physical page number is 0-7, so that's 3 bits), so likely at most one byte per virtual page — maybe even as small as a nibble (half byte), which would mean that you need 512 nibbles, eg 256 bytes.

However, even that would be a massive waste of the limited physical memory, if even a small TLB is present. I would redesign the page table array in reverse (and this is called an inverted page table , which is like an extension of the TLB in software).

Normally, the page table is indexed by the virtual page number, and the element at each index holds the physical page number for that index. This means theoretical O(1) access to the page table entry given virtual address.

Reversing that would mean that the table is indexed by the physical page number, which makes the entire table only 8 entries long in total! Such a table cannot be indexed by virtual page number, but it can be searched, and as there's only 8 entries to search, that's not a big search — so on average we have O(4), which is the effectively same as O(1). Probably each entry is two bytes large, holding a virtual page number (9 bits) and some status bits (there's 7 bits left in 2 bytes for status).

And as I mentioned, if there's even a small TLB, this arrangement would make for compact page table storage, while incurring a small search cost on TLB miss.

Ideally, if the TLB had 8 entries, that would be sufficient to map virtual addresses for all addresses that have physical pages, and a TLB miss on a valid virtual memory access would also indicate a page miss/fault.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM