From: Peter Xu <peterx@redhat.com>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Cc: Andrea Arcangeli <aarcange@redhat.com>,
Andi Kleen <andi.kleen@intel.com>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@redhat.com>,
Hugh Dickins <hughd@google.com>,
Huang Ying <ying.huang@intel.com>,
peterx@redhat.com, Nadav Amit <nadav.amit@gmail.com>,
"Kirill A . Shutemov" <kirill@shutemov.name>,
Vlastimil Babka <vbabka@suse.cz>
Subject: [PATCH 0/2] mm: Remember young bit for migration entries
Date: Tue, 2 Aug 2022 21:21:57 -0400 [thread overview]
Message-ID: <20220803012159.36551-1-peterx@redhat.com> (raw)
rfc->v1:
- Fix build for arch/um where MAX_PHYSMEM_BITS not defined [syzbot]
- Add VM_BUG_ON() in swp_offset_pfn() to check swap entry type [Ying]
- Use max_swapfile_size() to detect swp offset size [Ying]
- Posted patch 3 separately, dropped patch 4
rfc: https://lore.kernel.org/all/20220729014041.21292-1-peterx@redhat.com/
Problem
=======
When migrate a page, right now we always mark the migrated page as old.
The reason could be that we don't really know whether the page is hot or
cold, so we could have taken it a default negative assuming that's safer.
However that could lead to at least two problems:
(1) We lost the real hot/cold information while we could have persisted.
That information shouldn't change even if the backing page is changed
after the migration,
(2) There can be always extra overhead on the immediate next access to
any migrated page, because hardware MMU needs cycles to set the young
bit again (as long as the MMU supports).
Many of the recent upstream works showed that (2) is not something trivial
and actually very measurable. In my test case, reading 1G chunk of memory
- jumping in page size intervals - could take 99ms just because of the
extra setting on the young bit on a generic x86_64 system, comparing to 4ms
if young set.
This issue is originally reported by Andrea Arcangeli.
Solution
========
To solve this problem, this patchset tries to remember the young bit in the
migration entries and carry it over when recovering the ptes.
We have the chance to do so because in many systems the swap offset is not
really fully used. Migration entries use swp offset to store PFN only,
while the PFN is normally not as large as swp offset and normally smaller.
It means we do have some free bits in swp offset that we can use to store
things like young, and that's how this series tried to approach this
problem.
max_swapfile_size() is used here to detect per-arch offset length in swp
entries. We'll automatically remember the young bit when we find that we
have enough swp offset field to keep both the PFN and the young bit for a
migration entry.
Tests
=====
After the patchset applied, the immediate read access test [1] of above 1G
chunk after migration can shrink from 99ms to 4ms. The test is done by
moving 1G pages from node 0->1->0 then read it in page size jumps. The
test is with Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz.
Patch Layout
============
Patch 1: Add swp_offset_pfn() and apply to all pfn swap entries, we should
also stop treating swp_offset() as PFN anymore because it can
contain more information starting from next patch.
Patch 2: The core patch to remember young bit in swap offsets.
Please review, thanks.
[1] https://github.com/xzpeter/clibs/blob/master/misc/swap-young.c
Peter Xu (2):
mm/swap: Add swp_offset_pfn() to fetch PFN from swap entry
mm: Remember young bit for page migrations
arch/arm64/mm/hugetlbpage.c | 2 +-
include/linux/swapops.h | 84 ++++++++++++++++++++++++++++++++++---
mm/hmm.c | 2 +-
mm/huge_memory.c | 10 ++++-
mm/memory-failure.c | 2 +-
mm/migrate.c | 4 +-
mm/migrate_device.c | 2 +
mm/page_vma_mapped.c | 6 +--
mm/rmap.c | 3 +-
9 files changed, 99 insertions(+), 16 deletions(-)
--
2.32.0
next reply other threads:[~2022-08-03 1:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-03 1:21 Peter Xu [this message]
2022-08-03 1:21 ` [PATCH 1/2] mm/swap: Add swp_offset_pfn() to fetch PFN from swap entry Peter Xu
2022-08-03 1:21 ` [PATCH 2/2] mm: Remember young bit for page migrations Peter Xu
2022-08-03 7:42 ` Nadav Amit
2022-08-03 16:45 ` Peter Xu
2022-08-04 6:42 ` Nadav Amit
2022-08-04 17:07 ` Peter Xu
2022-08-04 17:16 ` Nadav Amit
2022-08-03 12:21 ` kernel test robot
2022-08-03 21:47 ` Peter Xu
2022-08-03 13:53 ` kernel test robot
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=20220803012159.36551-1-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=andi.kleen@intel.com \
--cc=david@redhat.com \
--cc=hughd@google.com \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nadav.amit@gmail.com \
--cc=vbabka@suse.cz \
--cc=ying.huang@intel.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).