From patchwork Wed Mar 23 23:29:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 12790256 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 87FEBC433EF for ; Wed, 23 Mar 2022 23:29:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19ED16B0072; Wed, 23 Mar 2022 19:29:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1506C6B0073; Wed, 23 Mar 2022 19:29:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 014F56B0074; Wed, 23 Mar 2022 19:29:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0088.hostedemail.com [216.40.44.88]) by kanga.kvack.org (Postfix) with ESMTP id E2D826B0072 for ; Wed, 23 Mar 2022 19:29:52 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9CDD3A32A9 for ; Wed, 23 Mar 2022 23:29:52 +0000 (UTC) X-FDA: 79277245824.18.C05B284 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf30.hostedemail.com (Postfix) with ESMTP id 39FC480024 for ; Wed, 23 Mar 2022 23:29:52 +0000 (UTC) Received: by mail-pf1-f201.google.com with SMTP id b7-20020aa79507000000b004fa88200f15so1681934pfp.14 for ; Wed, 23 Mar 2022 16:29: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=ot6po/CFv2v3JkHbEJ6hOR2zIpaz8kT2HNxSLK39YYY=; b=qf/G9y7hu/aGHw++Af1ZRutyQuT8k4dsoxf6VnL3dLw7AZTZiMt9lIUXB6wGNftjxY IoVseBJi20lhG1DnuzZvUbjB0+EZdLPwCPQxYJoagY57JDAeAb2JlTp2SS3rvxElHGCd isjUP1lf14xtW+ON7FaF9NSyeNWBMdFPjfq22fXtcxg3qo8ZcjHoh48+YJ/kSgxIB7zu iZsIZvYgLqGlw15xGFaMsOETfDxrGkmd2qIjGpN8BBtU2W5Ezx3EBxCAv6t2fvG+b48R oIGWomIoaXZjIghm00Q0+bES2CajVXidFpX7s/psfeiKkOy2DbfO2mHxxJ1ikUK2gI20 lSDg== 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=ot6po/CFv2v3JkHbEJ6hOR2zIpaz8kT2HNxSLK39YYY=; b=JNafQMm5DbT7SlmnVk1yXnLzZtfHEahi0XSJcNKu653FD9hSryW8BIsiES5tICiunM Ksr7NqiuPTLnEysRukax5fFRH4VSLgf1Dli05+tyocDZln2uJauF8AN+BHx+Aw7OvmvC //bjjdMaW9YXfbLJY6nO0VTnyxWSkodRv3xGhkA3pPcYP1+rlTaMY0nNeOPel3QiiNCQ Y7z4lS1fGiw5crykCKa+9PDB7AHW1znv+eOqcHjptjcah+A3X9+PYuZJFF3lKC7Nascf 9Wvube2NerwfAP+0PTdSiDAva279iqgArWoxX3ftVJ1+Cr2excEUsYzKBGLy6uHAgwdt LRPg== X-Gm-Message-State: AOAM530SjMnanrI3Gt+onC78PL7QQMeZnnGRUJ6FfqSO2xFtqTcdmZrS zpnUb8ZeDAakYXgi/dwDWNjOJfZMzPAL8g== X-Google-Smtp-Source: ABdhPJyXVm7HS0hSogCnLqVM6nGtof0++BJASTF838oIUsWPqnU3en4WadLjI+Hov4Yy765JYPeefrzFaTCoxA== X-Received: from yjqkernel.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1837]) (user=jiaqiyan job=sendgmr) by 2002:a05:6a00:22c3:b0:4f7:7cb:26b0 with SMTP id f3-20020a056a0022c300b004f707cb26b0mr2273663pfj.47.1648078191092; Wed, 23 Mar 2022 16:29:51 -0700 (PDT) Date: Wed, 23 Mar 2022 23:29:27 +0000 Message-Id: <20220323232929.3035443-1-jiaqiyan@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.894.gb6a874cedc-goog Subject: [RFC v1 0/2] Memory poison recovery in khugepaged From: Jiaqi Yan To: shy828301@gmail.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: bdnmb4xw8ik71nzmbetg34iczuwfhrh9 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="qf/G9y7h"; spf=pass (imf30.hostedemail.com: domain of 3b607YggKCNA54wC4Kw92AA270.yA8749GJ-886Hwy6.AD2@flex--jiaqiyan.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3b607YggKCNA54wC4Kw92AA270.yA8749GJ-886Hwy6.AD2@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 39FC480024 X-HE-Tag: 1648078192-323313 X-Bogosity: Ham, tests=bogofilter, spamicity=0.241516, 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. Impact ====== The main reason we chose to make khugepaged 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 application 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. 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 | 37 +++++++ mm/khugepaged.c | 211 +++++++++++++++++++++++++++++----------- 2 files changed, 189 insertions(+), 59 deletions(-)