Idle THPs
As part of the folio work, I'm looking at PageIdle and PageYoung and they're defined to operate on PF_ANY. So, for example, in pagecache_get_page(), we will call clear_page_idle() on the head page (actually, I changed this in a8cf7f272b5a -- before, it would call clear_page_idle() on the tail page).
However, we never actually call set_page_idle() on tail pages. This is because we only call it here:
page = page_idle_get_page(pfn);
if (page) {
page_idle_clear_pte_refs(page);
set_page_idle(page);
put_page(page);
}where page_idle_get_page() does:
struct page *page = pfn_to_online_page(pfn);
if (!page || !PageLRU(page) ||
!get_page_unless_zero(page))
return NULL;get_page_unless_zero() will always fail for tail pages (as it uses page_ref_add_unless(), which does not redirect to the head page's refcount). So all tail pages read back as !idle in page_idle_bitmap_read(). Is this intended? Should they rather mirror the state of their head page?
From: SeongJae Park <[email protected]>
Quoted 24 lines · On Thu, 10 Jun 2021 04:43:18 +0100 Matthew Wilcox <[email protected]> wrote:
As part of the folio work, I'm looking at PageIdle and PageYoung and they're defined to operate on
PF_ANY. So, for example, inpagecache_get_page(), we will callclear_page_idle()on the head page (actually, I changed this ina8cf7f272b5a-- before, it would callclear_page_idle()on the tail page).However, we never actually call
set_page_idle()on tail pages. This is because we only call it here:page = page_idle_get_page(pfn); if (page) { page_idle_clear_pte_refs(page); set_page_idle(page); put_page(page); }where
page_idle_get_page()does:struct page *page = pfn_to_online_page(pfn); if (!page || !PageLRU(page) || !get_page_unless_zero(page)) return NULL;
Quoted 5 lines
get_page_unless_zero()will always fail for tail pages (as it usespage_ref_add_unless(), which does not redirect to the head page's refcount). So all tail pages read back as !idle inpage_idle_bitmap_read(). Is this intended? Should they rather mirror the state of their head page?
I think this is an intended behavior, as the document[1] says as below:
For huge pages the idle flag is set only on the head page, so one has to read /proc/kpageflags in order to correctly count idle huge pages.
[1] https://www.kernel.org/doc/html/latest/admin-guide/mm/idle_page_tracking.html
Thanks,
SeongJae Park
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): CAHbLzkrznNBhGHZCN-Pf=1tUK+9Ad0TEXkC_fwDNcjceDt3vuw@mail.gmail.com
+Yu Zhao
Quoted 29 lines · Yang Shi
Quoted 27 lines · Hugh Dickins
Quoted 24 lines · Matthew Wilcox
As part of the folio work, I'm looking at PageIdle and PageYoung and they're defined to operate on
PF_ANY. So, for example, inpagecache_get_page(), we will callclear_page_idle()on the head page (actually, I changed this ina8cf7f272b5a-- before, it would callclear_page_idle()on the tail page).However, we never actually call
set_page_idle()on tail pages. This is because we only call it here:page = page_idle_get_page(pfn); if (page) { page_idle_clear_pte_refs(page); set_page_idle(page); put_page(page); }where
page_idle_get_page()does:struct page *page = pfn_to_online_page(pfn); if (!page || !PageLRU(page) || !get_page_unless_zero(page)) return NULL;
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
get_page_unless_zero()will always fail for tail pages (as it usespage_ref_add_unless(), which does not redirect to the head page's refcount). So all tail pages read back as !idle inpage_idle_bitmap_read(). Is this intended? Should they rather mirror the state of their head page?
From what I understand the idle bitmap is supposed to be used along with /proc/kpageflags. So, the users should skip tail pages for setting/getting the idle bits.
Quoted 19 lines
Quoted 12 lines
Good point.
I bet when I made that no-lru_lock cleanup in
page_idle_get_page(), I was expecting the PageLRU to fail on tail, soget_page_unless_zero()irrelevant; but apparently PageLRU isPF_HEADredirecting to head. Either way, yes, it will return NULL on tail, which may not be right.But maybe the physical scan works out okay with all the action happening on the head (Kirill got that to scan the tails in pvmw), then skipping the tails in the local scan.
Quoted 6 lines
I'm not a
page_idleuser and don't want to get into the mechanics of it. Seems to be largely in maintenance mode these days, maybe nobody cares.Yang Shi was the last to make a real mod there,
f0849ac0b8e0("mm: thp: fix potential clearing to referenced flag inpage_idle_clear_pte_refs_one()"):
likely he will know best.
Quoted 8 lines
It was more than 3 years ago :-)
Since the whole THP is considered referenced if any one of sub page is referenced, so IMHO the tail page should mirror the state of their head page.
And AFAIK Google uses the idle flag to reclaim memory proactively, but it is an out-of-tree feature. Loop Shakeel in this thread.
We are not directly using upstream idle page infrastructure but surgically using the parts we need. Yu can provide more details.
Quoted 3 lines
Quoted 3 lines
Hugh