From patchwork Fri May 27 19:07: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: 12863716 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 BC900C433F5 for ; Fri, 27 May 2022 19:07:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 160778D0003; Fri, 27 May 2022 15:07:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 10E9C8D0001; Fri, 27 May 2022 15:07:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F16818D0003; Fri, 27 May 2022 15:07:38 -0400 (EDT) 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 DEB7F8D0001 for ; Fri, 27 May 2022 15:07:38 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 70743120AA0 for ; Fri, 27 May 2022 19:07:38 +0000 (UTC) X-FDA: 79512456996.27.F4AEC43 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf27.hostedemail.com (Postfix) with ESMTP id 71FC140041 for ; Fri, 27 May 2022 19:07:34 +0000 (UTC) Received: by mail-pl1-f201.google.com with SMTP id c4-20020a170902c2c400b0015f16fb4a54so3271425pla.22 for ; Fri, 27 May 2022 12:07:37 -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=bdvYVk8aAkC9NwD3j/M7WRdJhKFNL8Dl9cRTAL7TOe8=; b=n6Sq5ipvE4XwE4OyuZZP89WO9Q6nuAwRS3/gaUVRkRUeZMxejDZ7Mk+Yj6+T1Gi5xr 0qwYKUgTOwCtYyiBBi2kclPkV3ytFyzNSFpoulfD+N+GUd/O9sfATHLwOXueFRU5vNG6 h91elqs5z5hGQBd1eynBby7et4huvEpCb6KIgsJ4c0jlbliUYEyXsk0ovGSQBnehtV2F fPIk9Cxh71ot4uxyo6RoO/duFZpQmY05zbl5Gv3IH4RE7c0q9ao0fvyB8N92GzNjiAvd GlTs8LbEVyuquSwp9hG/6IlQgwbJdyqLCLwlYvbLOL/GOX972B/fJJ6zK2sOULgtO663 ArCQ== 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=bdvYVk8aAkC9NwD3j/M7WRdJhKFNL8Dl9cRTAL7TOe8=; b=YyP0qQ232Yxpo4EgWM6uXAMBlKhTCbXTlVZSTynSXBiuNQEXy5cvG71Qdomkz6AhZn 4sgoSCSKNyCi5P1XI9//pOMk6z27c2tG8tzz96xK0hkMDnoQdEw73rMOydVjv22NEQ9k AriCkaDONp1d7kSi7r9W/Fz58SyQpSVGJ48CziG448O9nYtY3pBFwMTLyBa9ck05fjDp 8LxwNe1/EFCR10POdjABLIZa0vtNVbaLY06J4Ac1tlNU18WkO9l92paO+6w+FELVy6Rt 9+P2ARzGUTXTU9c+gpTctIFB+Qsp0owIt5C24upTojCQvoZArxvXkBQP7H9I4dcYqm8Q Y37A== X-Gm-Message-State: AOAM5312wIyV+o7o64Id/3WZUev2uW/yrbu2KCYTNiHC+3xvaRyVaQUS HdAhNh5iY6/XJfXaKR80OpjlD2tFea1CrA== X-Google-Smtp-Source: ABdhPJw+7Lp+jZubslOKfJNpYIlnCBnBCKjTYTli0AWg+wBlewaZd+U9qhiHwMWEo6QbTBQP0iuQiP5KJqGm9A== X-Received: from yjqkernel.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1837]) (user=jiaqiyan job=sendgmr) by 2002:a63:2645:0:b0:3f5:f438:c0e0 with SMTP id m66-20020a632645000000b003f5f438c0e0mr38167276pgm.186.1653678456624; Fri, 27 May 2022 12:07:36 -0700 (PDT) Date: Fri, 27 May 2022 12:07:29 -0700 Message-Id: <20220527190731.322722-1-jiaqiyan@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.1.124.g0e6072fb45-goog Subject: [PATCH v4 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 X-Stat-Signature: sjexge7iakjnt76o19x34pwz3zyx18rq X-Rspam-User: Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=n6Sq5ipv; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of 3eCGRYggKCBsA91H9P1E7FF7C5.3FDC9ELO-DDBM13B.FI7@flex--jiaqiyan.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3eCGRYggKCBsA91H9P1E7FF7C5.3FDC9ELO-DDBM13B.FI7@flex--jiaqiyan.bounces.google.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 71FC140041 X-HE-Tag: 1653678454-640892 X-Bogosity: Ham, tests=bogofilter, spamicity=0.019432, 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 ========= v4 changes - Remove tracepoint of trace_mm_collapse_huge_page_copy, only interpret the new result in trace_mm_collapse_huge_page() - Remove confusing comment, fix nit and typo v3 changes - Incorporate feedbacks from Yang Shi - Add tracepoint for __collapse_huge_page_copy - 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 | 19 +++ include/trace/events/huge_memory.h | 3 +- mm/khugepaged.c | 203 ++++++++++++++++++++--------- 3 files changed, 166 insertions(+), 59 deletions(-)