From patchwork Wed Jun 26 05:08:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13712308 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 93A37C27C4F for ; Wed, 26 Jun 2024 05:08:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E19386B0099; Wed, 26 Jun 2024 01:08:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA0BE6B009A; Wed, 26 Jun 2024 01:08:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA6246B009B; Wed, 26 Jun 2024 01:08:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 900086B0099 for ; Wed, 26 Jun 2024 01:08:29 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 44E7D1209CE for ; Wed, 26 Jun 2024 05:08:29 +0000 (UTC) X-FDA: 82271859138.20.73393A6 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf19.hostedemail.com (Postfix) with ESMTP id 7AAAB1A000E for ; Wed, 26 Jun 2024 05:08:27 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="kpy/o7hP"; spf=pass (imf19.hostedemail.com: domain of 3SqJ7ZggKCLcgfXnfvXkdlldib.Zljifkru-jjhsXZh.lod@flex--jiaqiyan.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3SqJ7ZggKCLcgfXnfvXkdlldib.Zljifkru-jjhsXZh.lod@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=1719378500; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8y7ao8RcoBqL0KFdl8TvipShcb1ljHNHWsgFR/lOgAk=; b=H8p8s+5yqkzeacSzgTOKuVdEWjRufWMTeOITlGqcCV7t/j4BxUWrslFE5TNKi061fc9Re0 +dLNBGzM+Pbmfg0yMvj8UOu9JCwdP8Jo288vCzrGS/IUYYCwF0dWyOn9bkcgOkvpCuev7O CvYXclOqM36X4kNi/UhImZ0qxgfAhkQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="kpy/o7hP"; spf=pass (imf19.hostedemail.com: domain of 3SqJ7ZggKCLcgfXnfvXkdlldib.Zljifkru-jjhsXZh.lod@flex--jiaqiyan.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3SqJ7ZggKCLcgfXnfvXkdlldib.Zljifkru-jjhsXZh.lod@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719378500; a=rsa-sha256; cv=none; b=NjndjqjSjPWS0mwb4u7YA31Q39cc/vtWnPm8SdKkCibPrsarK5+4Q202npcxkpXBuy3dvS 462EAfHYcSLxOFhOOHd+9D+LVpFy9a+tLPcu65EmyjZXaqUSEva4hUlopXWaqDmYpAJDSc 079fcEklkfBIG/voFlzQ8oOgh0AfI1w= Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-1f717559ed9so2193115ad.1 for ; Tue, 25 Jun 2024 22:08:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719378506; x=1719983306; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8y7ao8RcoBqL0KFdl8TvipShcb1ljHNHWsgFR/lOgAk=; b=kpy/o7hPpllPDHZ56FrpsEj8Lq4PcMl2D8nwcpKeHeLLafvmLJpVxWgcxCe+U1j3J2 FFYhKC/oCw7W8HmnLVnQp2xNTIVyWd2pstPwvi5pse8O6IA1olk+GyFDuZwjzFT6mcMj lmYTnEqhaiQiQyrQooE9ElXeVd1MM2s0WMpNV9HKsbtm1nE2w9T1kQ8r90zfVY7kNXtG 3VlxDVA8Hq/NltHBk7X9DQUfRzrICSgDWlUCBkS/qIpR0j6aqroQsX7xUUtsmMrHTiVJ w7Q6CMucvX2szzlZa4CXD8lH/jZWAlrPGQ7AITyJjbY4cLBN4K01TxJXdNrmEPsIR/wJ SKvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719378506; x=1719983306; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8y7ao8RcoBqL0KFdl8TvipShcb1ljHNHWsgFR/lOgAk=; b=OiuTErpPSZBqV9+8JowBGSXYu6U+DhYFpuvnFLXwOaVnU0llcxUTlfNH21NbZY8lGw UVuEJCKhMZa9PUScJ56jv5H6OtI0AnPyodVlfQCR8hNs2q3piQUjiTet5J5CcEH5dBVE Z59kP2qS0sk/aE+ip00xb24YyGCHnAl8rgyqnngsmfmm2Q75j6Hl1NKKxomtILgveigS Oasate6hpla5/YQTwT5y2kp6nyAcMadiOF1sOHFhvyyDmOTf62RQUEbzcSLvX9leivKy 2gwkVrbt8nFdjwHLG39i9jlOOFtivOLjLUqg+PBX2N97/zYdp/WTz2YWIogcB4Zb9CPG tHyQ== X-Forwarded-Encrypted: i=1; AJvYcCXeCFfs4OamDSBy8HXXRSChmCpUVfSI2xlGkPMj8HjDbovH2sxaP1g2iRvFCdb85z940yPPX1lXrA5EF1QWLq6/g/Q= X-Gm-Message-State: AOJu0YwnARek0SZ/LNCLT7S/lAr2QUBEFyFjOhPe1qgp3V0EEn5uNZqm kXDveX1r+pkYpoTI5WjqcLNfBqxyxs9kl9Y8gZHkjaop/Qc69w+UfWxbPMP6cKblwXD3XDij/oU /pyJ6C4Drsg== X-Google-Smtp-Source: AGHT+IFMw6f7MOlDWfVepmO+C1PVKVXo4zQODjs53YFlJ2c1BkCfmt+eu9ZUoQDtHFkvUJpUimIn1RfCeGhwow== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a17:902:eccb:b0:1f9:cc3c:9dc with SMTP id d9443c01a7336-1fa104968e4mr4123865ad.5.1719378506297; Tue, 25 Jun 2024 22:08:26 -0700 (PDT) Date: Wed, 26 Jun 2024 05:08:16 +0000 In-Reply-To: <20240626050818.2277273-1-jiaqiyan@google.com> Mime-Version: 1.0 References: <20240626050818.2277273-1-jiaqiyan@google.com> X-Mailer: git-send-email 2.45.2.741.gdbec12cfda-goog Message-ID: <20240626050818.2277273-3-jiaqiyan@google.com> Subject: [PATCH v6 2/4] mm/memory-failure: userspace controls soft-offlining pages From: Jiaqi Yan To: nao.horiguchi@gmail.com, linmiaohe@huawei.com Cc: jane.chu@oracle.com, rdunlap@infradead.org, ioworker0@gmail.com, muchun.song@linux.dev, akpm@linux-foundation.org, shuah@kernel.org, corbet@lwn.net, osalvador@suse.de, rientjes@google.com, duenwen@google.com, fvdl@google.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, Jiaqi Yan X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 7AAAB1A000E X-Stat-Signature: e61ejr1qkhirgo9edg4wou5ppinyd56r X-HE-Tag: 1719378507-823785 X-HE-Meta: U2FsdGVkX19TuogQeEfpxeA+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Bi/Q/yF92zYb/TFx84rs8EBH/5ayK0uzV9m0pdkkt/Pv3u9TC2nvYlLYsrstwEHSU7f1jM7wIcPaGkkD+hb/L3fqqtdPkoERcrKQMn5DL+K7giDNo3rPe2VApwBXdJEO+Pw/Ry0tmCzzvIdu0rT/HMR6/1DDCChKGVWP3YFuv7k+pVlwC9I35mbZCcVKTrIdwkjxI3y6K/PYEeKBReEAPIXEdZn3DtyaTcqb5GRi2leV+pFyjGjg99ab8mHoSjzF5JyWZ++5i90eWi+r1NPAjqCXETdDkBF/pmwqJdIHkKgupqPEWjTTo8+fpcdU4ZL8zAP/fIMSPLqkRsS+VGS8rDTP1OpZMuT9dckAH3ZcAV1lrFNc27/VrfwiLl2pvLsc5kDQSbFiCHaJRmPwEKG/fbx/OOjDo8i/y4Fm9npSVd7ToJ492icjG+DJQcAPyRJo8v9IJvt05CrcfAEPcLgYP1g8Exj6SR/EdPYX8wwC0HwS7dk1FTCehE3Z2dccLtj/tmptIsn9eQtYmsDl39+4b75eP 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: List-Subscribe: List-Unsubscribe: Correctable memory errors are very common on servers with large amount of memory, and are corrected by ECC. Soft offline is kernel's additional recovery handling for memory pages having (excessive) corrected memory errors. Impacted page is migrated to a healthy page if inuse; the original page is discarded for any future use. The actual policy on whether (and when) to soft offline should be maintained by userspace, especially in case of an 1G HugeTLB page. Soft-offline dissolves the HugeTLB page, either in-use or free, into chunks of 4K pages, reducing HugeTLB pool capacity by 1 hugepage. If userspace has not acknowledged such behavior, it may be surprised when later failed to mmap hugepages due to lack of hugepages. In case of a transparent hugepage, it will be split into 4K pages as well; userspace will stop enjoying the transparent performance. In addition, discarding the entire 1G HugeTLB page only because of corrected memory errors sounds very costly and kernel better not doing under the hood. But today there are at least 2 such cases doing so: 1. when GHES driver sees both GHES_SEV_CORRECTED and CPER_SEC_ERROR_THRESHOLD_EXCEEDED after parsing CPER. 2. RAS Correctable Errors Collector counts correctable errors per PFN and when the counter for a PFN reaches threshold In both cases, userspace has no control of the soft offline performed by kernel's memory failure recovery. This commit gives userspace the control of softofflining any page: kernel only soft offlines raw page / transparent hugepage / HugeTLB hugepage if userspace has agreed to. The interface to userspace is a new sysctl at /proc/sys/vm/enable_soft_offline. By default its value is set to 1 to preserve existing behavior in kernel. When set to 0, soft-offline (e.g. MADV_SOFT_OFFLINE) will fail with EOPNOTSUPP. Acked-by: Miaohe Lin Signed-off-by: Jiaqi Yan --- mm/memory-failure.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 6f5ac334efba..1559e773537f 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -68,6 +68,8 @@ static int sysctl_memory_failure_early_kill __read_mostly; static int sysctl_memory_failure_recovery __read_mostly = 1; +static int sysctl_enable_soft_offline __read_mostly = 1; + atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0); static bool hw_memory_failure __read_mostly = false; @@ -141,6 +143,15 @@ static struct ctl_table memory_failure_table[] = { .extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_ONE, }, + { + .procname = "enable_soft_offline", + .data = &sysctl_enable_soft_offline, + .maxlen = sizeof(sysctl_enable_soft_offline), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + } }; /* @@ -2749,8 +2760,9 @@ static int soft_offline_in_use_page(struct page *page) * @pfn: pfn to soft-offline * @flags: flags. Same as memory_failure(). * - * Returns 0 on success - * -EOPNOTSUPP for hwpoison_filter() filtered the error event + * Returns 0 on success, + * -EOPNOTSUPP for hwpoison_filter() filtered the error event, or + * disabled by /proc/sys/vm/enable_soft_offline, * < 0 otherwise negated errno. * * Soft offline a page, by migration or invalidation, @@ -2786,6 +2798,13 @@ int soft_offline_page(unsigned long pfn, int flags) return -EIO; } + if (!sysctl_enable_soft_offline) { + pr_info_once("%#lx: disabled by /proc/sys/vm/enable_soft_offline\n", + pfn); + put_ref_page(pfn, flags); + return -EOPNOTSUPP; + } + mutex_lock(&mf_mutex); if (PageHWPoison(page)) {