From patchwork Mon Jun 24 16:33: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: 13709845 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 9D24CC2BD09 for ; Mon, 24 Jun 2024 16:33:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07D986B009D; Mon, 24 Jun 2024 12:33:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 006146B0395; Mon, 24 Jun 2024 12:33:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0F866B0397; Mon, 24 Jun 2024 12:33:55 -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 C424F6B0394 for ; Mon, 24 Jun 2024 12:33:55 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6856914104F for ; Mon, 24 Jun 2024 16:33:55 +0000 (UTC) X-FDA: 82266328830.30.42B4F0A Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf04.hostedemail.com (Postfix) with ESMTP id 9016E40002 for ; Mon, 24 Jun 2024 16:33:52 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=vLASIGpN; spf=pass (imf04.hostedemail.com: domain of 37595ZggKCFA10s80Gs5y66y3w.u64305CF-442Dsu2.69y@flex--jiaqiyan.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=37595ZggKCFA10s80Gs5y66y3w.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=1719246822; 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=eGr5jYrJTE1J6jzu9163uNl/vkyYWJDsDpZJUXS72Vg=; b=hQBWmqc7T1D0NKeq66a4ggCi9GGBXNfEnm/B5cbsicuXn9DwPEEsB8CykK4JOdaPPenrup IKH40z1WhHhQZycWEKPH28YeHVfk+5AKYGZKkc2y2ZGUVvvRLc8L/6uRa1yoc/0c+VKzf1 zfrQqoMG98XILl9sHCJ4f5wxgxNhWdw= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=vLASIGpN; spf=pass (imf04.hostedemail.com: domain of 37595ZggKCFA10s80Gs5y66y3w.u64305CF-442Dsu2.69y@flex--jiaqiyan.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=37595ZggKCFA10s80Gs5y66y3w.u64305CF-442Dsu2.69y@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719246822; a=rsa-sha256; cv=none; b=uigJNVqH1dDSu4oZD7IlZHKJSbov29+9iDflrxnVBkif9tj8BL4gmuY5oyh3qJFmi3lBDd 92VJMwVThN5+W1xD6wxOKxmBuFK+PXegN2mqbtpFyAnmO0XJDHuB9U7yR+van3UFAZ482j BUZ9974nuE9ynshTPxmuU7GOc0mYahI= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dfeec5da777so8581114276.3 for ; Mon, 24 Jun 2024 09:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1719246831; x=1719851631; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=eGr5jYrJTE1J6jzu9163uNl/vkyYWJDsDpZJUXS72Vg=; b=vLASIGpNGLo/m1y0hKyPSokY8WWqPYHRe1R7Zo8VlczswLtHhGBlU7FTNr9hoOKhS8 eieRcM6PmErOPl9TQ1M8VL5wMHaohqrwO7uedTRPI8cn7UAOPMUmAaSZ3Gyl3A5vUwhl 0MQVeUD5q/i07134S6QwEoNJK6AA7WLNvZm1O782fM78G6M3hP3NLhd3mhtlqDOxY7uo Jg2jfo6RhSs6802vWs0TrThPanqE18q/wVH0i5U2R7dKhjmXHMERB7jL9W8qQlH01K6/ i9XWmOBS4FZXCmMTAC8lscg+Y3xDLz3EkE3T3TKUbwYjkv/wpWqrVHBu5k+y6OXepEaA x8VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719246831; x=1719851631; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=eGr5jYrJTE1J6jzu9163uNl/vkyYWJDsDpZJUXS72Vg=; b=jPYtGqdvS7JtImt1oIk+fZtAn97GPWwEHSqpgYTU2YGsiJ7q/LQAS1YL9/p3rHcb2g oukUj9UOBNt49naYOUEke1lISRIPfgBWSCVMbcSU8HQDBDbVz0IXlkFzCiUC7A3YxC95 E8TjwmRrDrL6XyBIN2pexl46Xbf6obu5cEAaO+NCIUzhZ9FeXgdxzkUfGqexk/wUJ26A g24Y6RVaWaPC4nQgenOUAZn9hw4n/BnAMX+p+GHhHUN+sZL0kgi0GP+hyLewidfKBZtr p8hyWfbi6mOy6W8YVB6husgG9arZ15jBZZp56BfrCmMbDllbwBNMZyZZp3AIGXhhWpc0 xYRQ== X-Forwarded-Encrypted: i=1; AJvYcCV47dlMhk2J41fJh6IdxwxZJiB/S3+Xu5f/LihuBO88iKeWe9Fk71VN8ihU8mVk5KfQGoxs1wdzk6bYLKq2bxgFlCw= X-Gm-Message-State: AOJu0YwIqSJeY3AP6tfUWumVsNso8ALbt/A30ZTG7Twdes4iAKydx6+X gWAhCYq6l3eiKzvLOP1qKIm63Y62QIQUdVMNGahel4McthSWgBj1cVAhKK6lI3TdswhvYaRS1JV Svmxfj+LQNg== X-Google-Smtp-Source: AGHT+IFWNAMBkg9ApvF/NZnDFtWll70llg5Vd6Kto042q57IhAU/LTqxD97BtYSxq/w4hjglfhfFmzi2FSC5cw== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a05:6902:2b04:b0:df2:eaac:d811 with SMTP id 3f1490d57ef6-e02fc598947mr18823276.10.1719246831656; Mon, 24 Jun 2024 09:33:51 -0700 (PDT) Date: Mon, 24 Jun 2024 16:33:44 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.2.741.gdbec12cfda-goog Message-ID: <20240624163348.1751454-1-jiaqiyan@google.com> Subject: [PATCH v5 0/4] 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-Stat-Signature: cmyrwhz94fxsxfgyc6watiisprdr7tgp X-Rspam-User: X-Rspamd-Queue-Id: 9016E40002 X-Rspamd-Server: rspam02 X-HE-Tag: 1719246832-843555 X-HE-Meta: U2FsdGVkX1+1pfZnoZAzIEVS/OephW/ZJAJt//eytavjBg0ZSDNlyyOJoP+NyLfdvvpNRPdyCQnOJDIHsp9J07HBPoreAnChifjcB7/o7MT52ZyDwzjkh33EAcNhd0gneF5VX7Q1Jg1VaSvYfG7W/sAIOj3LwFKNQvrRxSFcWS7GqY+I3V+lTE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AFz+n2+1iCZoswQI8PNDHVHiEMHVkdLJwipxsLVHBJL/7O+OGQ0vC4O47KN9nBHf+lkbw0ZVJ7cVDh03AjHewxz6mW20ojfB7ucxLhMXM6qDFgcZs2I/NBkGsck01GaJB8QFjTGISfSGzLzq2W45oEtjdtRtVRBhUxv+BGOXE4jusgnV8PHwOidLqDvew+ixo05QwE02knb75gpHjxAMgXt45E8OttyiRBUpjZdXB4lPdzjdn4OLyqQ+BAQ6dy3IpiosAd5z6SFEDwzD1/6NrkQ8sYdc6lwRAE2dz9UVkg5kccg+hSKEkFMuIKUsDH9cmn2vfmaH3jUvSkJlGyzPHjCPc8FQ8f+DbRL/G7QPSukkomq1iO04SFgCCu1fY9QMADVfxTPws1wXobKKHbdTKgx4lU8D5nZnST5NQ+ljAVrzmwQ1ZtaknDyT7YNcq1c8R2oNjd+U/oPhgEK8TlHGeuffAek6bkvvy44P2xlO5BKoezPy4QyUleiAiFah4l7427aH/jzF0E4k9hy4rJvP8lLLrinj8= 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 v4 => v5: * incorportate feedbacks from Muhammad Usama Anjum * refactor selftest to use what available in kselftest.h. * update a comment in soft_offline_page. 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 | 227 ++++++++++++++++++ tools/testing/selftests/mm/run_vmtests.sh | 4 + 6 files changed, 295 insertions(+), 8 deletions(-) create mode 100644 tools/testing/selftests/mm/hugetlb-soft-offline.c