From patchwork Mon Jun 24 16:33:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13709847 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 1D343C2BD09 for ; Mon, 24 Jun 2024 16:34:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00A8F6B032F; Mon, 24 Jun 2024 12:33:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EACEA6B0397; Mon, 24 Jun 2024 12:33:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C8E8F6B032F; Mon, 24 Jun 2024 12:33:58 -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 AA77C6B0327 for ; Mon, 24 Jun 2024 12:33:58 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 54D94141107 for ; Mon, 24 Jun 2024 16:33:58 +0000 (UTC) X-FDA: 82266328956.26.C0C0798 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by imf13.hostedemail.com (Postfix) with ESMTP id 62E8A20010 for ; Mon, 24 Jun 2024 16:33:56 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=IHmqFQiN; spf=pass (imf13.hostedemail.com: domain of 38p95ZggKCFM43vB3Jv819916z.x97638FI-775Gvx5.9C1@flex--jiaqiyan.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=38p95ZggKCFM43vB3Jv819916z.x97638FI-775Gvx5.9C1@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=1719246818; 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=jaVeSRVMUEHHsCQ2CT1Mt2nWqEzTQXYnHsGL8HUoHVg=; b=eBlDmxipx4bX2Kjk/6YEdZ9sQeIeNBrB0cKDdjd/r8V74Un8IcDcLu1U8F6p7KS+ZEqqco R3+VB2ZMZpf1FN7xy9H7sbx7IC45ozD85/dpo6779i4uIRkNXONpNmc4iw2orMDnkzYCr+ cihzoMGLd3WU/NOlwoBxGXkF/G4fBOs= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=IHmqFQiN; spf=pass (imf13.hostedemail.com: domain of 38p95ZggKCFM43vB3Jv819916z.x97638FI-775Gvx5.9C1@flex--jiaqiyan.bounces.google.com designates 209.85.215.202 as permitted sender) smtp.mailfrom=38p95ZggKCFM43vB3Jv819916z.x97638FI-775Gvx5.9C1@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719246818; a=rsa-sha256; cv=none; b=ywr/hBzkmpUkwXLezw3Xzc6irICLi6YtfBvjXdUDGYLm/TL2SwMlY/LiYrozub75Hxk6nd 8OsqnVmkkbNJoMq+V58pjOV2MvGlNO6COzTbqB2smzO2qfx17P7B9UoZomzsMuOKigj0ZK V94Usuu4BH38wr/ivkZ96dtQ+T7GpyQ= Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-718c62ad099so3349394a12.3 for ; Mon, 24 Jun 2024 09:33:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719246835; x=1719851635; 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=jaVeSRVMUEHHsCQ2CT1Mt2nWqEzTQXYnHsGL8HUoHVg=; b=IHmqFQiNj82me7NzRDLvf9nCH2gLe7tjydI5UzKTr7lCjVP8P/r8V/fuapw4KIYh7/ sJR/J4/irg4rDiLs4+P9lSmuDdN+IkUw8GX9MJNryE/d0LwRaj2hoAdaDgHPVEiRttN5 7mnNDgkY+gPECrPcyR3iOUOrAN4/FeuWYfzv4Jwhk7T4lyIWkgy/JQhpRdqQee8RD/X7 MkiZdUfiJnF9M/aCLW6gJW/Nr7lf05M+pSRQhEeADMwSF43571ZvEmzX3x8DBrwa0pZO 6Y/BQatJvHmrdBZxOjB2qODx5XxnrSXEQiWR8+yjlM5ejid9lBNJONe76akjCO2FY/+u TdHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719246835; x=1719851635; 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=jaVeSRVMUEHHsCQ2CT1Mt2nWqEzTQXYnHsGL8HUoHVg=; b=ZU96Rz302JNVInTWpn+ggSNs2mSxsO7sdNNbO2p4sjdsmsgC3ZY/pD3aMf/hbZfzOP 7ay5FPzsR4oembtvg119rxnyraiXWpNNLCEm8Wcrw4gXWsoh+pDyivH8AZqUq8HRhQIB WSlKJk1d1JWLGCmrwxYg3Hal2zIG/Sh2pPdfp8FdyhjBnLkkTmzX0+cNDuWR1e1DjT7A EFPhoArIG99wVA/GMYHWJ7Yp+/dk5QWMAQcABSU0ZQIdiabUfJPJPO4znKU8p04REAt+ pJHRaTSnLiioVTrNGnXrBkm7fWYpEF1V00vXT3xmNW9W8dQxNVUTPHgMm7T5Yt2kkkVs giPA== X-Forwarded-Encrypted: i=1; AJvYcCWeWO7P95UzJ+wsHkITtN7x7516GCBibPUeSkxFzlEv2Sk9XuU53TwJUvWphBXDG9bf7m1sx/C99egCC8PmA0Ylehg= X-Gm-Message-State: AOJu0Ywsm5iX3+TzAuDZ+9UBj+7o8SaUCYFZoks506VJLl7FaOoWJLPx KmStm33ddWdISaCGbuWF0ZGjSFl7WFy48eHYgWhQJ3BrX7BTnGmKk4yOtW7Z1R87zwDuII/7vzq 4VeKGrY/i5w== X-Google-Smtp-Source: AGHT+IFmjiZXsOh4qVWVE4+iXLz6GybpRfvQXdLXA2xaKMrN+J7XAcxYTT8GInfxKIa7RXbtOwVhCfQSnU4XDg== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a63:2354:0:b0:719:ae7d:9f2e with SMTP id 41be03b00d2f7-71a35641f60mr18300a12.2.1719246834803; Mon, 24 Jun 2024 09:33:54 -0700 (PDT) Date: Mon, 24 Jun 2024 16:33:46 +0000 In-Reply-To: <20240624163348.1751454-1-jiaqiyan@google.com> Mime-Version: 1.0 References: <20240624163348.1751454-1-jiaqiyan@google.com> X-Mailer: git-send-email 2.45.2.741.gdbec12cfda-goog Message-ID: <20240624163348.1751454-3-jiaqiyan@google.com> Subject: [PATCH v5 2/4] mm/memory-failure: userspace controls soft-offlining pages From: Jiaqi Yan To: nao.horiguchi@gmail.com, linmiaohe@huawei.com, jane.chu@oracle.com, ioworker0@gmail.com Cc: 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-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 62E8A20010 X-Stat-Signature: utfif63k4xqpc3438m911g8z86z749m8 X-Rspam-User: X-HE-Tag: 1719246836-486687 X-HE-Meta: U2FsdGVkX187IMk9Jm8xJNpCs4EMwPp/3iRsOxmy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sTa4M9ITOiiNAjUmy9HL6kfucTK//cA35PbcSwJGLRBfzukklz3F8mlDVyKmWp1bJ02M3QMGRbeW03bipTGKxmuZYfM2f/DLRoXB/5nAPkciflIujPlc12NQZJw83A8RTTTTYUL5WVUbeG7az7DaaqTUOpK6qeIIctijQGmfSAyB9UVoH4Os5kolW1w3oMRjUZXZO2Qs+yQI0swV/dYG8yIlI6EIibaVvrYU/0e9KmOt+y9ob0NRc4yCnX7aj2ASg2/quWesqqmaIqp3fpvR6OIWmiOkwK20WwvpaW7FVYIfD1gUU5TnByF9QYQI/auZAMt09QyZW4HnTR7vl9PCo3eoFG/lhERl6MjE6QSW3JgRaygTkKIXMGnxAR29tiz4UZvFJHbspsv2b87CE3U3DkzJaXgMQINcl4bS0u2sZMOSNqzRSCAHwR8fL1O5BugEjw3xZQ4yNAZxBKOi1OxagQImeNJ4wXwI95zxCbxthv3c361I3dTVcVvafCpGruos2OGq3+pedL0eGUCt 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 2a097af7da0e..0013d338569b 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)) {