Currently working on arm Xilinx development platforms. Using linux and C.
I mmap some pages. e.g. a = mmap(...)
. I want to know which pages are the least recently used so i can copy them somewhere else.
Currently working on arm Xilinx development platforms. Using linux and C.
I mmap some pages. e.g. a = mmap(...)
. I want to know which pages are the least recently used so i can copy them somewhere else.
The linux kernel itself keeps track of LRU pages, for example, to find out which pages to swap or not to swap out on memory contention.
You can read the LRU flag from userspace if you want to use it in your library:
Now you have several flags, which you can use for your logic:
3. UPTODATE page has up-to-date data
ie. for file backed page: (in-memory data revision >= on-disk one)
4. DIRTY page has been written to, hence contains new data
ie. for file backed page: (in-memory data revision > on-disk one)
8. WRITEBACK page is being synced to disk
[LRU related page flags]
5. LRU page is in one of the LRU lists
6. ACTIVE page is in the active LRU list
18. UNEVICTABLE page is in the unevictable (non-)LRU list
It is somehow pinned and not a candidate for LRU page reclaims,
eg. ramfs pages, shmctl(SHM_LOCK) and mlock() memory segments
2. REFERENCED page has been referenced since last LRU list enqueue/requeue
9. RECLAIM page will be reclaimed soon after its pageout IO completed
11. MMAP a memory mapped page
12. ANON a memory mapped page that is not part of a file
13. SWAPCACHE page is mapped to swap space, ie. has an associated swap entry
14. SWAPBACKED page is backed by swap/RAM
Some more flags are described in this document
There is also a feature called soft-dirty
, which is especially intended for tracking recent writes (reads are ignored) (see the Soft Dirty documentation). You can clear the soft-dirty flags by /proc and read them again through /proc/pid/pagemap. Maybe this comes in handy, too, for your application.
Have you considered using vmstat(8) Report virtual memory statistics ?
vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity. (emphasis mine).
Including:
Field Description For Slab Mode
cache: Cache name num: Number of currently active objects total: Total number of available objects size: Size of each object pages: Number of pages with at least one active object totpages: Total number of allocated pages pslab: Number of pages per slab
Here is a Linux Journal article going into more detail how vmstat
can be used to monitor OS statistics. Here is an excerpt:
Using vmstat
vmstat, as its name suggests, reports virtual memory statistics. It shows how much virtual memory there is, how much is free and paging activity. Most important, you can observe page-ins and page-outs as they happen. This is extremely useful.
To monitor the virtual memory activity on your system, it's best to use vmstat with a delay. A delay is the number of seconds between updates. If you don't supply a delay, vmstat reports the averages since the last boot and quit. Five seconds is the recommended delay interval.
To run vmstat with a five-second delay, type:
vmstat 5