From patchwork Wed Apr 6 22:23:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 12804145 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 69589C433EF for ; Wed, 6 Apr 2022 22:24:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8130B6B0071; Wed, 6 Apr 2022 18:24:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C0EF6B0073; Wed, 6 Apr 2022 18:24:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 689096B0074; Wed, 6 Apr 2022 18:24:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 5ADA16B0071 for ; Wed, 6 Apr 2022 18:24:09 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 168C461D50 for ; Wed, 6 Apr 2022 22:23:59 +0000 (UTC) X-FDA: 79327882998.03.1B948C9 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf05.hostedemail.com (Postfix) with ESMTP id 7D567100002 for ; Wed, 6 Apr 2022 22:23:58 +0000 (UTC) Received: by mail-pf1-f202.google.com with SMTP id y23-20020a62b517000000b004fd8affa86aso1397368pfe.12 for ; Wed, 06 Apr 2022 15:23:58 -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=sZRnJoLfnrGdOhf0+feqeHiMSk99y7rxNCo2yCJPe9HtH2aYFDUlwnwGTAlDmr98Vb q/atIg7pcKZvYQWl29ue/TbKePK6OVA3jtakG5ww/evWuEescIg2qRiDckchn7CaYYZz IHLa7X/CtSb89a2cGKJU6/UHFwQyTItYqk1Lsysj8CqG3wACtB4xeGLuVTtOROTP9cyG Sp4FiHJ7hXP7eiKVEqaoT8/ZuEtOc9qJrOV3LllM2XL7UMNCZwuoAHlvQBcQMMAbR9M1 613Kx1gr1YjK8W/Q4kjlLfHoqWosCSh+wEb1pWcQ+syYAedI8Xf2Y/kwusSS6VWDVWlN Tzug== 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=svThWoqruwQ+RAxsY9WQprnK39wn5493aeVtClQWD3UqKc7feZaGwq3vhAmZNjJZXT I8ylorz5RmTQp5yN8nzDfMkQG4P09zJFaZkFNlci2WGU8rI5x3+FKxWYozBJgs6a8UYW 35nKumkIWecufoRFnhJN7eZHCwNAdb7iaqaSD3h9FMFUNx4QBzhC3WW/AqHXDgTFPgad KdgPMYIFw7/drhfA3hnF/TtxfDbwzHA8PmKvsgXqqAnwur9bkIT/ZnpKlkZJ/1VcyPrY PQIsxEwY2LT/IUNDcowvgMFJ7kCApK7pFmJbwjIHX8zfs1lHxN9NJ24R94y0vAWt9ZZW dNoQ== X-Gm-Message-State: AOAM530hK0A2ImDw5a3eK4zM4FFWLU0epFmQTeG9yoVU09vSBNh7kt5u FZknblBp+iBuhrzv6Gc4AsH2iJSfObGeHQ== X-Google-Smtp-Source: ABdhPJzVDwsTGwW0FpNW+1S7WlNRhyfrYuRJJYGrCffrZ2fYZjcF3XV6EVj5oY60l6r5C2j5t4NqNmJBQBX3Tg== X-Received: from yjqkernel.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1837]) (user=jiaqiyan job=sendgmr) by 2002:a17:90b:224f:b0:1c9:949e:2202 with SMTP id hk15-20020a17090b224f00b001c9949e2202mr12277816pjb.56.1649283837268; Wed, 06 Apr 2022 15:23:57 -0700 (PDT) Date: Wed, 6 Apr 2022 15:23:49 -0700 Message-Id: <20220406222351.949927-1-jiaqiyan@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.1178.g4f1659d476-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, linux-mm@kvack.org, Jiaqi Yan X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=sZRnJoLf; spf=pass (imf05.hostedemail.com: domain of 3_RJOYggKCHQbaSiaqSfYggYdW.Ugedafmp-eecnSUc.gjY@flex--jiaqiyan.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3_RJOYggKCHQbaSiaqSfYggYdW.Ugedafmp-eecnSUc.gjY@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 7D567100002 X-Stat-Signature: qf3iib9mdpe94465fpir45otmkioy3x7 X-HE-Tag: 1649283838-196856 X-Bogosity: Ham, tests=bogofilter, spamicity=0.061011, 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(-)