From patchwork Thu Dec 1 00:59:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13060863 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 12075C47088 for ; Thu, 1 Dec 2022 00:59:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A4046B0071; Wed, 30 Nov 2022 19:59:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 254076B0073; Wed, 30 Nov 2022 19:59:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11BC16B0074; Wed, 30 Nov 2022 19:59:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 03B6B6B0071 for ; Wed, 30 Nov 2022 19:59:38 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C7765C0143 for ; Thu, 1 Dec 2022 00:59:37 +0000 (UTC) X-FDA: 80191929594.27.F103D24 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf11.hostedemail.com (Postfix) with ESMTP id E496A40010 for ; Thu, 1 Dec 2022 00:59:35 +0000 (UTC) Received: by mail-pl1-f202.google.com with SMTP id h3-20020a170902f54300b00189af47afd0so187322plf.9 for ; Wed, 30 Nov 2022 16:59:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=e92a18eHuJ8mZrfQDHSKc8Zy5Ob6/iLRtV4sTh5UTi4=; b=Tu5Jf4omA0dDqNVhxlMaktNhd9kMUc6ydmywaI3K2X24ITAiwF4YoMslCbEnOqI9P5 yBRDg3b/w8jRjMos8EWH4fxLnlXR0rHgV0agvEL5w90d97hxECa712iIsgkkC+Vyt825 4u+4QF67Fk9p6l/mN3SmW7T9LPBYwiR7zaV73QHjtdCfjmrGoXAX/0yhdAYLZcxkBlfh z8q5ea2u8qWhCzVCCM2ehFLH6nUgNhhqN+QYw9ZDZCTIewCaUBCvnOotJe7E5Eul5k3M g0uNKLrZuT3bUmRbJhVXuku4WKvSaYxZYc1NHli43lvWjJxr30t7GPyC6TGuI9su9ZTu EitA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=e92a18eHuJ8mZrfQDHSKc8Zy5Ob6/iLRtV4sTh5UTi4=; b=xNLdE7CB67zcUsuxnKNYGpZ7dihCBOrvQMgl5KNq9wQSzVM6xacpPHUdDNFS7sMdC9 eGNrgzY+DRXm92eX0G3F03Mw1tX8xxwIqPmaXzbQC7rbrUZFumjLho0K5UV0TSuTC87Z Jdyh62ZmxqiiYICJjf0/ZCErWiMCapsRxZKpEcn8/g3s30yq0p3uvH9uBsSvymtj8GK9 0OTEmsoU1AgaJBcf5TNEEgUGZqKiHH1S/lB3uQ0P2pq5RdDdZcXx11YwfN+OR7dhjdFX ZxgEV+GPFCS9rLm73WXG0n3HSmAlJ2qFno6HIXcvbSE6jEfmrEBH2YET++xQF/+DYovH F2Tw== X-Gm-Message-State: ANoB5pn9zQyyCy+lPpqifMz9LvfJ7esNdzKs9zYJkfRc/vA0N3A7C8+d zpVH/Z2KF4ibqdbBilw441rscrtxPQ/ZZw== X-Google-Smtp-Source: AA0mqf6/yHr8fTfp5a1CEviW5CpkkAFY8BSchwo1p258tmUhVL13JZm5Jnc1P4ht9FjdpZTJAYxm9qLkrfxJ5A== X-Received: from yjqkernel.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1837]) (user=jiaqiyan job=sendgmr) by 2002:a17:902:e950:b0:188:bc8f:5fb2 with SMTP id b16-20020a170902e95000b00188bc8f5fb2mr57996536pll.48.1669856374698; Wed, 30 Nov 2022 16:59:34 -0800 (PST) Date: Wed, 30 Nov 2022 16:59:29 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221201005931.3877608-1-jiaqiyan@google.com> Subject: [PATCH v8 0/2] Memory poison recovery in khugepaged collapsing From: Jiaqi Yan To: kirill.shutemov@linux.intel.com, kirill@shutemov.name, shy828301@gmail.com, tongtiangen@huawei.com, tony.luck@intel.com Cc: naoya.horiguchi@nec.com, linmiaohe@huawei.com, jiaqiyan@google.com, linux-mm@kvack.org, akpm@linux-foundation.org, osalvador@suse.de ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Tu5Jf4om; spf=pass (imf11.hostedemail.com: domain of 3dvyHYwgKCLEaZRhZpReXffXcV.TfdcZelo-ddbmRTb.fiX@flex--jiaqiyan.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3dvyHYwgKCLEaZRhZpReXffXcV.TfdcZelo-ddbmRTb.fiX@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669856376; a=rsa-sha256; cv=none; b=dXoSqhZIUZ5ns7jU3PlbipZSlCSgv0YsMUUdRzokqLJjKYRh2WAG1TmKcUUrPp58rudbef qyUuDUhQen4eXortxNQvysE9yeiyxDUvVCuM25yw5Ng6N5wBWoIsT4cBQXwRWUo85yubMe R1NtBJHf3TQ8Z1rTTwaIxt7S9X8KL/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669856376; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=e92a18eHuJ8mZrfQDHSKc8Zy5Ob6/iLRtV4sTh5UTi4=; b=GfQlUE53ztwgXok50V7OG3mZePhGfDl6b/2TXk8Bj+6Mt/fFDHCTK7ku0/Nagz/1deSzRK aLNXO0LhZu2Kwej8GVW8ycDbWZIOd7AZmYO2BqkhU1dE3+P47eBmD8fPatJUQsUNm20vLL rbtI3qCRTtR7zi618jQt0ZzrrDR2whY= Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Tu5Jf4om; spf=pass (imf11.hostedemail.com: domain of 3dvyHYwgKCLEaZRhZpReXffXcV.TfdcZelo-ddbmRTb.fiX@flex--jiaqiyan.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3dvyHYwgKCLEaZRhZpReXffXcV.TfdcZelo-ddbmRTb.fiX@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam01 X-Stat-Signature: 1azfd1j61jcn5kwhoex9mq37b9ntk9yq X-Rspamd-Queue-Id: E496A40010 X-Rspam-User: X-HE-Tag: 1669856375-586281 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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 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 ========= v8 changes - Incorporate feedbacks from Tony Luck - Rename copy_highpage_mc to copy_mc_highpage. - Update copy_mc_highpage with kmsan changes. - Code style changes: 1) copy_mc_highpage returns int as "copy" is an action and is consistent with copy_mc_user_highpage. 2) __collapse_huge_page_copy returns scan_result(int) and is consistent with __collapse_huge_page_isolate/swapin. 3) variables are declared in separate lines in collapse_file. v7 changes - Fix a bug "KASAN: stack-out-of-bounds Read in collapse_file". After copying all pages into the huge page, clear_highpage should use index instead of page->index. v6 changes - Address comments from Kirill Shutemov - 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 - 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 - 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 - 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 | 21 +++ include/trace/events/huge_memory.h | 3 +- mm/khugepaged.c | 234 ++++++++++++++++++++--------- 3 files changed, 186 insertions(+), 72 deletions(-)