You can use the Access Flag (
AF bit) to track whether a region covered by the translation table entry has been accessed. You can set the
AF bit to:
AF=0. Region not accessed.
AF=1. Region accessed.
This is useful for operating systems, as you can use it to identify which pages are not currently being used and as a result could be paged-out (removed from RAM).
Note: The Access Flag is not typically used in a bare-metal environment, and you can generate your tables with the
AF bit pre-set.
Updating the AF bit
AF bit is being used, the translation tables are created with the
AF bit initially clear. As a page is accessed its
AF bit is set. Software can parse the tables checking whether the
AF bits are set or clear. A page with
AF==0 cannot have been accessed and is potentially a better candidate for being paged-out.
There are two ways that the
AF bit can be set on access:
Accessing the page causes a synchronous exception (Access Flag fault). In the exception handler, software is responsible for setting the
AFbit in the relevant translation table entry and returns.
Accessing the page causes hardware to automatically set the
AFbit without needing to generate an exception. This behavior needs to be enabled and was added in Armv8.1-A.
Armv8.1-A introduced the ability for the processor to manage the Dirty state of a block or page. Dirty state records whether the block or page has been written to. This is useful, as if it is paged-out it tells the managing software whether the contents of RAM need to be written out to the storage.
For example, let's consider a text file. The file is initially loaded from disk (Flash or hard drive) into RAM. When it is later removed from memory, the OS needs to know whether the content in RAM is more recent than what is on disk. If the content in RAM is more recent, then the copy on disk needs to be updated. If not, then the copy in RAM can be dropped.
When managing Dirty State is enabled, software initially creates the translation table entry with the Access Permission set to Read-Only and the DBM (Dirty Bit Modifier) bit set. If that page is written to, the hardware automatically updates the Access Permissions to Read-Write.
DBM bit to 1 changes the function of the Access Permission bits (
S2AP), so that instead of recording access permission they record dirty state. This means that when the
DBM bit is set to 1 the access permission bits do not cause access faults.
Note: The same results can be achieved without using the hardware update option. The page would be marked as Read-Only, resulting in an exception (permission fault) on the first write. The exception handler would manually mark the page as read-write and then return. This approach might still be used if software wants to do copy-on-write.