Search code examples
memory-managementoperating-systemcpu-architecturevirtual-memorytlb

About TLB entries and Page table entries


From a website about TLB: (https://www.bottomupcs.com/virtual_memory_hardware.xhtml#other-page-related-faults):

For the following parts I highlighted:

1: Is the format of TLB entries the same as PTE(page table entries)? And it's not clear
the "the page" in the page can be marked as mean TLB entry or PTE?

2: For "the pages" in go through all the pages, are they TLB entries or PTEs?

3: Why it's moved out of not "moved into"?

4: Is that the order is (1)set the two bits (2)put into TLB, or the converse?

There are two other important faults that the TLB can generally generate which help to mange accessed and dirty pages. Each page generally contains an attribute in the form of a single bit which flags if the page has been accessed or is dirty.

An accessed page is simply any page that has been accessed. 1When a page translation is initially loaded into the TLB the page can be marked as having been accessed (else why were you loading it in?[19])

2The operating system can periodically go through all the pages and clear the accessed bit to get an idea of what pages are currently in use. When system memory becomes full and it comes time for the operating system to choose pages to be swapped out to disk, obviously those pages whose accessed bit has not been reset are the best candidates for removal, because they have not been used the longest.

A dirty page is one that has data written to it, and so does not match any data already on disk. For example, if a page is loaded in from swap and then written to by a process, 3before it can be moved out of swap it needs to have its on disk copy updated. A page that is clean has had no changes, so we do not need the overhead of copying the page back to disk.

Both are similar in that they help the operating system to manage pages. The general concept is that a page has two extra bits; the dirty bit and the accessed bit. 4When the page is put into the TLB, these bits are set to indicate that the CPU should raise a fault.

When a process tries to reference memory, the hardware does the usual translation process. However, it also does an extra check to see if the accessed flag is not set. If so, it raises a fault to the operating system, which should set the bit and allow the process to continue. Similarly if the hardware detects that it is writing to a page that does not have the dirty bit set, it will raise a fault for the operating system to mark the page as dirty.


Solution

  • I suggest ignoring that link as a source. It is highly confusing. I do not see any mention of a specific implementation but it is clearly describing one.

    In any rationally designed processor, the TLB is completely transparent to programmers (even systems programmers). It is entirely a piece of hardware.

    1: Is the format of TLB entries the same as PTE(page table entries)?

    A programmer never sees TLB entries. They could have the same format as PTEs. They might not.

    2: For "the pages" in go through all the pages, are they TLB entries or PTEs?

    Programmers have no access to TLB entries. They have to refer to PTEs.

    3: Why it's moved out of not "moved into"?

    Probably but there seems to be a lot of confusion in your link.

    4: Is that the order is (1)set the two bits (2)put into TLB, or the converse?

    This is describing some specific, unnamed implementation. Most processors have a dirty bit but not all have an accessed bit.