From patchwork Fri Jun 28 20:59:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13716601 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 6B1C5C2BD09 for ; Fri, 28 Jun 2024 21:00:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC3AE6B0088; Fri, 28 Jun 2024 17:00:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B4A986B008C; Fri, 28 Jun 2024 17:00:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9EB176B0092; Fri, 28 Jun 2024 17:00:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7D8776B0088 for ; Fri, 28 Jun 2024 17:00:05 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D37521604F7 for ; Fri, 28 Jun 2024 21:00:04 +0000 (UTC) X-FDA: 82281514728.02.2EBCCEC Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf06.hostedemail.com (Postfix) with ESMTP id 24DEB180019 for ; Fri, 28 Jun 2024 21:00:01 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=wOSMWKt2; spf=pass (imf06.hostedemail.com: domain of 3USR_ZggKCNA54wC4Kw92AA270.yA8749GJ-886Hwy6.AD2@flex--jiaqiyan.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3USR_ZggKCNA54wC4Kw92AA270.yA8749GJ-886Hwy6.AD2@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=1719608383; 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: references:dkim-signature; bh=H9SemWeck9sqZhF4PUkpmqs6CWCt5ZKMH0k65qfYp1Y=; b=YQBXeUMAvk5vXlPvSK/9XGjyyIssMxzMgBEKGEtRDwNbueSyso0CPUeB9SALYKePw+zSnm sfXCNhv0dxge75zE1hJ2NpwZlLwjv/cRmfO0njU2DtdCbBwC7ACidr8qvj3JvL2M/e6GoK FML54VhS0Tt23PzYdV3XnVGQPJ3uAEA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719608383; a=rsa-sha256; cv=none; b=WIuiq5w/ImE2HJPUQoosY63lhgyPHjAxkU3Fmyk2zNwaUCMksiHFPgBgFbrKtJPmCst+VR apMFkYbE6x6cmgf/xYn8uFhwwb0W5SPR19tH+XiQv9Wv97N+i2KXZSTo8BhknD3XdKLSZV 9ajnGVRfCSN2LO6ucnjpfI613njwZ+s= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=wOSMWKt2; spf=pass (imf06.hostedemail.com: domain of 3USR_ZggKCNA54wC4Kw92AA270.yA8749GJ-886Hwy6.AD2@flex--jiaqiyan.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3USR_ZggKCNA54wC4Kw92AA270.yA8749GJ-886Hwy6.AD2@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-64507372362so20140917b3.1 for ; Fri, 28 Jun 2024 14:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719608401; x=1720213201; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=H9SemWeck9sqZhF4PUkpmqs6CWCt5ZKMH0k65qfYp1Y=; b=wOSMWKt208Hj/NXcR1jG+7N8iRLUVLq6VHWwJNbFYYqA5vefnDtK4QO3T0wG8Yptsl V1xPrctTjyhhgWIuRXDGGfVITMG2fbTwp2aLK/qnnnmZ389EFjVZLHQgljnY9bhWmzp6 N/6teIH1wMwXUbywzvNiE3MGx3m2rZFSOGo4hdPlSO7yrnyUfWbjOcGxOPt0qnRENqqF 3Pebq9bLzEOFb0ynLW0S8XR3vC/TR9THTQli3u6edNDIrDOp94JZuUnshFkG0s/gbJ0g upBUxrdckk5IHUgnpZXnHermcoLO9zUKuF67qCZBS15Yk/iWlxCZPnRfUspeIYmlnD0A 8ihQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719608401; x=1720213201; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=H9SemWeck9sqZhF4PUkpmqs6CWCt5ZKMH0k65qfYp1Y=; b=CFirS+LTvGxWJNwo0spn3dSOzDe5gGqTxEPa4wl8drzoGpJ5GK5gszxzxVnYj/R/Ho 5jPE5nPKt076IR1q292mBMHpgEkr6jZ2+nZXu0EqarS/Hriku8y+McOJ/RxooLWKVhSw 2fPVPu+1a9yPy/WzJ/LSotSd0t0H1g2QNbj99msNTWQD46o0NghLPWlJH517ZTooaa7H cBwE3HYfispdpYqunkHJfrsU3b6raTlV9PZOkJBQOu0XSxJwzPWioacG4mtg1Y7oPfzG lYmc4gCOeD5ZgeQUlqoEE/aJWBnQTFyyEt6GtyNnMpjTWMuT7ANLOuzm5nm5A21otxO/ wGgA== X-Forwarded-Encrypted: i=1; AJvYcCUv7zSXCQvX1b1u0US54L6rS5L3L9aNO6Z6yO54/fe2g+7ImYO4zs8LCPjpgaZgL6IW/bGiAPlHrizHiWwkbkA9aHk= X-Gm-Message-State: AOJu0YxuG9Bc9nb0F6+/EmsL0c+dkGKspa5Ov3HmT+ntaNTI1unouUB1 sIZqF0gXTejrW785TvByGEDHNcfzbbgUIYs6A5RNG1dvfU2saXpJy4b8HgxysI5nr6vv4FTgGfN /xaIClHn4yw== X-Google-Smtp-Source: AGHT+IHuT2gN9XPtmf5SVn4cA59errpT4hxsDy5JZE1D+/oWILvq0fkQTnieruKPvX36J5LvENb5Muq2Vr+jNQ== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a05:690c:e:b0:62a:4932:68de with SMTP id 00721157ae682-6429d26f55emr814727b3.8.1719608401004; Fri, 28 Jun 2024 14:00:01 -0700 (PDT) Date: Fri, 28 Jun 2024 20:59:54 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.803.g4e1b14247a-goog Message-ID: <20240628205958.2845610-1-jiaqiyan@google.com> Subject: [PATCH v7 0/4] Userspace controls soft-offline pages From: Jiaqi Yan To: nao.horiguchi@gmail.com, linmiaohe@huawei.com Cc: jane.chu@oracle.com, ioworker0@gmail.com, muchun.song@linux.dev, akpm@linux-foundation.org, shuah@kernel.org, rdunlap@infradead.org, corbet@lwn.net, osalvador@suse.de, rientjes@google.com, duenwen@google.com, fvdl@google.com, ak@linux.intel.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, Jiaqi Yan X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 24DEB180019 X-Stat-Signature: if6qb3kp7bdx496bk95diu41ehfq67op X-HE-Tag: 1719608401-213284 X-HE-Meta: U2FsdGVkX19aPXLBns1NNukW2DwdBDBJkKxQubIUVPE81XOl8fI5XHAE+Jip0klB50vmEDoZQi0dVt/oiON3u4UnMZNyOdHmumCnWUGQ0l+B9rGhbHHs6fh8UqTaVKL+yeZZ19qEdQEO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L6D9BNIchj3CP9DLCiCVrnnJZ7LaNYdryKrBJVNJfASB1WwhOcxIzMITwmvdzPqJM+R+j4jX3r1fFTMpTtGeqZp6NSatk/Kb3EN537Oxj7lAbUfmMAKFuT0NWFDVqRbVjT0YLCxO30fWzOVbBjHBq7HcWM+JEAnGSw6KCmTelABOZHnp0eIzGDEGUXtR/bG60nTNhJtTWMHUhvCd6d6FxcyjTTXx9n50+uocR+pFgFOlyxdZ0/lZ3g+ysMe9bAuyV+ZJpPEDDlHCJPo8H46BmdsLZMACpzpPW6N56wbks8dWAQTida/0x2AtB8CCX7U31sePSje2xGBIRIU9jskpv0B4KyD0O1eG8VCV08dO9DbQniYpf+n9LzuedZkGL1/Ff8Bct9X/MrmWe1SSZR2AudiEWK6j8XIGlsBOEYY6JCMLdQqRab5Felq56JVJwx4n7GM4lqeCnZsb00DqBGPQS6fYOIx+9bkVDiOArHUiiGokU6hVY22Hny07tKjw+wIDgzce+YSIh4Wkx5ohh83q5D2QEEUH2lTb54sdDxDFDCo9uEw8Qi/KkgSKoQ8U= 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, but with two pain points to users: 1. Correction usually happens on the fly and adds latency overhead 2. Not-fully-proved theory states excessive correctable memory errors can develop into uncorrectable memory error. Soft offline is kernel's additional solution for memory pages having (excessive) corrected memory errors. Impacted page is migrated to healthy page if it is in use, then 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 mmap hugepages MAP_FAILED 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: 1. 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 patch series give 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 called enable_soft_offline under /proc/sys/vm. By default enable_soft_line is 1 to preserve existing behavior in kernel. Changelog v6 => v7 * incorporate feedbacks from Miaohe Lin and David Rientjes * remove PFN value from enable_soft_offline log * save/restore enable_soft_offline in run_vmtests.sh * v7 is based on commit 7c89bdbd3778 ("khugepaged: simplify the allocation of slab caches") v5 => v6: * incorporate feedbacks from Miaohe Lin * add a ':' in soft offline log. * close hugetlbfs file descriptor in selftest. * no need to "return" after ksft_exit_fail_msg. v4 => v5: * incorporate feedbacks from Muhammad Usama Anjum * refactor selftest to use what available in kselftest.h v3 => v4: * incorporate feedbacks from Miaohe Lin , Andrew Morton , and Oscar Salvador . * insert a refactor commit to unify soft offline's logs to follow "Soft offline: 0x${pfn}: ${message}" format. * some rewords in document: fail => will not perform. * v4 is still based on commit 83a7eefedc9b ("Linux 6.10-rc3"), akpm/mm-stable. v2 => v3: * incorporate feedbacks from Miaohe Lin , Lance Yang , Oscar Salvador , and David Rientjes . * release potential refcount if enable_soft_offline is 0. * soft_offline_page() returns EOPNOTSUPP if enable_soft_offline is 0. * refactor hugetlb-soft-offline.c, for example, introduce test_soft_offline_common to reduce repeated code. * rewrite enable_soft_offline's documentation, adds more details about the cost of soft-offline for transparent and hugetlb hugepages, and components that are impacted when enable_soft_offline becomes 0. * fix typos in commit messages. * v3 is still based on commit 83a7eefedc9b ("Linux 6.10-rc3"). v1 => v2: * incorporate feedbacks from both Miaohe Lin and Jane Chu . * make the switch to control all pages, instead of HugeTLB specific. * change the API from /sys/kernel/mm/hugepages/hugepages-${size}kB/softoffline_corrected_errors to /proc/sys/vm/enable_soft_offline. * minor update to test code. * update documentation of the user control API. * v2 is based on commit 83a7eefedc9b ("Linux 6.10-rc3"). Jiaqi Yan (4): mm/memory-failure: refactor log format in soft offline code mm/memory-failure: userspace controls soft-offlining pages selftest/mm: test enable_soft_offline behaviors docs: mm: add enable_soft_offline sysctl Documentation/admin-guide/sysctl/vm.rst | 32 +++ mm/memory-failure.c | 37 ++- tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 1 + .../selftests/mm/hugetlb-soft-offline.c | 228 ++++++++++++++++++ tools/testing/selftests/mm/run_vmtests.sh | 6 + 6 files changed, 297 insertions(+), 8 deletions(-) create mode 100644 tools/testing/selftests/mm/hugetlb-soft-offline.c