From patchwork Mon Jun 17 17:05:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13701090 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 5256DC27C79 for ; Mon, 17 Jun 2024 17:05:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E13E6B024C; Mon, 17 Jun 2024 13:05:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 990296B024D; Mon, 17 Jun 2024 13:05:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E2436B024E; Mon, 17 Jun 2024 13:05:54 -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 612616B024D for ; Mon, 17 Jun 2024 13:05:54 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EC0A5A19E0 for ; Mon, 17 Jun 2024 17:05:52 +0000 (UTC) X-FDA: 82241007744.15.AC67741 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf02.hostedemail.com (Postfix) with ESMTP id 3196180017 for ; Mon, 17 Jun 2024 17:05:50 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=cqQi9+Za; spf=pass (imf02.hostedemail.com: domain of 37WxwZggKCMIrqiyq6ivowwotm.kwutqv25-uus3iks.wzo@flex--jiaqiyan.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=37WxwZggKCMIrqiyq6ivowwotm.kwutqv25-uus3iks.wzo@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=1718643947; 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=v7FfUmROvXWPzNqZLzmg1Chpa3PlFFTPBJMZ6K8GE4k=; b=N+QDiFol9GXM03XZJPvIUIk0eGdN3rceotdRDRwG8ReMb97O3O1QXK3rYuHjnNvRc4Z/Dv FwWcrskarWrpRDO9RWIPzszOQ4S2KFKJzzDk8auMiH0yYN9NPmVd1WR3ztdjNrU6Gcwd1E LIJapC1aJDmOggglvEWbkWYb/zDuFPs= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=cqQi9+Za; spf=pass (imf02.hostedemail.com: domain of 37WxwZggKCMIrqiyq6ivowwotm.kwutqv25-uus3iks.wzo@flex--jiaqiyan.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=37WxwZggKCMIrqiyq6ivowwotm.kwutqv25-uus3iks.wzo@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718643947; a=rsa-sha256; cv=none; b=R5d20bSW6B/SXwm63UQCrddSFW6dH5W6PYqx3V8JDp6uNIkElKaKKKFlme8y7KkI7DXjsL iL2YQ6ti/olheR8oWQzAmnZ/77mAu72MG5ZMYIBPDf4Xm017vGAQHJZ+xWJPecBz1UxH9E Z5tTeHIxN1zBhpwlgdJlA7BW0RUuqm4= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6338f71a577so49192607b3.1 for ; Mon, 17 Jun 2024 10:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718643949; x=1719248749; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=v7FfUmROvXWPzNqZLzmg1Chpa3PlFFTPBJMZ6K8GE4k=; b=cqQi9+ZaLqnI5fucXpM+Z22HvXXslIUtYCpnKoJtygWFy2md3V5ZGqz82QSVo9VWNH CPvPnyW+1gqxfaz3hiOtKzjMJcO+m3yLwR1ukMObCbSgcztwgII8fZzgaTCgUEtCMVOl hJBPw0/Mgg1tLN0gbB6zC1ZlW8TLVLOsFxq1V31tzzGlwOgYpn+5HOjdhli6EKJooccV sluEq/WKI2YPDlALKby+FBzPw4jDDO6DaegaaFh+j+h+Js2wRGCzwFSnpb+ehJOiZrgR zJyCd4OU4TqgFHOXb7JTwfW8zsn4gYr5xc/bnf3EgtxJ5PFQfApfuGlRH18LiBEVIWr7 2Pxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718643949; x=1719248749; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=v7FfUmROvXWPzNqZLzmg1Chpa3PlFFTPBJMZ6K8GE4k=; b=kvRFod+FkwVWTbqydYpugz/K0jjrGJ2U9BHo9KOAYISGsBETsYssX5pVi/Z5+GNoBn 9nLFkSwGEMr1lGbzw9OQDT/8WBC9yIfcUFZyGM/bOsxQFvBhUeLZP0BjuMB34HGYo6Tj QPvnJPMf94FdaJRGizCgvo08r+X00EYKiuAT4dbEZex/TlPuYlpOLeMZNZjmFlbDQqLT ovj2UNR7aQii4OXFSoSqNfy2vIEfTGMoqraHjjtGo+GSYE9FdKyQqRXCU1PHK3F9b1fs j0kUAh0/yrAqb083NOLl4LBLpWiogvVuDPjMo9HkODR8/1JwjipGBV3VFAr0MRyNuKat NQUA== X-Forwarded-Encrypted: i=1; AJvYcCUtOq7435qLGSx9KZ0qsxsXLg8dc44f948UGluGbKeWkr19IC42LMwttd4ff2+hKUe3TOyayyTe7MAiuna4RmgXSrM= X-Gm-Message-State: AOJu0YxMH6lAUDeIE14kxJXPNYWgjwJaC0mdrhzDn70oOuqBrKHcnyys DtbVSlD7P01WBWYIwRZIUcm/jOvAxsnnVMhSovxwq1Yl0melnymJuz7jhQXq+GKHSw4G+Bes8xb j/a1xP8NROA== X-Google-Smtp-Source: AGHT+IG6R2axixGQhhzTe7v99HTPI+dX+xPnuaKeod6jwj6XeI/di+Vqf4aBYtfcMff+UqyPSeISN4w3QpoWsQ== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a05:690c:4805:b0:631:9b3b:525d with SMTP id 00721157ae682-63222b588bdmr27182107b3.4.1718643949130; Mon, 17 Jun 2024 10:05:49 -0700 (PDT) Date: Mon, 17 Jun 2024 17:05:42 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240617170545.3820912-1-jiaqiyan@google.com> Subject: [PATCH v3 0/3] Userspace controls soft-offline 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: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 3196180017 X-Stat-Signature: pcif7o9ni3nj4i6gd9qubfwpijt56gpd X-HE-Tag: 1718643950-508246 X-HE-Meta: U2FsdGVkX1/nyNGQAS8XQM43soIJdbG5hMCMGeNr2PISFhv5YhsGoL/mnQl3/X+kyLFsjt4OuQcdVjPI9G2E/M16ssOtITqxcNvaDThugJ0g26lHQ/q1JaS/vUHHS/53A9ICJPN6UUTnsY1LJBiRZjuY07xGTLvhjU03nuPgM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HjU3k+7/2orCYmhgS6TloF6gyjqzs4lstcV9EzZ6CiKnWn++QHa9WDUgw3yh2GMqM5FcrpLZwqCzfnq9kgA063gnnakFq/0VH3N/JLKIK0YJyq3zbm+uboToDAgxEBNLjmNhscVOXAY7m590weScy4HJe/i4MZByX3+YKszYA+3eRCFzpJqRij2O5jJvF8XprxKZAloFcWnJGl8TAiJNVyxW17gcsmB7YB+xKXZgiwWoMLjshAak7wbNm+Kv6Di31l7u/CiLP/4t15NzYPPa7LjFB8f9A0sa54IM6n4sh5aHRiqJerauw4k4LmwNvaTP/Yblad7K3R3+UoFDXQB2n5tLBYIyqtpoFukSd1FheCF147ee930+gkOg1py8HxH91dO8MOZG7IQIJvtosYs9Z 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 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 (3): 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 | 33 +++ mm/memory-failure.c | 22 +- tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 1 + .../selftests/mm/hugetlb-soft-offline.c | 229 ++++++++++++++++++ tools/testing/selftests/mm/run_vmtests.sh | 4 + 6 files changed, 288 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/mm/hugetlb-soft-offline.c