From mboxrd@z Thu Jan 1 00:00:00 1970 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 D07A4C27C4F for ; Mon, 10 Jun 2024 22:56:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B0086B0085; Mon, 10 Jun 2024 18:56:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 25FD56B0088; Mon, 10 Jun 2024 18:56:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 127EF6B0089; Mon, 10 Jun 2024 18:56:15 -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 E2DE86B0085 for ; Mon, 10 Jun 2024 18:56:14 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 645791A0505 for ; Mon, 10 Jun 2024 22:56:14 +0000 (UTC) X-FDA: 82216489068.09.21C3AE6 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by imf07.hostedemail.com (Postfix) with ESMTP id 90F4E4000C for ; Mon, 10 Jun 2024 22:56:12 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=zk4dz4sP; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of jiaqiyan@google.com designates 209.85.221.44 as permitted sender) smtp.mailfrom=jiaqiyan@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718060172; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=quTZIKCYwo1oMqK9GegsysfKZz3tpeEKNEIgMJqv2pE=; b=lIZMPtC58QXNJZfT22Cbvq43S4z9oN0WgLQ7sMhEKY3eCYLhh4EclkNTPWaCu9C7+y6P4Q gtmL/eUfFlPbLp/0jVSlbBZNqKEUS1OwAaD+06+IQpSzJyvOEGRG6twGCzg2xsUvP20ci9 tl/yb6v/i1BkVtF/3/IRr3mTH2bAEJg= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=zk4dz4sP; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of jiaqiyan@google.com designates 209.85.221.44 as permitted sender) smtp.mailfrom=jiaqiyan@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718060172; a=rsa-sha256; cv=none; b=S7MtcstQHWTTeKefNaxOSBEZh9JzKVwOqzUP7tvtgTj08qPfCKq+g9q0t2xdkvPJQD1XMi 7Kir/0QqWMH0rOx4cQhyfrhSE0/v+MYq9aQVrKNMWFZpJsYJikcJqCV5H4wqrrzMRz558T dPhXLUdJJRqx+KcFkRgvooEyqo6o8kI= Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-35f223e7691so1088877f8f.1 for ; Mon, 10 Jun 2024 15:56:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718060171; x=1718664971; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=quTZIKCYwo1oMqK9GegsysfKZz3tpeEKNEIgMJqv2pE=; b=zk4dz4sPF5XcOp56LUHcXOi8O6J+ZRXsshKD/TYQCyMHj/4kg3mVXYa3Zly+Gyl7ay E02DAGHcgwyAsEu8Eqlv5lhF/xuHE8pHzpSfxeXxwJK5evqKf4EBbuTmt2zoIs/O8Y7q Ee7PNxte7Rc8bjPpuZCjriavcmUzWv/3TaD4ez6zU/iP/8khVDtbtl21CRId9sT3D/JN tDscdKidaOHjn6eYNCcGQnZM5Hmg9E9fcCp20baSGLxklL8VrQrBc9Oje5xbkuzoOvFm gahFH2WTwPEabngh7drDbn7X+va2OfjhPEauXztHRhCsSW9FxXUV1hw6KAUMD6ToXZQN 4g6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718060171; x=1718664971; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=quTZIKCYwo1oMqK9GegsysfKZz3tpeEKNEIgMJqv2pE=; b=e+hAI1EPde3ENC1JcaBKbRq+2RbrzugdJHs1z9fl+fU8+i1Vng/A3XDaBVHglh7So+ fE27nbOnMGnZKO85+SDEl6Vn/LLuWX/qVvXKhiAvabVpGoXisTjMESgRuudkajk9kGlR 6/9SLrdHBNSfOMa23KzjDVtnzQ0npZUv4xmT5LWL1kmMxQ8A2Q8GT8Lo1E12Pu6HXq2i uc/PlpRn5dJnnbo8CKuIcFGTiVoJ0QkamZnBQwJNure48/H+cTUvdMaYBQJXvh7DRowY xuC6+GVa2HP6vmLzWJUXbVC8CUH3LWGIaFAwfOKfLCaA/90QshWnv8RAbl/V94Pjpram RjiQ== X-Forwarded-Encrypted: i=1; AJvYcCWSFwmPyzawCo2DhvC+6Xls09Fer1FY6F9KaTw+N0XKxiqgvaRyWjR6Tfmc6FhlS1cdhSW+K+XJxuZ6lMws3MI7C6I= X-Gm-Message-State: AOJu0Yzs4lez6tdUUFRqVSULZpvolwrsR+6JnNscDLkHXf2r9GlMHggQ 15BlFtNh5Ywc+DixLQ09efZ7+DKAgO1xgIUu6VGqjP8EBSXtqoFbMbvDgoxrW/WGaNeT1uZ++AA SmxPge0k87l+mGK7jL+atOwQI7FGgz+yMnUoV X-Google-Smtp-Source: AGHT+IEWSnXDkOOuWxy4buVy5+bH83YnyNR4w4o3Mv7K46VM8aoNm19YQLygFNgF60V3lHzBQ/YzJdQu2mPPWV96c9Q= X-Received: by 2002:adf:f707:0:b0:35f:1243:a956 with SMTP id ffacd0b85a97d-35f2b2c173bmr921417f8f.23.1718060170659; Mon, 10 Jun 2024 15:56:10 -0700 (PDT) MIME-Version: 1.0 References: <20240531213439.2958891-1-jiaqiyan@google.com> <21841726-6427-5a92-a3d1-8aac2687c01a@huawei.com> <2738aa0e-99d8-44d7-ac81-e38fd64591b7@oracle.com> In-Reply-To: <2738aa0e-99d8-44d7-ac81-e38fd64591b7@oracle.com> From: Jiaqi Yan Date: Mon, 10 Jun 2024 15:55:58 -0700 Message-ID: Subject: Re: [PATCH v1 0/3] Userspace controls soft-offline HugeTLB pages To: Jane Chu Cc: Miaohe Lin , naoya.horiguchi@nec.com, 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, muchun.song@linux.dev, Kefeng Wang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 90F4E4000C X-Stat-Signature: gyx8hjaq53eqpm3588q66serfjx5pzgq X-Rspam-User: X-HE-Tag: 1718060172-610278 X-HE-Meta: U2FsdGVkX19t9S2AgNGzzVLDCS35cBLo23khVlChWduywUrGpczRnEAFlYgPA3Rap/XWMKtFbMt6VFlIE8fINWky9k145So30AipyJVlEIz9+cLOAJYcvuEQ+hrEA/QWRHYepe0tBzA/IEXIF/bMYsiLTU6qBxTsZk0NNgjuaTEcZ7ZvEmq1DYYSaMaoDzufU+SFtR1xD33N3G5wtg+YTUuJ6Jz5MH0B3pl3pUiFuTAY4ahcNIA4qofihd0A8wl8COXLOjIIGRfbpRtbhNvERubh5QsAo0U4peK31fp1PVkj6Nkw1Q81PgBw7uWoQv4Oeura7tlvE8xPSQj0YyjPlMeyZB652VcA7ECGp9l1w80rzI9SbyzJqV8d54mkQFNx2J+VwX5+2Baug1fdnjhqjUyg6FPwT45G5qKNq3bgOq+i8dMX4ku7D1Q8SaQNPjR/eIT6xdbg78yhtCoNMULbziLZ1SY+IrqfDOJF1rGwK6RQnuRuN5LAMrl++dQGqlBPftJbyT4KPwVBGQ1WWDMq1zJu1S3+6Jn03rDRnb7ft2ioHH8c7V6/n03UfPwa4BitrXiWSRn6WVjKYtdkwGLtKyRUOmdweDpk8eNUYtJZPKl5/AoAQyjIzWWzL+NpD7QmP2teSqxJPyZT3cl30goOSGNO4ELSJEl6JQiTtJKyD+wQKuIn9TvJK65BgzjSFd2OAQO6ORtkDoClki/KxSQbqZ1c3cz2EBEE+ST5JbEIhtH5et5WuxXMdCHxFfColKjazJ+tJLWxWbDAL5rJrZvXq+hq33pcgBS52sqAjBXjWbHsTcvY5Uvx59FEyFMD8eLqcbI/oxhTfQcxBQ2ebGqoYRl1+ZstWHXZuPzyTh7rBezqKctkUmJjFcSDLm2R1pnvvomqHKZL646bGnUjCbsU8Nti80KzI7qmWJs8X9lK9dTKsz/EVmRhaPy2PjJDtJRz9eYZR0E/qlD6zzKPG3l qFT1idra o0LOn0qnQImZZiQeirXt8lsa9YTHCT33a+RaD6vXRcHCsNfLpiKGbj5sxIb5ls9CS+VEBtC+DwK9DUg4p6kolCB7bG3J1j7h4HK/hS6dt0iy131PSDkmvdlpqnwX8IROqDdH+dzlCaOdxBRIcaKbLV2jScT8qFhjKW3XlA4ft+WPMnfWOMextiNmTnA== 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: Thanks for your feedback, Jane! On Mon, Jun 10, 2024 at 12:41=E2=80=AFPM Jane Chu wro= te: > > On 6/7/2024 3:22 PM, Jiaqi Yan wrote: > > > On Tue, Jun 4, 2024 at 12:19=E2=80=AFAM Miaohe Lin wrote: > >> On 2024/6/1 5:34, Jiaqi Yan wrote: > >>> 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. > >> Thanks for your patch. > > Thanks Miaohe, sorry I missed your message (Gmail mistakenly put it in > > my spam folder). > > > >>> 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. > >> For in use hugetlb folio case, migrate_pages() is called. The hugetlb = pool > >> capacity won't be modified in that case. So I assume you're referring = to the > > I don't think so. > > > > For in-use hugetlb folio case, after migrate_pages, kernel will > > dissolve_free_hugetlb_folio the src hugetlb folio. At this point > > refcount of src hugetlb folio should be zero already, and > > remove_hugetlb_folio will reduce the hugetlb pool capacity (both > > nr_hugepages and free_hugepages) accordingly. > > > > For the free hugetlb folio case, dissolving also happens. But CE on > > free pages should be very rare (since no one is accessing except > > patrol scrubber). > > > > One of my test cases in patch 2/3 validates my point: the test case > > MADV_SOFT_OFFLINE a mapped page and at the point soft offline > > succeeds, both nr_hugepages and nr_freepages are reduced by 1. > > > >> free hugetlb folio case? The Hugetlb pool capacity is reduced in that = case. > >> But if we don't do that, we might encounter uncorrectable memory error= later > > If your concern is more correctable error will develop into more > > severe uncorrectable, your concern is absolutely valid. There is a > > tradeoff between reliability vs performance (availability of hugetlb > > pages), but IMO should be decided by userspace. > > > >> which will be more severe? Will it be better to add a way to compensat= e the > >> capacity? > > Corner cases: What if finding physically contiguous memory takes too > > long? What if we can't find any physically contiguous memory to > > compensate? (then hugetlb pool will still need to be reduced). > > > > If we treat "compensate" as an improvement to the overall soft offline > > process, it is something we can do in future and it is something > > orthogonal to this control API, right? I think if userspace explicitly > > tells kernel to soft offline, then they are also well-prepared for the > > corner cases above. > > > >>> 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. > >> Userspace can figure out the hugetlb folio pfn range by using `page-ty= pes -b huge > >> -rlN` and then decide whether to soft offline the page according to it= . But for > >> GHES driver, I think it has to be done in the kernel. So add a control= in /sys/ > >> seems like a good idea. > > Thanks. > > > >>> 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=3D0, skip soft offlining for all > >>> hugepages of size ${size}kB. > >>> * When softoffline_corrected_errors=3D1, soft offline as before this > >> Will it be better to be called as "soft_offline_corrected_errors" or s= implify "soft_offline_enabled"? > > "soft_offline_enabled" is less optimal as it can't be extended to > > support something like "soft offline this PFN if something repeatedly > > requested soft offline this exact PFN x times". (although I don't > > think we need it). > > The "x time" thing is a threshold thing, and if your typical application > needs to have a say about performance(and maintaining physically > contiguous memory) over RAS, shouldn't that be baked into the driver > rather than hugetlbfs ? I mostly agree, only that I want to point out the threshold has already been maintained by some firmware. For example, CPER has something like the following defined in UEFI Spec Table N.5: Section Descriptor: Bit 3 - Error threshold exceeded: If set, OS may choose to discontinue use of this resource. In this case, I think "enable_soft_offline" is a better name for "OS choose to discontinue use of this page" (enable_soft_offline=3D1) or not (enable_soft_offline=3D0). WDYT? > > Also, I am not comfortable with this being hugetlbfs specific. What is > the objection to creating a "soft_offline_enabled" switch that is > applicable to any user page size? I have no objection to making the "soft_offline_enabled" switch to apply to anything (hugetlb, transparent hugepage, raw page, etc). The only reason my current patch is hugetlb specific is because softoffline behavior is very disruptive in the hugetlb 1G page case, and I want to start with a limited scope in my first attempt. If Miaohe, you, and other people are fine with making it applicable to any user pages, maybe a better interface for this could be at something like /sys/devices/system/memory/enable_soft_offline (location-wise close to /sys/devices/system/memory/soft_offline_page)? > > thanks, > > -jane > > > > > softoffline_corrected_errors is one char less, but if you insist, > > soft_offline_corrected_errors also works for me. > > > >> Thanks. > >> . > >>