From patchwork Tue Jun 11 21:55:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13694213 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 3A483C27C65 for ; Tue, 11 Jun 2024 21:55:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC21D6B00EA; Tue, 11 Jun 2024 17:55:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A71C06B00EB; Tue, 11 Jun 2024 17:55:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93A166B00EC; Tue, 11 Jun 2024 17:55:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 76F796B00EA for ; Tue, 11 Jun 2024 17:55:51 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1D4611602BB for ; Tue, 11 Jun 2024 21:55:51 +0000 (UTC) X-FDA: 82219965702.27.92418DE Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf11.hostedemail.com (Postfix) with ESMTP id 5B2474000E for ; Tue, 11 Jun 2024 21:55:49 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=pTNn2z8J; spf=pass (imf11.hostedemail.com: domain of 348doZggKCFA10s80Gs5y66y3w.u64305CF-442Dsu2.69y@flex--jiaqiyan.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=348doZggKCFA10s80Gs5y66y3w.u64305CF-442Dsu2.69y@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=1718142949; 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=Jj8YgqrXbXlWU/XVvADXYq9uceGyByggX91FE/iL3i0=; b=Br1OFjOA9H/3iAdMQwa7iilJTS+PbdsLMzS4Rvaz65ISgoEYMjRFrnf/cagCX2SGlNmJix obyXX6+1PAF3JQwymgR10wNbqZSk4WeghfnFf0GPHAs908Sxcd587IVh63tXdh2KEQAsqk PqBrhmGQppGDk3bv0vtgjplT0On4cFU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718142949; a=rsa-sha256; cv=none; b=KmakgRds5mqmRgWwJpE0wZSBmil1mPtdIGfMdihxXjJnekLCxCLzYcW7zJDg2PaiXW4zHu RKUX2z4svRNLWXNW2qz5sLTFpEQrWwu+Rkp7AoaI1qE6CONlsLL1ZneUwJHYr3VEXpeTc4 xX/DycQ0tq8ma1PEGNMC4Ptz1K/8AjQ= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=pTNn2z8J; spf=pass (imf11.hostedemail.com: domain of 348doZggKCFA10s80Gs5y66y3w.u64305CF-442Dsu2.69y@flex--jiaqiyan.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=348doZggKCFA10s80Gs5y66y3w.u64305CF-442Dsu2.69y@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-1f6dfbec85aso40238275ad.2 for ; Tue, 11 Jun 2024 14:55:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718142948; x=1718747748; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=Jj8YgqrXbXlWU/XVvADXYq9uceGyByggX91FE/iL3i0=; b=pTNn2z8JHVSfRnocVhpfWVG4lUcRtmSaQ9BkYgSK0WuyPVXtZwA5TMNTFHks5ZV37+ k51x2qjfXr1RuAeppm9jR8gKntUIsbhtfKYgOVIsugJBIa28e+2H3Wujt3P8DouF8Fin 3No5w+EedDL8c611l3dpeOupk/FI7nNdWsymee0R1pE3PLdaiHs6fj/S0MUFx5sXntmE uK65S95F0wtf5Zb/4bkJJwl6Gg1lE1xfVc0xWbDUf6yGCDKNMW8WrsN16Em88oGMg87c eVbefUgLL+34SO12E09SoGhhhKzv5hfzKKADe0FpiKrFhjMq9PAHyGXdO782mRzgHkDw RbQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718142948; x=1718747748; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Jj8YgqrXbXlWU/XVvADXYq9uceGyByggX91FE/iL3i0=; b=piIwOhSl3giRHz3V4z1jqeKGXxA6jMG85kBJw9cymPyVX8hrcYa8EVa2ogLx5YTnyb IDvfZycT44VKzVuhJVlWjFXUf+Xd++5fkj9tLnik1BFcRRjzyEfIKWy/eXRUt2fU/G7D yCarr4lNCi6FfXsFUF7RRGUoJ3iMH3Qg+M5WukAZ+bCImFebUEoHa7mVyI4bcsgtrVOx cP7upz3Vjx71BOTXjZ++xLwWtd9QUsWZGexgmc+SkG3bnHNAZjPHK1clFXpdv/wzDnHq LulvGGcEyuGOIRb6FbJHyT1scznbPRr5B2jwjyM6UlQ6SWlHZeIENOqJii8nBKWpeosd ofmA== X-Forwarded-Encrypted: i=1; AJvYcCVdeHzaMRiZu3BsGw4kzau3J32ikvN6dYI6arO9aapTrFp091WcFMRD4NcQW2Is9xvqnT9AjpzANTQiHXuarPoMbfU= X-Gm-Message-State: AOJu0Yzm+s6yUBoiYPS2BzoPpAGDCW8Cg8GEz7kM4j4krR0Sujnpix9U EIm37ICJlq22laMS95EjAEzfh+ZDhAdrtLmcWwcalkVz3XsiYeCPq0cguxvVaa3qrI1F24gwILg x+cxf5ftubw== X-Google-Smtp-Source: AGHT+IEYPPG9JfHp7uLek7ysPZ+oTxIHFHCXuoWTRFqA/sqnS6jFOn+oGbLU6U4URlsA1/KoSA1/1J+iH4tRJg== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a17:903:22d0:b0:1f7:165f:3eda with SMTP id d9443c01a7336-1f83b55b13bmr5265ad.5.1718142947927; Tue, 11 Jun 2024 14:55:47 -0700 (PDT) Date: Tue, 11 Jun 2024 21:55:41 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog Message-ID: <20240611215544.2105970-1-jiaqiyan@google.com> Subject: [PATCH v2 0/3] Userspace controls soft-offline pages From: Jiaqi Yan To: nao.horiguchi@gmail.com, linmiaohe@huawei.com, jane.chu@oracle.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-Stat-Signature: zwe3xhgziq5zxfu7ufh7ewnr3e43izes X-Rspamd-Queue-Id: 5B2474000E X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1718142949-780760 X-HE-Meta: U2FsdGVkX18yHLIuLjf42bLOVAneWGRzRr4bQHLQtZvhlQQTpccwfKrnsN4sYWMqTvddG1O7RnN2hrlJrylHUmBzvFnE+88QUBI+6O3w7RujJ6Jq3+gsYYmBNfYpj/T0+OHrsXVDeHtDBfa4vmnqfK3/KMClXKoMAxEoaqpdCwp7lbVf5oI9xPG4P95sFxnki7y5tHV8kOrJ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vPii92X0DvuTm006VXZTOIq7hdHbyDe/s5pTKxrAx/6HjB8Abp6nbyPerrA7W3HXTjIV3nkSYvb1jaYUgvZhPeyOAeiJ0SF4yAVexQCQ16jOXVHLMM+aY6GfTZh5qeg9rnUiMGg/QbtBMNC/Eg/hQ50NQXxn4kFpJ474SW03Rv39ynvaobAL7fgxHNrXN+yWUjxeCazjI4bEogW9+gRGvVfc6Dvp4d7bTobP64SpTJDo+ceNGcHmHZvmmLoDVNBE3jYQch7aq6GZgg7PfjCpvmJ+dDo8OrAYHOYL69zl7lKybT9pPcGnOFQx53fNCH3i5MOwqjVqTMJtTR07WESQFRg== 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 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 | 15 + mm/memory-failure.c | 16 ++ tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 1 + .../selftests/mm/hugetlb-soft-offline.c | 258 ++++++++++++++++++ tools/testing/selftests/mm/run_vmtests.sh | 4 + 6 files changed, 295 insertions(+) create mode 100644 tools/testing/selftests/mm/hugetlb-soft-offline.c