All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gregory Price <gregory.price@memverge.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
	naoya.horiguchi@linux.dev
Subject: Re: [PATCH v14 08/39] mm/swap: Add folio_mark_accessed()
Date: Fri, 13 Oct 2023 12:38:21 -0400	[thread overview]
Message-ID: <ZSlyfdXsW0bmxb0T@memverge.com> (raw)
In-Reply-To: <ZSWTD1sgbM/LUKch@casper.infradead.org>

On Tue, Oct 10, 2023 at 07:08:15PM +0100, Matthew Wilcox wrote:
> On Sun, Oct 08, 2023 at 11:34:45AM -0400, Gregory Price wrote:
> > a) Should we update kpageflags_read to use page_folio() and get the
> >    folio flags for the head page
> > 
> > or
> > 
> > b) the above change to mark_page_accessed() should mark both the
> >    individual page flags to accessed as well as the folio head accessed.
> 
> Hi Greg, thanks for reaching out.
> 
> The referenced bit has been tracked on what is now known as a per-folio
> basis since commit 8cb38fabb6bc in 2016.  That is, if you tried to
> SetPageReferenced / ClearPageReferenced / test PageReferenced on a tail
> page, it would redirect to the head page in order to set/clear/test
> the bit in the head page's flags field.
> 
> That's not to say that all the code which sets/checks/tests this
> really understands that!  We've definitely found bugs during the folio
> work where code has mistakenly assumed that operations on a tail
> page actually affect that page rather than the whole allocation.
> 
> There's also code which is now being exposed to compound pages for the
> first time, and is not holding up well.
> 
> I hope that's helpful in finding the bug you're chasing.
> 

ah, very interesting.  So the kpageflags code doesn't appear to respect
flag locations defined in 8cb38fabb6bc

We tested this hack of a patch which swaps the page flags for the folio
head flags according to the flag locations defined in page-flags.h.

The result was that the referenced bit was almost *never* set on an
anonymous pages, no matter where we look, even when we have a program
constantly touching every page in a large chunk of memory.

Head scratcher.

Thank you for the response.  We're still very much confused, but it
looks like there are potentially many problems (unless we're
misunderstanding the reference bit).

(cc Naoya since I saw you were actively working on kpageflags for folio
 support not sure what else you're seeing).

~Gregory


diff --git a/fs/proc/page.c b/fs/proc/page.c
index 195b077c0fac..8022a41d7899 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -110,6 +110,7 @@ static inline u64 kpf_copy_bit(u64 kflags, int ubit, int kbit)
 u64 stable_page_flags(struct page *page)
 {
        u64 k;
+       u64 fh;
        u64 u;

        /*
@@ -119,7 +120,7 @@ u64 stable_page_flags(struct page *page)
        if (!page)
                return 1 << KPF_NOPAGE;

-       k = page->flags;
+       fh = *folio_flags(page_folio(folio), 0);
        u = 0;

        /*
@@ -188,20 +189,20 @@ u64 stable_page_flags(struct page *page)
                u |= 1 << KPF_SLAB;

        u |= kpf_copy_bit(k, KPF_ERROR,         PG_error);
-       u |= kpf_copy_bit(k, KPF_DIRTY,         PG_dirty);
+       u |= kpf_copy_bit(fh, KPF_DIRTY,        PG_dirty);
        u |= kpf_copy_bit(k, KPF_UPTODATE,      PG_uptodate);
        u |= kpf_copy_bit(k, KPF_WRITEBACK,     PG_writeback);

-       u |= kpf_copy_bit(k, KPF_LRU,           PG_lru);
-       u |= kpf_copy_bit(k, KPF_REFERENCED,    PG_referenced);
-       u |= kpf_copy_bit(k, KPF_ACTIVE,        PG_active);
+       u |= kpf_copy_bit(fh, KPF_LRU,          PG_lru);
+       u |= kpf_copy_bit(fh, KPF_REFERENCED,   PG_referenced);
+       u |= kpf_copy_bit(fh, KPF_ACTIVE,       PG_active);
        u |= kpf_copy_bit(k, KPF_RECLAIM,       PG_reclaim);

        if (PageSwapCache(page))
                u |= 1 << KPF_SWAPCACHE;
        u |= kpf_copy_bit(k, KPF_SWAPBACKED,    PG_swapbacked);

-       u |= kpf_copy_bit(k, KPF_UNEVICTABLE,   PG_unevictable);
+       u |= kpf_copy_bit(fh, KPF_UNEVICTABLE,  PG_unevictable);
        u |= kpf_copy_bit(k, KPF_MLOCKED,       PG_mlocked);

 #ifdef CONFIG_MEMORY_FAILURE


  reply	other threads:[~2023-10-13 16:38 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15 19:59 [PATCH v14c 00/39] Memory folios: Pagecache edition Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 01/39] mm: Add folio_pfn() Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 02/39] mm: Add folio_raw_mapping() Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 03/39] mm: Add flush_dcache_folio() Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 04/39] mm: Add kmap_local_folio() Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 05/39] mm: Add arch_make_folio_accessible() Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 06/39] mm: Add folio_young and folio_idle Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 07/39] mm/swap: Add folio_activate() Matthew Wilcox (Oracle)
2021-07-15 19:59 ` [PATCH v14 08/39] mm/swap: Add folio_mark_accessed() Matthew Wilcox (Oracle)
2023-10-08 15:34   ` Gregory Price
2023-10-10 18:08     ` Matthew Wilcox
2023-10-13 16:38       ` Gregory Price [this message]
2021-07-15 20:00 ` [PATCH v14 09/39] mm/rmap: Add folio_mkclean() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 10/39] mm/migrate: Add folio_migrate_mapping() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 11/39] mm/migrate: Add folio_migrate_flags() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 12/39] mm/migrate: Add folio_migrate_copy() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 13/39] mm/writeback: Rename __add_wb_stat() to wb_stat_mod() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 14/39] flex_proportions: Allow N events instead of 1 Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 15/39] mm/writeback: Change __wb_writeout_inc() to __wb_writeout_add() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 16/39] mm/writeback: Add __folio_end_writeback() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 17/39] mm/writeback: Add folio_start_writeback() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 18/39] mm/writeback: Add folio_mark_dirty() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 19/39] mm/writeback: Add __folio_mark_dirty() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 20/39] mm/writeback: Convert tracing writeback_page_template to folios Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 21/39] mm/writeback: Add filemap_dirty_folio() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 22/39] mm/writeback: Add folio_account_cleaned() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 23/39] mm/writeback: Add folio_cancel_dirty() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 24/39] mm/writeback: Add folio_clear_dirty_for_io() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 25/39] mm/writeback: Add folio_account_redirty() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 26/39] mm/writeback: Add folio_redirty_for_writepage() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 27/39] mm/filemap: Add i_blocks_per_folio() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 28/39] mm/filemap: Add folio_mkwrite_check_truncate() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 29/39] mm/filemap: Add readahead_folio() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 30/39] mm/workingset: Convert workingset_refault() to take a folio Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 31/39] mm: Add folio_evictable() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 32/39] mm/lru: Convert __pagevec_lru_add_fn to take a folio Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 33/39] mm/lru: Add folio_add_lru() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 34/39] mm/page_alloc: Add folio allocation functions Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 35/39] mm/filemap: Add filemap_alloc_folio Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 36/39] mm/filemap: Add filemap_add_folio() Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 37/39] mm/filemap: Convert mapping_get_entry to return a folio Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 38/39] mm/filemap: Add filemap_get_folio Matthew Wilcox (Oracle)
2021-07-15 20:00 ` [PATCH v14 39/39] mm/filemap: Add FGP_STABLE Matthew Wilcox (Oracle)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZSlyfdXsW0bmxb0T@memverge.com \
    --to=gregory.price@memverge.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=naoya.horiguchi@linux.dev \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.