user16468058
user16468058

Reputation:

Page PG_referenced vs PG_active bit?

I was reading about pages and memory allocaitons and found:

PG_referenced and PG_active but it's not clear to me what's the difference at all? I know that PG_active is set when acessing the page and cleared every some time. but how is that different from PG_referenced, how can one be 1 and other be 0 or both share same value?

Upvotes: 2

Views: 929

Answers (2)

wxz
wxz

Reputation: 2546

This is specific to Linux implementation. There are two LRU lists for the page cache that pages jump between: active and inactive. The PG_active bit tells you if the page is currently on the active list or not. Look at this function from mm/swap.c:

/*
 * Mark a page as having seen activity.
 *
 * inactive,unreferenced    ->  inactive,referenced
 * inactive,referenced      ->  active,unreferenced
 * active,unreferenced      ->  active,referenced
 *

void mark_page_accessed(struct page *page)

This function comment explains it well. Any page that needs to be marked as accessed makes a transition from one of those states on the left (e.g. "inactive, unreferenced") to the states on the right (e.g. "inactive, reference"). When an inactive but referenced page is accessed again, it should jump to the active list, have its active bit set, but have its referenced bit cleared.

A page that is active and referenced is safest from being kicked out of memory, whereas inactive unreferenced pages are first in line for being kicked out. The page replacement algorithm will move pages off the active list to the inactive list as needed to keep a certain ratio of pages on each list and to keep a certain amount of free pages available for the OS.

Upvotes: 1

Vishal Deka
Vishal Deka

Reputation: 53

PG_active is set when the page belongs to the active list and cleared when it is in the inactive list. PG_reference is set when the page is referenced regardless of whether it is in the active or inactive list.

Upvotes: 0

Related Questions