From patchwork Tue Apr 5 20:51:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 12801948 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 363CAC433EF for ; Tue, 5 Apr 2022 20:52:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5F166B0072; Tue, 5 Apr 2022 16:52:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A3EF26B0073; Tue, 5 Apr 2022 16:52:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FC5E6B0074; Tue, 5 Apr 2022 16:52:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 7FB896B0072 for ; Tue, 5 Apr 2022 16:52:01 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 49E5861B1A for ; Tue, 5 Apr 2022 20:51:51 +0000 (UTC) X-FDA: 79324022022.14.AA2E8DE Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf05.hostedemail.com (Postfix) with ESMTP id D0BC0100036 for ; Tue, 5 Apr 2022 20:51:50 +0000 (UTC) Received: by mail-pl1-f201.google.com with SMTP id v11-20020a170902f0cb00b00156b1cc7040so62337pla.23 for ; Tue, 05 Apr 2022 13:51:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=Lc5n02VyOtbn7aZtDJrCHNimzOIGMXs2iHZBy4nbQiE=; b=UKeE72AuDWnhW0gaFHf8NdWonXu5r5PnGYFyIHSKKYgkVxFpJqG6tXnVmXfQ5xGjZK v/3+S0ibbPs/uySImHDr6mciPNsfkIiQU/7TpUW8pWWxImt0zHbpMktMXGQRKZvOeIne 63sWEBkmyszXQ15uj7GiGxJ1H9ny9fhoCMjN5xIaF+AtU9Alqgs7ewcoEwIIMiC4xkZS KEPZk67QjYQclS8rCaNo+TXYesiniCtn7C/mgSt6URbl+E7AelKZTvYrF3GkTpQ1RMrK i1yL52fv1jAliRJvzufCBaEHuLba5pAqfkS1ELjOfmzyLvfsv0VE/ANrFJKaHV74nLet p+gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=Lc5n02VyOtbn7aZtDJrCHNimzOIGMXs2iHZBy4nbQiE=; b=ga7WmlhNf0U8owTlVTjwGKuS+fhwmgcw9RRBLqzjlf4PNosrtNJ7SVxes+sMN59bFD s81J0r9hveG1w8sLWu2AN9X0EjDrx3ezD68/BsV6xKsNxaFavNxhRikEBxeaVskF/Phl AAfAEkdc9tSju6Cb9OXFK6OslLM/vJRhGBmfr4wEy96RVqcUUp0tS+DNOQ7vI2Yx46WI iFD+dxvwtynI8/VwkzU0FnLcNrcSz7K+3qaWdlRW5380Dh6NXWq7K7yzdsk+dHkXebeM MH4oAkHvVl834or76GgFEcCBRjCJ4VpW/NiYfXARjTsQWDG8fdAPeUpm8ZvRKYxMOeNh I7JA== X-Gm-Message-State: AOAM531V21u+ZjFYqP1P81vyRW3C+i5eAZQEQw+C72HVcCV15J6qxJHL 1Dads0eA/aiXlTYJH0qdo9EW1rG6M34Etw== X-Google-Smtp-Source: ABdhPJwZFKk+Ms9OUL/APma9wOsMUikScVBf1UBj3EemewzX115DNE1I8Gi6G7W+TkAQi0qPYSldlw2bgcI8ew== X-Received: from yjqkernel.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1837]) (user=jiaqiyan job=sendgmr) by 2002:a17:903:22ca:b0:14c:d9cf:a463 with SMTP id y10-20020a17090322ca00b0014cd9cfa463mr5589717plg.32.1649191909911; Tue, 05 Apr 2022 13:51:49 -0700 (PDT) Date: Tue, 5 Apr 2022 13:51:44 -0700 Message-Id: <20220405205146.411595-1-jiaqiyan@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [RFC v2 0/2] Memory poison recovery in khugepaged collapsing From: Jiaqi Yan To: shy828301@gmail.com, tongtiangen@huawei.com Cc: tony.luck@intel.com, naoya.horiguchi@nec.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, juew@google.com, jiaqiyan@google.com, linux-mm@kvack.org Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=UKeE72Au; spf=pass (imf05.hostedemail.com: domain of 35atMYggKCIgvum2uAmzs00sxq.o0yxuz69-yyw7mow.03s@flex--jiaqiyan.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=35atMYggKCIgvum2uAmzs00sxq.o0yxuz69-yyw7mow.03s@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: nhrjazeio65986c3s1rykkrw33tntidx X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D0BC0100036 X-HE-Tag: 1649191910-421963 X-Bogosity: Ham, tests=bogofilter, spamicity=0.380946, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 application 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. Jiaqi Yan (2): mm: khugepaged: recover from poisoned anonymous memory mm: khugepaged: recover from poisoned file-backed memory include/linux/highmem.h | 18 ++++ mm/khugepaged.c | 215 ++++++++++++++++++++++++++++------------ 2 files changed, 171 insertions(+), 62 deletions(-)