From patchwork Fri May 31 21:34:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13682198 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 914E2C25B75 for ; Fri, 31 May 2024 21:34:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D5C8F6B00A2; Fri, 31 May 2024 17:34:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0CAD6B00A3; Fri, 31 May 2024 17:34:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFB5F6B00A5; Fri, 31 May 2024 17:34:46 -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 A1F926B00A2 for ; Fri, 31 May 2024 17:34:46 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1FE3241372 for ; Fri, 31 May 2024 21:34:46 +0000 (UTC) X-FDA: 82179995772.09.25D846D Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf02.hostedemail.com (Postfix) with ESMTP id 6F1E18000C for ; Fri, 31 May 2024 21:34:44 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=mfHPxH3g; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3c0JaZggKCJoDC4KCS4HAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--jiaqiyan.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3c0JaZggKCJoDC4KCS4HAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--jiaqiyan.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717191284; 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=g9a4m0tSyICWy0UguPev6jQ4VtQUH+IhztdiBrfWz7s=; b=JDC3T0yUu0uiQdKxd5GYxWzcEN007guOnFTi5t/yNHnTh+CCZCkDbiRcMjkHFBAwUxVyng oecrRAYojs7bxAPf+/3Oi3PIhA7/jaz4NbXgFrKTPFXEDjTQ+DzGXxoOMlh/8yQrdBROJ/ VMl9SeiesgF8boWtBUjON5ITNlkF520= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=mfHPxH3g; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf02.hostedemail.com: domain of 3c0JaZggKCJoDC4KCS4HAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--jiaqiyan.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3c0JaZggKCJoDC4KCS4HAIIAF8.6IGFCHOR-GGEP46E.ILA@flex--jiaqiyan.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717191284; a=rsa-sha256; cv=none; b=LxDOGmeVcKwJHKHxUEHxRs8Irq0bARrturufxJoim5fMw/R1uk2IdZUW6QXL+32IRSxmkO eVb2mmFLr6lHrPltk8i+55/1ux5VLGRms4EUZiI8soKwSqCntDwJNFmbn7aXhg81UPadhw ze667XAjKpbg64agR4zL54tK3HYlyi0= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dfa77d54cd2so1791303276.3 for ; Fri, 31 May 2024 14:34:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717191283; x=1717796083; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=g9a4m0tSyICWy0UguPev6jQ4VtQUH+IhztdiBrfWz7s=; b=mfHPxH3gXCGaRhyJUKGyYEXMMUIZJpWH2uHcfvdxxC1YsM/lDtskCKRI5wg8pGwJRZ /hg4VqVOXkgKKo0VtG/27rEQN/HL1yZhmvrnoo126vImW9Mz502jpiHDKKNbuuLbovac Fl/vIzh+vlFvi0XulaQ5q1wFkxLj6xRkkVzE3znw6RXfUxmGL/wuWclUL/nBhW7NXykr 7gryMzArmqAPm9DDQK0VMh30OfPTcswf5000494ni10WLad1ax4UYdPi2/r4SJ7HLFaW D/jm0RwVaM3puDf66VxMnwuLKE2t0y2djEjdrzEyMPe5zfbwQOzxU2wqOhzX1zljP0c2 DYdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717191283; x=1717796083; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=g9a4m0tSyICWy0UguPev6jQ4VtQUH+IhztdiBrfWz7s=; b=nb1BDWvWidmSrbOqPfBOrF3cX4wxDoSX/WcC1W4ZfqYlterKoXjhCzFoJt6weWuyl0 l+MoZDAtXJhzqJhm22iBJzP8JNkj3u/ju2Ea28x0PHQ36QYZRfnY6TX6Y/EJkL1scHj2 QGVJK5mh95jtR851sU5cfrkUGKmmoxqtFfNUpwvI31NcuOcSUPCpZx7nZpKJNMnm/ls7 G/7N4uRsRNWhQfZA2X6XfHlIJuWyKCV2UA8R7lo6GiR5LKctm8igAl+ik3CBhWf5Oc/g M50S0Zk2MIat+AtQhvAZAehTIcopCS7p6xnLdx8Dw2bzIXkQOGBYlIhNsf7wy+RCx553 S3Gg== X-Forwarded-Encrypted: i=1; AJvYcCUgAvOJkGwgptYW2qxKu//lESJ5tp4sxRDVwHzDFQAw1rsYqRD2L0+/zEiiZawuRfqChBNOk8eb13wgjXx0jXUmy2Y= X-Gm-Message-State: AOJu0Yz+y/bJ8bUlWBSIjZSvv8/2wQWiuG2iyv08nvyYF5L+kx+PTfU1 7ilANcCmlcH/njjZ/MNmcbDdG2h0aKIXgMxHai1UGjiFAiqOLlOGGc/Yq1GpzJ/DbwVtFrKiXiJ 1VMIci5ZeVA== X-Google-Smtp-Source: AGHT+IEcPY6XgPhyEspQP0kWwXng6v8b1Mv+0NoD2vv4x30M+l7m0p019T5E5CKmHGsb9yQrDP2DWrLq7Dg9WQ== X-Received: from yjq3.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:272f]) (user=jiaqiyan job=sendgmr) by 2002:a05:6902:110d:b0:df1:d00c:130c with SMTP id 3f1490d57ef6-dfa73bf59bcmr348904276.5.1717191283404; Fri, 31 May 2024 14:34:43 -0700 (PDT) Date: Fri, 31 May 2024 21:34:36 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240531213439.2958891-1-jiaqiyan@google.com> Subject: [PATCH v1 0/3] Userspace controls soft-offline HugeTLB pages From: Jiaqi Yan To: naoya.horiguchi@nec.com, muchun.song@linux.dev, linmiaohe@huawei.com Cc: akpm@linux-foundation.org, mike.kravetz@oracle.com, 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-Queue-Id: 6F1E18000C X-Stat-Signature: dkdiuoew1sbdn4hjjky9tj7tk96giqt6 X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1717191284-308649 X-HE-Meta: U2FsdGVkX1/ZAD7QPzXCOhV2OzC6wByt2vpLuQfrRk1lVZdItCqPzHoeLypz3bYCbUfxMChZgpFbszR4U1A32BEVODdRuu8fGwC7vvzm7VGkkD/0VV6An02Hl89tA33Jygl0cCB0PhJWeOOU/29d69G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EKefOVRIUe1uuBBBqujO6yStF6TAnduNRbiJWAlKXFMVjn7i9BZBU1puDBLkHp3DmAWDZ/pQyK8RNJs3Apiy/BWWu4H0dwnCB1mR+Lno+UiJ0TqEmyPRPMbJpcUlwprEbamx4nlDKkmREY1W0UYzpz3sl691HFPpaEueQtLhjht3igBMKkKbe51OZW5f2aQbNLwQ3nS4ScNo2DDbu4uv6TSvn3H2Gcg4PrkB+nd2t+6oYL/M7CV1MDnTLEEuPSVrBt0kx5xv/TAax9pWedzbM5XbOwZ4l3Q50d9h21p5q00+x3QIEcB0rGH5xJuyf7GCvUQSE+Q95NNHsnoGMVziK2uLDm77ue6tiEasQh9zfDl+VrSkZvr5jLZz 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 HugeTLB hugepages. Soft-offline dissolves a hugepage, 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 addition, discarding the entire 1G memory 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 soft-offlining HugeTLB pages: kernel only soft offlines hugepage if userspace has opt-ed in for that specific hugepage size, and exposed to userspace by a new sysfs entry called softoffline_corrected_errors under /sys/kernel/mm/hugepages/hugepages-${size}kB directory: * When softoffline_corrected_errors=0, skip soft offlining for all hugepages of size ${size}kB. * When softoffline_corrected_errors=1, soft offline as before this patch series. By default softoffline_corrected_errors is 1. This patch set is based at commit a52b4f11a2e1 ("selftest mm/mseal read-only elf memory segment"). Jiaqi Yan (3): mm/memory-failure: userspace controls soft-offlining hugetlb pages selftest/mm: test softoffline_corrected_errors behaviors docs: hugetlbpage.rst: add softoffline_corrected_errors Documentation/admin-guide/mm/hugetlbpage.rst | 15 +- include/linux/hugetlb.h | 17 ++ mm/hugetlb.c | 34 +++ mm/memory-failure.c | 7 + tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 1 + .../selftests/mm/hugetlb-soft-offline.c | 262 ++++++++++++++++++ tools/testing/selftests/mm/run_vmtests.sh | 4 + 8 files changed, 340 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/mm/hugetlb-soft-offline.c