From patchwork Mon Dec 5 23:40:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13065208 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 EA06BC47089 for ; Mon, 5 Dec 2022 23:41:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8262F8E0002; Mon, 5 Dec 2022 18:41:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D65A8E0001; Mon, 5 Dec 2022 18:41:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69DF78E0002; Mon, 5 Dec 2022 18:41:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5AAAF8E0001 for ; Mon, 5 Dec 2022 18:41:06 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 28A65A0C9D for ; Mon, 5 Dec 2022 23:41:06 +0000 (UTC) X-FDA: 80209875732.24.48BA61B Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf08.hostedemail.com (Postfix) with ESMTP id AEA98160007 for ; Mon, 5 Dec 2022 23:41:05 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=rzyVcbNe; spf=pass (imf08.hostedemail.com: domain of 3kIGOYwgKCO8aZRhZpReXffXcV.TfdcZelo-ddbmRTb.fiX@flex--jiaqiyan.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3kIGOYwgKCO8aZRhZpReXffXcV.TfdcZelo-ddbmRTb.fiX@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670283665; 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=KPk7safCVvPP2htEy0IL5oewRr1kBVkolCXgcfcay4g=; b=Tk7ztIFDOdY38R0XkhCsroOSCtHz0Kl7O5eZLF6K8mGMsKRoHrDO90v03yriXKMBDIiO6i WWjefkDtayfzjt+EIaiWPHKyp75azfyBp/IPrZ9ERyxRQQpEDGb/bMfxqS8KA7RowCXAc6 3Z2i0sUUfUu9g+k9jUO5CC3PPpgPeqo= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=rzyVcbNe; spf=pass (imf08.hostedemail.com: domain of 3kIGOYwgKCO8aZRhZpReXffXcV.TfdcZelo-ddbmRTb.fiX@flex--jiaqiyan.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3kIGOYwgKCO8aZRhZpReXffXcV.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=1670283665; a=rsa-sha256; cv=none; b=AhMW2zIH+wLQmBqIrQbR/l28Doj1MmFD3odZWfZfcdkXLaPuqjobOtaBmynf4otXyvAhJV pR2Bpo0/FCQGdQCDiMD66ElskIJXw7f3VPlM7EJvsh6Gug94ZvIA1+KbRQJisoVMAUKEYR upSW6PK2Dhvcce97tNo0u6b3PkTO2CU= Received: by mail-pf1-f202.google.com with SMTP id bq9-20020a056a000e0900b00571802a2eaaso11925276pfb.22 for ; Mon, 05 Dec 2022 15:41:05 -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=KPk7safCVvPP2htEy0IL5oewRr1kBVkolCXgcfcay4g=; b=rzyVcbNeLd0Y9ENJfSkiWitnhZvVc6TL42KPYC753xl7qBlMY69F8GoTJuqOqytA00 LOz25/UFVY02PUtFhU/0hvsx7XAOMfH+cXMcaUgiE1CVfne27ej9xzDCYNfhksd89E4Y gzGbH+WZLUkqFRpoy5SpteS1ofQ7Fr9P0YGTtsOaU4xVVHTP7OOqr6MqVIU0h5Siy3SP MkgpZVjH/GMpuupKOEWsD8lqjNLcAPGZZFDlUKRcn3bikkcLPWnbnFneux4Rp2r/qWcg cophkOohJ6mCX38z8zrTMmEe6/I6Tygo8ejC0QhcfR1+Kk78/IdM2hV0Imb8Tx3EyuSP MjcA== 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=KPk7safCVvPP2htEy0IL5oewRr1kBVkolCXgcfcay4g=; b=eZovPK9wvvDmyExnIMyC5zNFaGA5kEjwp+R9FkDtlWhU98H3qZJatp67Y8el8iclLi XN09/+X8Y8sfmiYoUzbFr7Mmu4IGrc9mfKXqneqIGq3Iv6ibMba7Fd3XGlpvSf0GXRb7 rPvS0SNlp5idDljhEv2iiEOKCTwqF+v+XhiBTiGbLn9O+ufGp2FFgG6yuLdrLt+InxxK 5DdZydM8cflMw0eI+iOStapdki8NCK1EPNFCsNli4PK3y8zPtWR6aaBULv1mMscSi/QY nSHf6P/Ppr8Qy9Ufg3RdfAOu4BQoYrlilwgl+/LDbCGf8SANqITErP+Po3KkBqAWuRdz Sy/g== X-Gm-Message-State: ANoB5pkJEDKUX05kKOayKKWNraWS3wfka8qnER/3qUFE7XN9dUKoOxfY l2uy+eN7R4BxPK33C2v+04zjeZHKLXJCyg== X-Google-Smtp-Source: AA0mqf75EVOuFFA29fl5vl5OCF/8pxkU8yLkAmYHzepOEA2ESxt0FImDNmxVPSuuUwVcNwBd8B45OmAjICn3iw== X-Received: from yjqkernel.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1837]) (user=jiaqiyan job=sendgmr) by 2002:a17:90b:f89:b0:219:5b3b:2b9f with SMTP id ft9-20020a17090b0f8900b002195b3b2b9fmr3121872pjb.2.1670283664385; Mon, 05 Dec 2022 15:41:04 -0800 (PST) Date: Mon, 5 Dec 2022 15:40:57 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog Message-ID: <20221205234059.42971-1-jiaqiyan@google.com> Subject: [PATCH v9 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, akpm@linux-foundation.org, wangkefeng.wang@huawei.com Cc: naoya.horiguchi@nec.com, linmiaohe@huawei.com, jiaqiyan@google.com, linux-mm@kvack.org, osalvador@suse.de X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: AEA98160007 X-Stat-Signature: moq1ctxu3ttiocdc43ycze765d1xhxxi X-Spamd-Result: default: False [-1.10 / 9.00]; BAYES_HAM(-6.00)[100.00%]; SORBS_IRL_BL(3.00)[209.85.210.202:from]; MID_CONTAINS_FROM(1.00)[]; MV_CASE(0.50)[]; FORGED_SENDER(0.30)[jiaqiyan@google.com,3kIGOYwgKCO8aZRhZpReXffXcV.TfdcZelo-ddbmRTb.fiX@flex--jiaqiyan.bounces.google.com]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; TO_DN_NONE(0.00)[]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:209.85.128.0/17]; R_DKIM_ALLOW(0.00)[google.com:s=20210112]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; RCPT_COUNT_TWELVE(0.00)[12]; DKIM_TRACE(0.00)[google.com:+]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; DMARC_POLICY_ALLOW(0.00)[google.com,reject]; FROM_NEQ_ENVFROM(0.00)[jiaqiyan@google.com,3kIGOYwgKCO8aZRhZpReXffXcV.TfdcZelo-ddbmRTb.fiX@flex--jiaqiyan.bounces.google.com]; TO_MATCH_ENVRCPT_SOME(0.00)[]; ARC_NA(0.00)[] X-Rspam-User: X-HE-Tag: 1670283665-520728 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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 ========= v9 changes - Incorporate feedback from Andrew Morton - Move copy_mc_highpage into khugepage.c as a static out-of-line function copy_mc_page. 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/trace/events/huge_memory.h | 3 +- mm/khugepaged.c | 257 +++++++++++++++++++++-------- 2 files changed, 187 insertions(+), 73 deletions(-)