next up previous contents
Next: Physical and Virtual Addressing Up: An Abstract Model of Previous: Access Control

Making the Model More Efficient

If you were to implement a system using this theoretical model then it would work, but not particularly efficiently. Both operating system and CPU designers try hard to extract more performance from the system. Apart from making the processors, memory and so on faster the best approach is to maintain caches of useful information and data that make some operations faster. Linux uses a number of memory management related caches:

Page Cache
This is used to speed up access to images and data on disk. As pages are read into memory from disk they are cached in the page cache. If they were discarded and then needed again they can quickly be fetched from this cachegif.

Buffer Cache
Pages may contain data buffers being used by the kernel, device drivers and so on. The buffer cache is a look aside list of buffers. If, for example, a device driver needs a 256byte buffer, it is quicker to take a buffer from the buffer cache than to allocate a physical page and then break it up into 256byte buffers.

Swap Cache
    Only written (or dirty) pages are saved in the swap file. So long as these pages are not modified after they have been written to the swap file then the next time the page is swapped out there is no need to write it to the swap file as the page is already in the swap file. Instead the page can simply be discarded. In a heavily swapping system this saves many unnecessary and costly disk operations.

One commonly implemented hardware cache is in the CPU; a cache of Page Table Entries. In this case, the CPU does not read the page table directly but instead caches translations for pages is it needs them. These are the Translation Look-aside Buffers and contain copies of the information kept in the operating system's page table. When the reference to the virtual address is made, the CPU will attempt to find a matching TLB entry. If it finds one, it can directly translate the virtual address into a physical one and perform the correct operation on the data. If the CPU cannot find a matching TLB entry then it must get the operating system to help. It does this by raising an exception. In essence this means signalling the the operating system that a TLB miss has occurred. A system specific mechanism is used to deliver that exception to the operating system code that can fix things up. That code fixes things up by generating a TLB entry for the address mapping. When the exception has been cleared, the CPU will make another attempt to translate the virtual address. This time it will work because there is now a valid entry in the TLB for that address.

The drawback of using caches, hardware or otherwise, is that in order to save effort Linux must use more time and space maintaining these caches and if the caches become corrupted then the system will crash.


next up previous contents
Next: Physical and Virtual Addressing Up: An Abstract Model of Previous: Access Control

David A. Rusling
david.rusling@reo.mts.dec.com