mbox series

[v6,0/2] Memory poison recovery in khugepaged collapsing

Message ID 20221107025359.2911028-1-jiaqiyan@google.com (mailing list archive)
Headers show
Series Memory poison recovery in khugepaged collapsing | expand

Message

Jiaqi Yan Nov. 7, 2022, 2:53 a.m. UTC
Problem
=======
Memory DIMMs are subject to multi-bit flips, i.e. memory errors.
As memory size and density increase, the chances of and number of
memory errors increase. The increasing size and density of server
RAM in the data center and cloud have shown increased uncorrectable
memory errors. There are already mechanisms in the kernel to recover
from uncorrectable memory errors. This series of patches provides
the recovery mechanism for the particular kernel agent khugepaged
when it collapses memory pages.

Impact
======
The main reason we chose to make khugepaged collapsing tolerant of
memory failures was its high possibility of accessing poisoned memory
while performing functionally optional compaction actions.
Standard applications typically don't have strict requirements on
the size of its pages. So they are given 4K pages by the kernel.
The kernel is able to improve application performance by either

  1) giving applications 2M pages to begin with, or
  2) collapsing 4K pages into 2M pages when possible.

This collapsing operation is done by khugepaged, a kernel agent that
is constantly scanning memory. When collapsing 4K pages into a 2M page,
it must copy the data from the 4K pages into a physically contiguous
2M page. Therefore, as long as there exists one poisoned cache line in
collapsible 4K pages, khugepaged will eventually access it. The current
impact to users is a machine check exception triggered kernel panic.
However, khugepaged’s compaction operations are not functionally required
kernel actions. Therefore making khugepaged tolerant to poisoned memory
will greatly improve user experience.

This patch series is for cases where khugepaged is the first guy
that detects the memory errors on the poisoned pages. IOW, the pages
are not known to have memory errors when khugepaged collapsing gets to
them. In our observation, this happens frequently when the huge page
ratio of the system is relatively low, which is fairly common in
virtual machines running on cloud.

Solution
========
As stated before, it is less desirable to crash the system only because
khugepaged accesses poisoned pages while it is collapsing 4K pages.
The high level idea of this patch series is to skip the group of pages
(usually 512 4K-size pages) once khugepaged finds one of them is poisoned,
as these pages have become ineligible to be collapsed.

We are also careful to unwind operations khuagepaged has performed before
it detects memory failures. For example, before copying and collapsing
a group of anonymous pages into a huge page, the source pages will be
isolated and their page table is unlinked from their PMD. These operations
need to be undone in order to ensure these pages are not changed/lost from
the perspective of other threads (both user and kernel space). As for
file backed memory pages, there already exists a rollback case. This
patch just extends it so that khugepaged also correctly rolls back when
it fails to copy poisoned 4K pages.

Changelog
=========

v6 changes
- Address comments from Kirill Shutemov <kirill@shutemov.name>
- Rewrite __collapse_huge_page_copy to make rollback operations more
  clear to its reader.
- Add detailed test steps in each commit message.

v5 changes
- Rebase patches to mm-unstable at
  commit ffb39098bf87 ("Merge tag 'linux-kselftest-kunit-6.1-rc1' of
  git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest").
- Resolves conflicts with:
  commit 2f55f070e5b8 ("mm/khugepaged: minor cleanup for collapse_file")
  commit 1baec203b77c ("mm/khugepaged: try to free transhuge swapcache
  when possible")

v4 changes
- Incorporate feedbacks from Yang Shi <shy828301@gmail.com>
- Remove tracepoint for __collapse_huge_page_copy, just keep SCAN_COPY_MC
  and let trace_mm_collapse_huge_page it
- Remove unnecessary comments

v3 changes
- Incorporate feedbacks from Yang Shi <shy828301@gmail.com>
- Add tracepoint for __collapse_huge_page_copy
- Restore PMD in collapse_huge_page
- Correct comment about mmap_read_lock

v2 changes
- Incorporate feedbacks from Yang Shi <shy828301@gmail.com>
- Only keep copy_highpage_mc
- Adding new scan_result SCAN_COPY_MC
- Defer NR_FILE_THPS update until copying succeeded

Jiaqi Yan (2):
  mm/khugepaged: recover from poisoned anonymous memory
  mm/khugepaged: recover from poisoned file-backed memory

 include/linux/highmem.h            |  19 +++
 include/trace/events/huge_memory.h |   3 +-
 mm/khugepaged.c                    | 233 ++++++++++++++++++++---------
 3 files changed, 183 insertions(+), 72 deletions(-)

Comments

Andrew Morton Nov. 7, 2022, 8:53 p.m. UTC | #1
On Sun,  6 Nov 2022 18:53:57 -0800 Jiaqi Yan <jiaqiyan@google.com> wrote:

> Memory DIMMs are subject to multi-bit flips, i.e. memory errors.
> As memory size and density increase, the chances of and number of
> memory errors increase. The increasing size and density of server
> RAM in the data center and cloud have shown increased uncorrectable
> memory errors. There are already mechanisms in the kernel to recover
> from uncorrectable memory errors. This series of patches provides
> the recovery mechanism for the particular kernel agent khugepaged
> when it collapses memory pages.

Thanks, I'll toss v6 into mm-unstable for some testing, pending further review.

When resending a patchset, please try to also cc the people who have
commented on previous versions.
Jiaqi Yan Nov. 16, 2022, 5:58 p.m. UTC | #2
Thanks for ccing Oscar, Andrew.

After getting this patch into our internal production environment, I
recently found a regression bug introduced by my commit a0157a2c735b
("mm/khugepaged: recover from poisoned file-backed memory").
Given it is only in mm-unstable, I wonder should I put out a v7 with
the fix, or should I make it a new and separate commit?
Sorry for the bug.


On Mon, Nov 7, 2022 at 12:53 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Sun,  6 Nov 2022 18:53:57 -0800 Jiaqi Yan <jiaqiyan@google.com> wrote:
>
> > Memory DIMMs are subject to multi-bit flips, i.e. memory errors.
> > As memory size and density increase, the chances of and number of
> > memory errors increase. The increasing size and density of server
> > RAM in the data center and cloud have shown increased uncorrectable
> > memory errors. There are already mechanisms in the kernel to recover
> > from uncorrectable memory errors. This series of patches provides
> > the recovery mechanism for the particular kernel agent khugepaged
> > when it collapses memory pages.
>
> Thanks, I'll toss v6 into mm-unstable for some testing, pending further review.
>
> When resending a patchset, please try to also cc the people who have
> commented on previous versions.
>
Andrew Morton Nov. 16, 2022, 9:52 p.m. UTC | #3
On Wed, 16 Nov 2022 09:58:23 -0800 Jiaqi Yan <jiaqiyan@google.com> wrote:

> Thanks for ccing Oscar, Andrew.
> 
> After getting this patch into our internal production environment, I
> recently found a regression bug introduced by my commit a0157a2c735b
> ("mm/khugepaged: recover from poisoned file-backed memory").
> Given it is only in mm-unstable, I wonder should I put out a v7 with
> the fix, or should I make it a new and separate commit?

Either approach is OK.  I usually convert replacement patches into
deltas so I and others can see what changed.  But people like to see
the whole patch for review purposes, so I guess that if you email out a
new version of the patch, we get to see both.
Jiaqi Yan Nov. 18, 2022, 1:34 a.m. UTC | #4
On Wed, Nov 16, 2022 at 1:52 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Wed, 16 Nov 2022 09:58:23 -0800 Jiaqi Yan <jiaqiyan@google.com> wrote:
>
> > Thanks for ccing Oscar, Andrew.
> >
> > After getting this patch into our internal production environment, I
> > recently found a regression bug introduced by my commit a0157a2c735b
> > ("mm/khugepaged: recover from poisoned file-backed memory").
> > Given it is only in mm-unstable, I wonder should I put out a v7 with
> > the fix, or should I make it a new and separate commit?
>
> Either approach is OK.  I usually convert replacement patches into
> deltas so I and others can see what changed.  But people like to see
> the whole patch for review purposes, so I guess that if you email out a
> new version of the patch, we get to see both.
>
>

Thanks Andrew. I just sent out v7 with the fix.