From patchwork Mon Jun 17 17:05:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13701089 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 EB2B6C2BA18 for ; Mon, 17 Jun 2024 17:05:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43AB16B024B; Mon, 17 Jun 2024 13:05:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3EA3D6B024C; 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 28BCD6B024D; Mon, 17 Jun 2024 13:05:54 -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 08B066B024B for ; Mon, 17 Jun 2024 13:05:54 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A1F101C33B9 for ; Mon, 17 Jun 2024 17:05:53 +0000 (UTC) X-FDA: 82241007786.15.BA5BD12 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf26.hostedemail.com (Postfix) with ESMTP id C8804140010 for ; Mon, 17 Jun 2024 17:05:51 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="rH1ir/SE"; spf=pass (imf26.hostedemail.com: domain of 37mxwZggKCMMsrjzr7jwpxxpun.lxvurw36-vvt4jlt.x0p@flex--jiaqiyan.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=37mxwZggKCMMsrjzr7jwpxxpun.lxvurw36-vvt4jlt.x0p@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=1718643946; 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=KM/EmQyPzaIKRRU3lBo3RyHuJehGBp5I0jJwxKmg0Wk=; b=hvVP1M9HRUPSnQWyIVItDDtGwIDbuhhPxheptlBOfTW5PcXI4TC9eNZ3196eWhD5khH7PU j/h40zvZk1PSNenMsLvN/2rYHUUPg+YbBc6cQJVXrjPbOw0kr2CgB7/mV3UPKv/DNPw3NT +wt+ZTtlfeLO84hdddTg2QwNSagdnUg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718643946; a=rsa-sha256; cv=none; b=sqY2H05239UdzrA8iJv8t+X6cX6mNtmAZmFtaSVKw/TmE7zXNCIWo13Ie53tmT1IWBCzST lU3+V4rhTBEYBP/dxRnziLyRA/yCDvBM3ZQYzJJ3aTsj6+wl9LEjEuOa+h4gf1Tvez256W MVri+Uuvq+LxopUSiD6rj1ljWz3UdS0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="rH1ir/SE"; spf=pass (imf26.hostedemail.com: domain of 37mxwZggKCMMsrjzr7jwpxxpun.lxvurw36-vvt4jlt.x0p@flex--jiaqiyan.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=37mxwZggKCMMsrjzr7jwpxxpun.lxvurw36-vvt4jlt.x0p@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dfeec5da787so7960072276.1 for ; Mon, 17 Jun 2024 10:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718643951; x=1719248751; 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=KM/EmQyPzaIKRRU3lBo3RyHuJehGBp5I0jJwxKmg0Wk=; b=rH1ir/SE6wfzQWh0Kk6j2t505bhJIoBwgXmy2aGwjPA1VZJ+UKkDFdcF+kpCdS9C/Y oXS5YbF4OgOLeA1ZkuCozNF6wX8YZH0zPMcH1Z3Bmfq8phpE7QvA5H39k9pI9MBi8fax VvxLrMZdFKEUsBT0MLPcq0EnP9p3+K3+txybuZ3uJdufsFsHRjAZivrcdDj7HsVk7+d0 2VhjThYwuyt1aNSq33dx/bsylFFy16chDLZidcKGIphzkNiCJUoZwv4mywaaWKaQKeBY SkWTdB6kaKlT4g6dsbsZ6WOMKbsZvxPB5MO/9nSSGuxDqQ8o95jpIWRUfphqYHBcx7Im BgZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718643951; x=1719248751; 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=KM/EmQyPzaIKRRU3lBo3RyHuJehGBp5I0jJwxKmg0Wk=; b=LRQqzHSVaupxMlXmrvX+N5HUBSGbIFtgnJMy7Ne6el4+LaMRuNDqmESy76VOMQP+2p /0wjEVQpQmLizM3WEATuCAwBP+g7bgTC6dvx7/koI30eAreYmJWEkTjcMcZa1WuGbQvf gdo67nDQz7AmfqX4RVA0uOTwzm0lBmTmcnAH6jPoEk7+WM9kyiOXlMKSbQ1XnE/fQEFV RNvkzhVM3fgVLG6X0ViGlLSMv76Sp/fdfShAiwI7/BtP5+d8o5sZ7Whk30Nfyk4gEmXj A8EV6VMlG3+p7W4DZwGYJN8kbrO5PHctFqckgtxh3HTbBJxuoWwEqLqlj1KAHZvIGjZj d4aw== X-Forwarded-Encrypted: i=1; AJvYcCUmK/P7z7H2Su1fdZL9Bkt7chAP7jls/4N/A2GI83nNQqvcdRbuHEzH0z31SLVk2PfDvXs8RGgu5BdcW9k8YULsaAw= X-Gm-Message-State: AOJu0Ywl1ekklt357dkZOGQTraR2kM25c9bWUTNfyy8ebuH/Br2ZI4Ed kQayJGfptiD3KkeFSh5Kbsn/KNnEIkFVXOjMYLkISEwqd3gLrF1HXfOegFLkcFo77f8UIYU8zWX ASo/JIh/6Cw== X-Google-Smtp-Source: AGHT+IE6i7AwPAxo0OUUZFk9HFUB3axExctM9lLZOhHsVMPD9MZ5+BUeIdWtDZUhg3QZQeglebomfhWpC7C7uw== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a05:6902:1242:b0:dff:2d92:d952 with SMTP id 3f1490d57ef6-dff2d92e760mr569722276.9.1718643950758; Mon, 17 Jun 2024 10:05:50 -0700 (PDT) Date: Mon, 17 Jun 2024 17:05:43 +0000 In-Reply-To: <20240617170545.3820912-1-jiaqiyan@google.com> Mime-Version: 1.0 References: <20240617170545.3820912-1-jiaqiyan@google.com> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240617170545.3820912-2-jiaqiyan@google.com> Subject: [PATCH v3 1/3] 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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C8804140010 X-Stat-Signature: ntoi4h88bngezf6m5u4ztxa9gyizk3te X-HE-Tag: 1718643951-622771 X-HE-Meta: U2FsdGVkX195YHeG3Nhf65ED/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YooydSea2S/6Cvso+KlIdCO7qlfofbhUpMvJUx6/7UwMuppHb+sd8SvwwZC5mioEIgs0nLiY7dOqYTugM4Pfi4tJfuGaxcYirR4DBGace/vBYJeZSt1ou8g31ACBtiFaqkndnZ3a+40wz5AOlXwYVg4DYn9F7gvxHo1wQH0a4CqP+xsNuOBIGA+FeGpcU2W6hdDRC+DLZlze0R0s6gvM72eRPlw7j1/v1Q2UitNHQnqONMJoSJpZRmt+abtItFSVENd1pNQBUp05DadQRut4rikK6rCtnfZ7/H2zR7sOrg6H5cH0MMvSHB0DtyqMviBqqdVGXf8X19J3lLHGSNkra4mBvidCGXPfQr5OxtOURoEIXmD6qbDfOhDHg0NZiZZuQ4tXznTR07KsB8b4xV2MzikzqhyB/+6OmwcuR6KBL25LSRedTN50O+v1srCaPGFF18lVl5tHqZIMVeIyadS3a8jZpKBtY7H5vs93yR/qFNhs5hR2hhraHg 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 it is in-use; 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. 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. Signed-off-by: Jiaqi Yan --- mm/memory-failure.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index d3c830e817e3..9eb216ed0b86 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, + } }; /* @@ -2746,8 +2757,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, + * -EOPNOTSUPP if disabled by /proc/sys/vm/enable_soft_offline, * < 0 otherwise negated errno. * * Soft offline a page, by migration or invalidation, @@ -2783,6 +2795,12 @@ int soft_offline_page(unsigned long pfn, int flags) return -EIO; } + if (!sysctl_enable_soft_offline) { + pr_info("%#lx: OS-wide disabled\n", pfn); + put_ref_page(pfn, flags); + return -EOPNOTSUPP; + } + mutex_lock(&mf_mutex); if (PageHWPoison(page)) { From patchwork Mon Jun 17 17:05:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13701091 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 895D8C2BA18 for ; Mon, 17 Jun 2024 17:05:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 798AA6B024E; Mon, 17 Jun 2024 13:05:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 721F66B0250; Mon, 17 Jun 2024 13:05:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54B8E6B0251; Mon, 17 Jun 2024 13:05:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2B4526B024E for ; Mon, 17 Jun 2024 13:05:56 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9FDF9141953 for ; Mon, 17 Jun 2024 17:05:55 +0000 (UTC) X-FDA: 82241007870.21.2EA18A3 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf06.hostedemail.com (Postfix) with ESMTP id BA61618000B for ; Mon, 17 Jun 2024 17:05:53 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=COm3SxIH; spf=pass (imf06.hostedemail.com: domain of 38GxwZggKCMUutl1t9lyrzzrwp.nzxwty58-xxv6lnv.z2r@flex--jiaqiyan.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=38GxwZggKCMUutl1t9lyrzzrwp.nzxwty58-xxv6lnv.z2r@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718643950; a=rsa-sha256; cv=none; b=nGvqbKT6TKEKxRB+DJ4lTTMykUNXgezoUA+gvBFfYOnfNa7dNL6/hL1I8Vqpmer0OA0J7M xzZcGs4o/U6DjFqh/BH3oGQ/r3DVyPacR04Vj86shus2uudeRYc/XRYhhvKxNwMXAi/Trb 6wmuiqtiTzlsbTHqz6zoeAYiwOCTu48= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=COm3SxIH; spf=pass (imf06.hostedemail.com: domain of 38GxwZggKCMUutl1t9lyrzzrwp.nzxwty58-xxv6lnv.z2r@flex--jiaqiyan.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=38GxwZggKCMUutl1t9lyrzzrwp.nzxwty58-xxv6lnv.z2r@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=1718643950; 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=1tevmA1HCzsTVLfVkW48VuStWY2+98Ib3ji+6cFhdVU=; b=hnjCBXcMpHia8mFYG8Di6D1nwq3o3+yzfmQwLgka2uU2od4S3lhWXaFQ2O9/7orQA3q2gS GX8qdJpQ5zG/nlJe/sbsaR7EjAWy9236xIpCZFO30uxwOP2FFVoXfsVNHp9OHOkRoyGinE bN2JAhQxNbJW2IGlxOzJSsvZJrtB2Ik= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dfeac23fe6eso8976023276.0 for ; Mon, 17 Jun 2024 10:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718643952; x=1719248752; 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=1tevmA1HCzsTVLfVkW48VuStWY2+98Ib3ji+6cFhdVU=; b=COm3SxIHP4U7onT3Yju893LAlS41gRbKT/fbqn59NS1joayfaShmdZUvFWkK8C39tH /EO0Yb4KhNschF5lHR0cEepg7a+MVU/lCS45Yj5ktQq9R/3GVjo0X1SfPvkcChOA6JWg 7CSYHueID9gG4Lt4PGvGrtiysyDVHpVmixe4b+kVPLMYG6zTku965iVjU9UH7zDuvbCD 5wbMZc//1y22RMqtTkj5ySrfLH3mkfpTyBt4C2xXtBAmXOHSeWfeGe9Yq1Uhj/QT6EM/ dJFf0lv+BrMVMuWDpGUFh5U+KdAV2WvIaerT4+LMo2U3buOmEs9smB3O7Ju0+BHZhK1b UxnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718643952; x=1719248752; 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=1tevmA1HCzsTVLfVkW48VuStWY2+98Ib3ji+6cFhdVU=; b=KueyMajz3nOcnLU/rLnw7E6LT9gPj9haWWjhROtMHcxeTA8zj8GO40useS2A07qwKq BzFPwAXT/ubMP0+bQGDa4PMdoHKAczoCoZxGAUiQeJ6BOuDsdOMEZwMVUA5Ka9sySekY 2e0I0nRCTioRYWpo9nEPPPl6BxJz+dI7hUb7U6iTiO2gyf7AQvZBlFXY0uj69CMYJsM2 AnBVQE5p0p/1cYBHYr6KSS/dsZM9NsFuU+2VBcX3etPSFTxQPALx/jqqMeOlWSHcOI1c 0NrEMHtdthetMgtI0m/EuGgqMmM/lXJiNonWwu4YVrj3oVWWD0p5EeZZWT9HCgzlB71u GXtg== X-Forwarded-Encrypted: i=1; AJvYcCXZd/5zOYDw6vXzyxWCuxPKZkFdqx3Co4Et9ne+nRKXc5N2BLeBpNi7UR19xs9+ZVlxQRymTN8JitRAS41Cb/iIcbs= X-Gm-Message-State: AOJu0Yy1Q5jef2gg56NNLa7wLfcD2kwEfAZj5Qa4fOEpPKT8F9wJ029F qMfF3WigqBorlQ/gKH1x728skqfn7Db7Ni0I3H7sP2fgda2GCMkT7dv5G4pTKZM9Ql7lRpQPyPt BgAJc01tKZw== X-Google-Smtp-Source: AGHT+IHaPH860LoxB8KdOgFhvqZSzGViBlD2JGwLQiFXTHzuc4xC+T3rNtkWpuJIT3TcVn/I2RZqtycsHAYZ7w== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a05:6902:110e:b0:dfa:b2ca:7a9e with SMTP id 3f1490d57ef6-dff15456ffbmr3225706276.8.1718643952522; Mon, 17 Jun 2024 10:05:52 -0700 (PDT) Date: Mon, 17 Jun 2024 17:05:44 +0000 In-Reply-To: <20240617170545.3820912-1-jiaqiyan@google.com> Mime-Version: 1.0 References: <20240617170545.3820912-1-jiaqiyan@google.com> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240617170545.3820912-3-jiaqiyan@google.com> Subject: [PATCH v3 2/3] selftest/mm: test enable_soft_offline behaviors 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-Stat-Signature: f6midkr1gx4aepohefza4bn3nkwt6e3y X-Rspamd-Queue-Id: BA61618000B X-Rspam-User: X-Rspamd-Server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Pfiov7/vl4VgkaY/VSxmkkhDAX2SkQtqx4jceO+FqK3DVUIhXeyJ5gMhhkKlUaijIdqXRY6OnksxBDr84VspM3TXpHLgK+LbTDT3qAA2DejnZP6jQX1UxKUMFm+PxVKXvvPslMpNB2BhzuJoMaVejcqWbMRvX50FI5obdOR40xMerMmuWoJYuvkKBBUxqIIu9vvI9Ze15/c+/BqcMxpCFOUHoF3wP6OXLhAW0GYpkHdMXTIu9uL/XmX+UyuAEOGL397gPYNfFHQ+K8oV5yXAWEcdkLb7Zz6j2IyLjt9UXbf7FTYjDl3Q3ZywNOnITT0yX7KQyUB3dNjazTbWwFzP/ATKtIRH247o0UeKgRTW9AdyZ5sUGTprzh6eJqpwYEtjnTBd59zSoLvKtcUZnaTl6KR+zp3My7yktgHqTSDr2VvEafBJZlpqbsh6pZ3B/nmwro9cz3sQdijexMl1kkcBpBB6p2SbGMhnAgydAVz2GHeFaCuWlUqk01Btws0ce4UiSZrGWLFatiJYGex/7sx00iPv79iW/c87YG0C9nt1KPGyuE8wm77dZFSoW4WFHAYt0vYfDZJD38cJX9f2N3kJr0nGidsBtWcHaqFu4LeSoQ== 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: Add regression and new tests when hugepage has correctable memory errors, and how userspace wants to deal with it: * if enable_soft_offline=1, mapped hugepage is soft offlined * if enable_soft_offline=0, mapped hugepage is intact Free hugepages case is not explicitly covered by the tests. Hugepage having corrected memory errors is emulated with MADV_SOFT_OFFLINE. Signed-off-by: Jiaqi Yan --- 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 + 4 files changed, 235 insertions(+) create mode 100644 tools/testing/selftests/mm/hugetlb-soft-offline.c diff --git a/tools/testing/selftests/mm/.gitignore b/tools/testing/selftests/mm/.gitignore index 0b9ab987601c..064e7b125643 100644 --- a/tools/testing/selftests/mm/.gitignore +++ b/tools/testing/selftests/mm/.gitignore @@ -6,6 +6,7 @@ hugepage-shm hugepage-vmemmap hugetlb-madvise hugetlb-read-hwpoison +hugetlb-soft-offline khugepaged map_hugetlb map_populate diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index 3b49bc3d0a3b..d166067d75ef 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -42,6 +42,7 @@ TEST_GEN_FILES += gup_test TEST_GEN_FILES += hmm-tests TEST_GEN_FILES += hugetlb-madvise TEST_GEN_FILES += hugetlb-read-hwpoison +TEST_GEN_FILES += hugetlb-soft-offline TEST_GEN_FILES += hugepage-mmap TEST_GEN_FILES += hugepage-mremap TEST_GEN_FILES += hugepage-shm diff --git a/tools/testing/selftests/mm/hugetlb-soft-offline.c b/tools/testing/selftests/mm/hugetlb-soft-offline.c new file mode 100644 index 000000000000..5701eea4ee48 --- /dev/null +++ b/tools/testing/selftests/mm/hugetlb-soft-offline.c @@ -0,0 +1,229 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Test soft offline behavior for HugeTLB pages: + * - if enable_soft_offline = 0, hugepages should stay intact and soft + * offlining failed with EINVAL. + * - if enable_soft_offline = 1, a hugepage should be dissolved and + * nr_hugepages/free_hugepages should be reduced by 1. + * + * Before running, make sure more than 2 hugepages of default_hugepagesz + * are allocated. For example, if /proc/meminfo/Hugepagesize is 2048kB: + * echo 8 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifndef MADV_SOFT_OFFLINE +#define MADV_SOFT_OFFLINE 101 +#endif + +#define PREFIX " ... " +#define EPREFIX " !!! " + +enum test_status { + TEST_PASS = 0, + TEST_FAILED = 1, + // From ${ksft_skip} in run_vmtests.sh. + TEST_SKIPPED = 4, +}; + +static enum test_status do_soft_offline(int fd, size_t len, int expect_ret) +{ + char *filemap = NULL; + char *hwp_addr = NULL; + const unsigned long pagesize = getpagesize(); + int ret = 0; + enum test_status status = TEST_SKIPPED; + + if (ftruncate(fd, len) < 0) { + perror(EPREFIX "ftruncate to len failed"); + return status; + } + + filemap = mmap(NULL, len, PROT_READ | PROT_WRITE, + MAP_SHARED | MAP_POPULATE, fd, 0); + if (filemap == MAP_FAILED) { + perror(EPREFIX "mmap failed"); + goto untruncate; + } + + memset(filemap, 0xab, len); + printf(PREFIX "Allocated %#lx bytes of hugetlb pages\n", len); + + hwp_addr = filemap + len / 2; + ret = madvise(hwp_addr, pagesize, MADV_SOFT_OFFLINE); + printf(PREFIX "MADV_SOFT_OFFLINE %p ret=%d, errno=%d\n", + hwp_addr, ret, errno); + if (ret != 0) + perror(EPREFIX "madvise failed"); + + if (errno == expect_ret) + status = TEST_PASS; + else { + printf(EPREFIX "MADV_SOFT_OFFLINE should ret %d\n", expect_ret); + status = TEST_FAILED; + } + + munmap(filemap, len); +untruncate: + if (ftruncate(fd, 0) < 0) + perror(EPREFIX "ftruncate back to 0 failed"); + + return status; +} + +static int set_enable_soft_offline(int value) +{ + char cmd[256] = {0}; + FILE *cmdfile = NULL; + + if (value != 0 && value != 1) + return -EINVAL; + + sprintf(cmd, "echo %d > /proc/sys/vm/enable_soft_offline", value); + cmdfile = popen(cmd, "r"); + + if (cmdfile) + printf(PREFIX "enable_soft_offline => %d\n", value); + else { + perror(EPREFIX "failed to set enable_soft_offline"); + return errno; + } + + pclose(cmdfile); + return 0; +} + +static int read_nr_hugepages(unsigned long hugepage_size, + unsigned long *nr_hugepages) +{ + char buffer[256] = {0}; + char cmd[256] = {0}; + + sprintf(cmd, "cat /sys/kernel/mm/hugepages/hugepages-%ldkB/nr_hugepages", + hugepage_size); + FILE *cmdfile = popen(cmd, "r"); + + if (cmdfile == NULL) { + perror(EPREFIX "failed to popen nr_hugepages"); + return -1; + } + + if (!fgets(buffer, sizeof(buffer), cmdfile)) { + perror(EPREFIX "failed to read nr_hugepages"); + pclose(cmdfile); + return -1; + } + + *nr_hugepages = atoll(buffer); + pclose(cmdfile); + return 0; +} + +static int create_hugetlbfs_file(struct statfs *file_stat) +{ + int fd; + + fd = memfd_create("hugetlb_tmp", MFD_HUGETLB); + if (fd < 0) { + perror(EPREFIX "could not open hugetlbfs file"); + return -1; + } + + memset(file_stat, 0, sizeof(*file_stat)); + if (fstatfs(fd, file_stat)) { + perror(EPREFIX "fstatfs failed"); + goto close; + } + if (file_stat->f_type != HUGETLBFS_MAGIC) { + printf(EPREFIX "not hugetlbfs file\n"); + goto close; + } + + return fd; +close: + close(fd); + return -1; +} + +static enum test_status test_soft_offline_common(int enable_soft_offline) +{ + int fd; + int expect_ret = enable_soft_offline ? 0 : EOPNOTSUPP; + struct statfs file_stat; + unsigned long hugepagesize_kb = 0; + unsigned long nr_hugepages_before = 0; + unsigned long nr_hugepages_after = 0; + enum test_status status = TEST_SKIPPED; + + printf("Test soft-offline when enabled_soft_offline=%d\n", + enable_soft_offline); + + fd = create_hugetlbfs_file(&file_stat); + if (fd < 0) { + printf(EPREFIX "Failed to create hugetlbfs file\n"); + return status; + } + + hugepagesize_kb = file_stat.f_bsize / 1024; + printf(PREFIX "Hugepagesize is %ldkB\n", hugepagesize_kb); + + if (set_enable_soft_offline(enable_soft_offline)) + return TEST_FAILED; + + if (read_nr_hugepages(hugepagesize_kb, &nr_hugepages_before) != 0) + return TEST_FAILED; + + printf(PREFIX "Before MADV_SOFT_OFFLINE nr_hugepages=%ld\n", + nr_hugepages_before); + + status = do_soft_offline(fd, 2 * file_stat.f_bsize, expect_ret); + + if (read_nr_hugepages(hugepagesize_kb, &nr_hugepages_after) != 0) + return TEST_FAILED; + + printf(PREFIX "After MADV_SOFT_OFFLINE nr_hugepages=%ld\n", + nr_hugepages_after); + + if (enable_soft_offline) { + if (nr_hugepages_before != nr_hugepages_after + 1) { + printf(EPREFIX "MADV_SOFT_OFFLINE should reduced 1 hugepage\n"); + return TEST_FAILED; + } + } else { + if (nr_hugepages_before != nr_hugepages_after) { + printf(EPREFIX "MADV_SOFT_OFFLINE reduced %lu hugepages\n", + nr_hugepages_before - nr_hugepages_after); + return TEST_FAILED; + } + } + + return status; +} + +int main(void) +{ + enum test_status status; + + status = test_soft_offline_common(1); + if (status != TEST_PASS) + return status; + + status = test_soft_offline_common(0); + if (status != TEST_PASS) + return status; + + printf("Soft-offline tests all good!\n"); + return TEST_PASS; +} diff --git a/tools/testing/selftests/mm/run_vmtests.sh b/tools/testing/selftests/mm/run_vmtests.sh index 3157204b9047..781117fac1ba 100755 --- a/tools/testing/selftests/mm/run_vmtests.sh +++ b/tools/testing/selftests/mm/run_vmtests.sh @@ -331,6 +331,10 @@ CATEGORY="hugetlb" run_test ./thuge-gen CATEGORY="hugetlb" run_test ./charge_reserved_hugetlb.sh -cgroup-v2 CATEGORY="hugetlb" run_test ./hugetlb_reparenting_test.sh -cgroup-v2 if $RUN_DESTRUCTIVE; then +nr_hugepages_tmp=$(cat /proc/sys/vm/nr_hugepages) +echo 8 > /proc/sys/vm/nr_hugepages +CATEGORY="hugetlb" run_test ./hugetlb-soft-offline +echo "$nr_hugepages_tmp" > /proc/sys/vm/nr_hugepages CATEGORY="hugetlb" run_test ./hugetlb-read-hwpoison fi From patchwork Mon Jun 17 17:05:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13701092 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 AD275C27C79 for ; Mon, 17 Jun 2024 17:06:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 997A76B0250; Mon, 17 Jun 2024 13:05:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F4C56B0251; Mon, 17 Jun 2024 13:05:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7218B6B0252; Mon, 17 Jun 2024 13:05:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4B4206B0250 for ; Mon, 17 Jun 2024 13:05:57 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id F2D28120DE7 for ; Mon, 17 Jun 2024 17:05:56 +0000 (UTC) X-FDA: 82241007912.05.CBFD9EA Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf30.hostedemail.com (Postfix) with ESMTP id 31EDB80002 for ; Mon, 17 Jun 2024 17:05:54 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=mM5bNwBE; spf=pass (imf30.hostedemail.com: domain of 38mxwZggKCMcwvn3vBn0t11tyr.p1zyv07A-zzx8npx.14t@flex--jiaqiyan.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=38mxwZggKCMcwvn3vBn0t11tyr.p1zyv07A-zzx8npx.14t@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=1718643951; 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=lmqa+eDYiknLWtQ9zaPVQYbfuHlo6Q/kAey0Pd/nR7w=; b=nkvGybmh+OYvRKU8w7JuqGT42ZJxzRsmU2My47yDO6igM/GF0ZL3vKxrNs7jTgm7NA5RlU TLbRTpZI51dFMkM7idBrLAp4lCNjSYZr1BQaiSjpy/o55+mTb8rMif6bmjFeOJHs9xmU6K BpvqarYw4w67DklHsVYLg5TE2qHpVfw= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=mM5bNwBE; spf=pass (imf30.hostedemail.com: domain of 38mxwZggKCMcwvn3vBn0t11tyr.p1zyv07A-zzx8npx.14t@flex--jiaqiyan.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=38mxwZggKCMcwvn3vBn0t11tyr.p1zyv07A-zzx8npx.14t@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718643951; a=rsa-sha256; cv=none; b=eCKyZNh5rTVpFgkhYjDIpXfnRQse7q0H6SAQwl456ZvmQRQ3UUTspdYYP1cmy/o44lA4iG bVtGGJhKtkWOt0z5aC4gGcSO6Ku7tir69T0cx0VkplISnV7sC0TeFhfzC27Ta4hkr8LfI6 FGD5i4zjKUGBwISdFizvCXAvAau/CPk= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-df79945652eso9476689276.0 for ; Mon, 17 Jun 2024 10:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718643954; x=1719248754; 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=lmqa+eDYiknLWtQ9zaPVQYbfuHlo6Q/kAey0Pd/nR7w=; b=mM5bNwBEvqjKrUwVol68jX9nD1fQmnpwyVTuPiTwSfvRlMoX5Wio1o68TpZCryI6kE J4Bc/z40RfPvxH/8v62c6OkBgmqsdhhvHbONg3Yn9mST81yMKdJnCs+XFuaiqB6Eey97 le2sMXbDY/GPvDqEd4p/47YxPl//ZyE/VzFkfGbRLP9GAZ3S1hyBud4j1G3a3DZ+XGzn IOF3ZS+3sZ8wW8sarinVxNiP5WmjrMygQ1EokeKBttmsMVwkvkH2zy8/b9IowOEuYBUg OZ4iza4yhTSrZBt9H7zoW0ORKVa2cG2qU5U1uw15sxSUt7DsvHPQmDuSXwwlk3Lmmg24 UuJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718643954; x=1719248754; 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=lmqa+eDYiknLWtQ9zaPVQYbfuHlo6Q/kAey0Pd/nR7w=; b=Tl++CVYN+IABBFrTJl5fQ1+NOoFKZOke+P/h2JiuPrjmqEItKNVRXoR5g4o8wzzgBt 6I2HGzM9QzQWikXsUmfSLh29RqsIzSGtwunw/sc2hVbp6vMEih+MeTPhkmL8Zp0JAORN 0r57TBsa29DtufivDjVSiffFmK+COWhKAyLLw+RaROfRPTOv9iGTgbEQ/UEmczhG9s+7 e28x9RbdLCtmlZdajAhMS3tqjeICILfoa6yEOT3mzfE2LkGSxz2R/NX07F9P4wokqKjp R+OD+F14DcTVKYxB7fnlY9Op6xlOwcpib8nlPDvhmxLGA+DEDr1OnCT3B1dDytm1Uv1C Erag== X-Forwarded-Encrypted: i=1; AJvYcCWGfbfsUAF3oS/XO+NV40ueP47iOY2beluI1h4u0lYaSXv9CO/guQ+vVTFKs5YX+ViFY6SeaWvq10MMtVH+Bn9GRNM= X-Gm-Message-State: AOJu0YyzkPn3Tq/a9l+/2SPALL4nRAU1TWEYt/R2Talf65AUCSKkzmwF D6GnWRWJpaV5kspwMWa/ZuBaVW2LuOx+KUO9axLvQ73xioXmuZ4/ltv0rRHv++EsigmzyY7zHrf 7gSaFctwOZg== X-Google-Smtp-Source: AGHT+IHINQQBbNRf7KhELYqBt0/Q0yNW0Gm7Uiwvy1m/YHP63sxC+8TwS3fjRLwHObbkJ8tAXyAlcAdEODvV0g== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a05:6902:1007:b0:dff:7d1:33a7 with SMTP id 3f1490d57ef6-dff1552cbabmr2952019276.12.1718643954195; Mon, 17 Jun 2024 10:05:54 -0700 (PDT) Date: Mon, 17 Jun 2024 17:05:45 +0000 In-Reply-To: <20240617170545.3820912-1-jiaqiyan@google.com> Mime-Version: 1.0 References: <20240617170545.3820912-1-jiaqiyan@google.com> X-Mailer: git-send-email 2.45.2.627.g7a2c4fd464-goog Message-ID: <20240617170545.3820912-4-jiaqiyan@google.com> Subject: [PATCH v3 3/3] docs: mm: add enable_soft_offline sysctl 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: rspam11 X-Rspamd-Queue-Id: 31EDB80002 X-Stat-Signature: gpckdt43jc61n51tgkw1zfnj7k3z96nw X-Rspam-User: X-HE-Tag: 1718643954-574200 X-HE-Meta: U2FsdGVkX18WI4pdDznT6Fulvij/hCVBRIqc98vbOpT7STidDDtvzToN7ZX84eyeNaOcGLgSliQqe/XAx/Mxh4PgH02F46xb2akfMrG5pXXDbsAA8TSL33HwqTxeCogBnrAlQxJAo88bf0SGqw4yLHziJ52cJstibUj+J99r6aMqxd9bwGCn/dObWuP/OFJCXWgSodxdz4rDT1iYZ7c+epGTLnzk5n4jLCAvrtf2ZoY3j5J8YPdXVBc2TZUHMH9ErdWeGTirP+qUWgQYcnAjaHnTd51UALXMVJd18UzjRxaqNl6VNQqQGDolDybYe3ZFowXHRklOZDijfgITileLRgcrosDmq2YqwL5+lshJIAnlRBIJArFI2OdN9KGrqHPwHavTFMP8MrNB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iljr2QyWKdAXk15pnLsVss0Ppvlxoq653pNo2nPfm+7/TmACEMVbGdUYxfGuSFIp01ZZ8pV3k0ue6Usp9TjL6/5ZFOkGp1Nu4ofuuRtBVbr9u5nw2LjPQ5oBpL93x610hEWMcZfHmR0annJdlHlLIeGzxqGZdJMLCXhCWXtqGUHTkxiebErkdw== 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: Add the documentation for soft offline behaviors / costs, and what the new enable_soft_offline sysctl is for. Signed-off-by: Jiaqi Yan Acked-by: Oscar Salvador --- Documentation/admin-guide/sysctl/vm.rst | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Documentation/admin-guide/sysctl/vm.rst b/Documentation/admin-guide/sysctl/vm.rst index e86c968a7a0e..fc62fc272fc5 100644 --- a/Documentation/admin-guide/sysctl/vm.rst +++ b/Documentation/admin-guide/sysctl/vm.rst @@ -36,6 +36,7 @@ Currently, these files are in /proc/sys/vm: - dirtytime_expire_seconds - dirty_writeback_centisecs - drop_caches +- enable_soft_offline - extfrag_threshold - highmem_is_dirtyable - hugetlb_shm_group @@ -267,6 +268,38 @@ used:: These are informational only. They do not mean that anything is wrong with your system. To disable them, echo 4 (bit 2) into drop_caches. +enable_soft_offline +=================== +Correctable memory errors are very common on servers. Soft-offline is kernel's +solution for memory pages having (excessive) corrected memory errors. + +For different types of page, soft-offline has different behaviors / costs. +- For a raw error page, soft-offline migrates the in-use page's content to + a new raw page. +- For a page that is part of a transparent hugepage, soft-offline splits the + transparent hugepage into raw pages, then migrates only the raw error page. + As a result, user is transparently backed by 1 less hugepage, impacting + memory access performance. +- For a page that is part of a HugeTLB hugepage, soft-offline first migrates + the entire HugeTLB hugepage, during which a free hugepage will be consumed + as migration target. Then the original hugepage is dissolved into raw + pages without compensation, reducing the capacity of the HugeTLB pool by 1. + +It is user's call to choose between reliability (staying away from fragile +physical memory) vs performance / capacity implications in transparent and +HugeTLB cases. + +For all architectures, enable_soft_offline controls whether to soft offline +memory pages. When setting to 1, kernel attempts to soft offline the pages +whenever it thinks needed. When setting to 0, kernel returns EOPNOTSUPP to +the request to soft offline the pages. Its default value is 1. + +It is worth mentioning that after setting enable_soft_offline to 0: +- If RAS Correctable Errors Collector is running, its request to soft offline + pages will fail. +- On ARM, the request to soft offline pages from GHES driver will fail. +- On PARISC, the request to soft offline pages from Page Deallocation Table + will fail. extfrag_threshold =================