From patchwork Fri Apr 29 00:09:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 12831340 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 9CB26C433F5 for ; Fri, 29 Apr 2022 00:09:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8F5C6B0071; Thu, 28 Apr 2022 20:09:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E40546B0073; Thu, 28 Apr 2022 20:09:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D062C6B0074; Thu, 28 Apr 2022 20:09:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id C025B6B0071 for ; Thu, 28 Apr 2022 20:09:51 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9B38D25D9C for ; Fri, 29 Apr 2022 00:09:51 +0000 (UTC) X-FDA: 79407983382.10.ACB42A9 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf25.hostedemail.com (Postfix) with ESMTP id 5D31DA006D for ; Fri, 29 Apr 2022 00:09:42 +0000 (UTC) Received: by mail-pj1-f73.google.com with SMTP id d64-20020a17090a6f4600b001da3937032fso3662238pjk.5 for ; Thu, 28 Apr 2022 17:09:51 -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=jaPczUXVbGL4lHdzBNlirh2jepP7wb5FIbR5c55FaXg=; b=Z+l31QqLnQHMF14L7UYBwtNyIL1Gf1iDUf3BiYyBR2AmxCm1lpJGhffskK+djSK4ae +ep0X7sGbGHJRHsu/H03Zf/9ctf25kPAN5Rr4Kb3ih5F9RMpsky91jw8M3Fg877ie250 SgP7pDX75nUI9iPtpNO7FFlu3DNb9lxNBz1NMoZL9nfjyeBFIyk6SqO6r4+LtS3p64mX OqxZF8K08FXo3z85CcMyFTTgt038xaMXW5mBIwATTF6AtsM0N0I7Lhlyhl4CQmlCTF9Z BYHDF4MD423n+9YDGFWQF+GWJL/EdKGgqwhTepnqjZk7PpZ+gDmn7GZFbFkbqH7VJpaY ZtLQ== 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=jaPczUXVbGL4lHdzBNlirh2jepP7wb5FIbR5c55FaXg=; b=CF/9R0yDfyV6lh/OKdrfDGD5EUN3L8hc/GEVLOPrum1hnhkzg8Gin3LcAn4Gah11nh sWKatCLYRcfKSFJB5q71Yay7GbGQkN+8bC5ftFKj9EmltcU5Do9P1GQaoXBDSdCI4qB2 o9/feOq1fsX+fP8iKHMblPljaGdCa0H7+iifdTrT3lIJRpPQbN1dAsJoQ+9hoqKFuodl /5bfT5J9cMfbdusDg79VXKQWO8WuBAJLl9ZeG9WMqCAkxVTCwxhGrfkrS+EjmclGprkY usl8YVktHNvv2DVVNBb5laNXYXM4d5+xmHqJyrl29d9UmF6MkGcxa8fQxTIGyEM4GLkw NgYQ== X-Gm-Message-State: AOAM530xisFEqfUiXjXxLStvBg4CDGyFY2pROfxppSUO28qoeTYg+r8M Zjsy6/24YtRZtwT/ughh96zMw+/2MqZjSw== X-Google-Smtp-Source: ABdhPJyMFDA9rdQDUUKxiKIbkx/V/l2AEkc45M8dlm07ZfZMnMfl2uFZyhBkpLi3cn7YLq7ROWpN8mcXQi4KMg== X-Received: from yjqkernel.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1837]) (user=jiaqiyan job=sendgmr) by 2002:a17:90a:e510:b0:1d9:ee23:9fa1 with SMTP id t16-20020a17090ae51000b001d9ee239fa1mr172287pjy.0.1651190989611; Thu, 28 Apr 2022 17:09:49 -0700 (PDT) Date: Thu, 28 Apr 2022 17:09:45 -0700 Message-Id: <20220429000947.2172219-1-jiaqiyan@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [RFC v2 0/2] Memory poison recovery in khugepaged collapsing From: Jiaqi Yan To: shy828301@gmail.com, tongtiangen@huawei.com Cc: linux-mm@kvack.org, tony.luck@intel.com, naoya.horiguchi@nec.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, juew@google.com, jiaqiyan@google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 5D31DA006D X-Stat-Signature: sukrjmr8ipqh9wgtwtikwrzg77na1f5b Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Z+l31QqL; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf25.hostedemail.com: domain of 3zSxrYggKCOwXWOeWmObUccUZS.QcaZWbil-aaYjOQY.cfU@flex--jiaqiyan.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3zSxrYggKCOwXWOeWmObUccUZS.QcaZWbil-aaYjOQY.cfU@flex--jiaqiyan.bounces.google.com X-Rspam-User: X-HE-Tag: 1651190982-764577 X-Bogosity: Ham, tests=bogofilter, spamicity=0.187430, 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. Jiaqi Yan (2): mm: khugepaged: recover from poisoned anonymous memory mm: khugepaged: recover from poisoned file-backed memory include/linux/highmem.h | 19 ++++ mm/khugepaged.c | 215 ++++++++++++++++++++++++++++------------ 2 files changed, 172 insertions(+), 62 deletions(-)