From patchwork Thu Jun 20 18:48:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13706248 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 6BCE6C27C79 for ; Thu, 20 Jun 2024 18:49:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC4B18D00D1; Thu, 20 Jun 2024 14:49:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D74538D00A7; Thu, 20 Jun 2024 14:49:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 536996B013C; Thu, 20 Jun 2024 14:49:03 -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 31B8F6B0128 for ; Thu, 20 Jun 2024 14:49:03 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AEF1A1A053B for ; Thu, 20 Jun 2024 18:49:02 +0000 (UTC) X-FDA: 82252154124.07.4F1213C Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf30.hostedemail.com (Postfix) with ESMTP id F236180002 for ; Thu, 20 Jun 2024 18:49:00 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=rFigLUtf; spf=pass (imf30.hostedemail.com: domain of 3m3l0ZggKCJoDC4KCS4HAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--jiaqiyan.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3m3l0ZggKCJoDC4KCS4HAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718909335; a=rsa-sha256; cv=none; b=nXzimS+9OEphWKZTl7UnC8PaR3KOASg7Njyc41HoBmmx7xhpC8o9xtSnthXrfk4Owxtyke 0oBi4n0U8okMYZlaNE+ebqUCq/dsvGWzYXoQQqdmm/f2CysUqCMx25T68sWkJbkRe+yXpH RS/mOVk+VN4wdSmNfj3FMD+GzfPmU1o= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=rFigLUtf; spf=pass (imf30.hostedemail.com: domain of 3m3l0ZggKCJoDC4KCS4HAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--jiaqiyan.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3m3l0ZggKCJoDC4KCS4HAIIAF8.6IGFCHOR-GGEP46E.ILA@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=1718909335; 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=d9tdNDDl88qMcZ8yPf5Qu/IpIHQAZ5ZqhxULhpb88jo=; b=abNaVYVDM+BzHwQe+dmfYtcP4vIIOzzsej992sGROBbIwvLB3oy7u6ho5F41WD5gwVbjR7 AQLCfrHwwfPwQqLDuaMIO1MDGz28+Lz7QC8LAInEAJ2nOncQr5iFhFxb3N0glqM1foq337 EplIxv6TrvAYmH8aEZo9L6MFbbCU0TA= Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-1f733390185so10530025ad.3 for ; Thu, 20 Jun 2024 11:49:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718909340; x=1719514140; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=d9tdNDDl88qMcZ8yPf5Qu/IpIHQAZ5ZqhxULhpb88jo=; b=rFigLUtfBrAqU6pHtjI93PnB8mv0J6R3dCLUdrRY8UkJZJWJkPvNG810S4CvAIGQpQ d9psQAfZ/TXJfqM+4tNn0cDa2NErtl7fbyqdTzukA3u5CaFMBzwXN6SucOp1CIEhOpxz JcY28G1uWmzQ8II+AVDPxNXDmH/j9tSWkMY86EVuvImQBJjuV0i81AeHHHisa2WJQNmN CPJXRNNjNhCGpei5AkZa+vdRAgeso47mKQlFc5eecupSMr2k5eG+yHBCxu/rhqN4cMTw MbUbxp8hl69yi8afepqXw3lqo+4GdsbLeKLod21G6XW6WE5C23GCRbioeQmiIdtCxLno 75AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718909340; x=1719514140; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=d9tdNDDl88qMcZ8yPf5Qu/IpIHQAZ5ZqhxULhpb88jo=; b=QGgbrQur2cohqK8osfNZj5y3aPQhPE/WmxZtMZUy8WnL8k01TnbyZffIWwg/FVbttU TJ6RBPLdFAOKgTYBeG6TjpwvXQOzQqxjEw4xhTjt8+MEKW9IYZxvDspSkQfNT3vVkwL4 mDTQbXPYvLRiaWkSbag++lNDWxZynx2yU0I8A5+Ryz0uKEf2tN6YiqpU+y+xUvpmJIsP BkJjkwL6eDjZ5ta5y17O7RDomOWxNL4F8FGvruEuxzFAZBRNkLYSSDD8a0ICdy/ExoVK j0QJwe20/unuYQEEvxrlepedPTi7+4Ufw4NyOfWtQSvCZ7P9mz0QSe6aC5/chH9fJSw9 rwDA== X-Forwarded-Encrypted: i=1; AJvYcCVry5Yr9whfkvGIP+vd+PFsoR1xMv69p9riEMy9lXyLh2xxcJs6GVEcd+HvsZkinYlwncCM+A5Z3QVE6/ygCMbdPss= X-Gm-Message-State: AOJu0Yw4svKIv5vWWZzW4etqfDflsy1tXSNpaLRqOKhXOHi7/QQhQqCN JU66wCmaS/O3kSFnS5bqKlF+8Mp+XdfaC5gjKg8Z/SqvtnniYRss0v3UaJzawlm5kqBChGM35Y8 M0RGgCDfVhA== X-Google-Smtp-Source: AGHT+IGeFtSm0Ob5GbXFXzE2dfom7nuBRbI+HybKNWPf03Ehp6HFBkwzY/nxmSyoKG+btklxI5CDQ60BWXewkA== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a17:903:1cf:b0:1f6:84b5:1e10 with SMTP id d9443c01a7336-1f9aa396c7bmr1298975ad.1.1718909339520; Thu, 20 Jun 2024 11:48:59 -0700 (PDT) Date: Thu, 20 Jun 2024 18:48:52 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.741.gdbec12cfda-goog Message-ID: <20240620184856.600717-1-jiaqiyan@google.com> Subject: [PATCH v4 0/4] Userspace controls soft-offline pages From: Jiaqi Yan To: nao.horiguchi@gmail.com, linmiaohe@huawei.com, jane.chu@oracle.com, osalvador@suse.de Cc: muchun.song@linux.dev, akpm@linux-foundation.org, shuah@kernel.org, corbet@lwn.net, 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: z77z8hesxpfhjzq3efn9xunhmt75k5o9 X-Rspamd-Queue-Id: F236180002 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718909340-929554 X-HE-Meta: U2FsdGVkX18DQLLWZ/WCz7OHDJR9FFBVbow4YK/k2BPdRt1WWl1djJcVmv7zEuhLi80SFP0bXgRaMs+K8Tk4SpyjiQayy7DtKBSDEHQia/ZZ6pnaKx6mHpYN/e2eaXWg1nbcWlKj0nKD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S48e8J8JMC+3ViO74XkfHs4pWrRCrJibbE/O4JNowFXDjq0KEGGq95vUWpuTXlON42I+x/GZjEc2XI4u9YXOOkowAiROaJ5gWGVlBHI7zJ/0BaQw6tvtMgrutBxyTZDs7K/cAyflE934iy1FCzcKDR0S/fIlZ5afKdR9YALmfNa2W413oMQkfB59roWwby+fovh4x/GYcY08Y3GRGN+eclNTJ62D34gDy9q9DFUDbEa/9cQkKV3IadGX+FYTqBFjPwSd/j0LNGHG40sWUTCsVaOYxqmqxys4ORjuBYx36kMv/Y8+ESO3dYvOUd+wUouCUMEUT/+4GoIVL8dq2DHyatPx2qHWd/vW4pkpy8InrcKPtxP4Le/7UFz5OsFj0+idlq3hdFjLmxQkLnsYgknCkY9oq10tZy5OOPlazRIwHjyCkiBM7reJQ/lzGLEStp3u6nXCf0KxKU64qE5xiNx1O648hyhXWKzeO8d6KmwXDl2KPAPqkSl3mf5d4kysdx/YtXDj61jcfi9fv63Ko+ocM= 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 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 | 38 ++- 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, 297 insertions(+), 8 deletions(-) create mode 100644 tools/testing/selftests/mm/hugetlb-soft-offline.c