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 704AEC27C6E for ; Mon, 17 Jun 2024 07:31:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 898E06B0149; Mon, 17 Jun 2024 03:31:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 849016B014A; Mon, 17 Jun 2024 03:31:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 737EF6B014B; Mon, 17 Jun 2024 03:31:36 -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 56A3C6B0149 for ; Mon, 17 Jun 2024 03:31:36 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0A6F8A39D5 for ; Mon, 17 Jun 2024 07:31:36 +0000 (UTC) X-FDA: 82239560592.13.CAB3E39 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf20.hostedemail.com (Postfix) with ESMTP id 5887F1C0008 for ; Mon, 17 Jun 2024 07:31:32 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718609487; 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; bh=6DB2BZo/T2ATtTf0dWOIuhORWrx8CwLfS8oN7WXTxq4=; b=MNO9U4RhU1TzDyosSmkEeY41jOeQI1E4f8dRfKO9lo8+HlUbjWo9QC5Kiro1A4YLxMIQdm wVxDJKyarF4+4MCQQI/C5WL4Ux91h+P+uiS2NDoy3QPi9B+Qk7CrpAFhSMqalMAtOAQUT2 RFhd1WPpE7uTMdbc4vK9ZybfYMBJc0k= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718609487; a=rsa-sha256; cv=none; b=VBhuKzc8v1WrW94yiPhzv+6+fVSS5b/ShTgiInEcG6NEzW3zeZc9q76hZhOGAyG7iv/tKp wK5KJIBzNvQmX287rwA+9PSpjbdkzl+97QB27ltDmJNFqd8SmzUqqn0hvclqHMNq9U5bMf tMC99iZjlrPFhERDm1bKjGf5CCEaTAc= Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4W2hLQ6WLxzPr9c; Mon, 17 Jun 2024 15:27:58 +0800 (CST) Received: from canpemm500002.china.huawei.com (unknown [7.192.104.244]) by mail.maildlp.com (Postfix) with ESMTPS id 542171402CA; Mon, 17 Jun 2024 15:31:29 +0800 (CST) Received: from [10.173.127.72] (10.173.127.72) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 17 Jun 2024 15:31:28 +0800 Subject: Re: [PATCH v2 1/3] mm/memory-failure: userspace controls soft-offlining pages To: Jiaqi Yan CC: , , , , , , , , , , , , , Lance Yang References: <20240611215544.2105970-1-jiaqiyan@google.com> <20240611215544.2105970-2-jiaqiyan@google.com> From: Miaohe Lin Message-ID: <786a08ff-aa7e-49d5-f589-0a405c7e1a34@huawei.com> Date: Mon, 17 Jun 2024 15:31:28 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.173.127.72] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500002.china.huawei.com (7.192.104.244) X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5887F1C0008 X-Stat-Signature: 4y4gztjk3iry9ihbdparfhauxwtjimsq X-Rspam-User: X-HE-Tag: 1718609492-300383 X-HE-Meta: U2FsdGVkX1/9dIRL/YqUs5Xp40/+cLT11mOYfinTuTKeYNH4iY8oXCT0vKO+v3LoDSRdOG+MAX91cGiM287Y6T5JB3gB0fCINhZY+BKlRP2FBC9qyyriGSAOU/ZKtuPo4FbPSjlGGcWiWWnSw5rJRUeFHBD1BBbRQ7HP7pftT2hVmD/7epRfieVpJKvLTpEmO4EwEKmZrC/q6XuAqoQuVOSYD3IJqVK8y6msFMvb4ZhS0UT+6X8hCwG2/7bmWWe/jamg4LB+/ZZteef88Gnsngblx13ZaF3M6XAbeMoKWaoKsaQ+xjpDSk0L9CyFeb+9a6qiYL0Q2M7q93KEa4ZFUQfGOmhhH/vD7vYUXaCp7ZuchAfVB+HBC+rn3FiqCITLKkDsXX8en4S9RVhOxWT2AMMFqDMcyge5wwQT7Fp1hLSwXi+MENwBytvgEqPxywCKXI04nu5HIRLQLQJD8cQ3gt5xBco9VZRtV5IvRwwP3qXp5PHnpSgIftBxzT5hMSu9sOXrv2tXs6SW86wWSY0aGvROh5ScTsqk6AcRGff88P8sJOsgmmLcwlFOsJ3J0vaxfOSp8M5gzfVg+EOtRoU/iWsw75OcXJZXRocC1D2naZxrkYNsYNjX+NpBVD+YsBEfGpsvZC7lNdQ3qgsvGaJ4bBXgP3L3EYUnLIkVNVibz/Fu29sMfyH/BzABa83ujxsL+T0l1L6yejEjbAFo4biJlawSYylRywlRXHwc7Z4L3W/oFNvcNCmS8igDTE+9eLj+7uErh4CYWtt82HGzjMFtvIJ/Z4xH76g+E2B3D7WnpzClR1Ud3AsOy+sNuCtQKEKyFGIsT83bv5EPRDUYvMQRGYtPdKPlURuL27CFckwn7CkPbQkNPCjp850+7QsSBtreWcbKN/i+9fks2f1W6Y6HXHU8poxa6oWTq2RYqbXw/GE4ZbdwDqOcFJqUbu/isqODombI3wrLNaEl/HpcIsb NY74l5HS XCmAuziNPvXM1dOhZArQT8QoKkGqEx3cijpGgcWauwTVxY0xcgrsPUH4MnsOhruJKKEHWvdGCiDu1S9S95rJl0mOamgLR9BiJfyq/epPwOOCD705c62IfZ2oknF30bjud7cCSLqmOPxZhX7qK15wuw+9isUBJaqfRz+UkGa2+fYm0eazjiNhsEt9ls6zkJN6KRSQP7CE98jFMi8I7U6OcC+oRmILHXeQuT0D+WOolKu4TDhZ5BZloxs8M181Aw1JPP7lNu56qwmOKzahfMnuvebN9Xg== 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: On 2024/6/15 0:30, Jiaqi Yan wrote: > On Fri, Jun 14, 2024 at 1:35 AM Lance Yang wrote: >> >> Hi Jiaqi, >> >> On Wed, Jun 12, 2024 at 5:56 AM Jiaqi Yan wrote: >>> >>> 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 inuse; 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 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 called enable_soft_offline under /proc/sys/vm. By default >>> enable_soft_line is 1 to preserve existing behavior in kernel. >> >> s/enable_soft_line/enable_soft_offline > > Will fix this typo in v3. > >> >>> >>> Signed-off-by: Jiaqi Yan >>> --- >>> mm/memory-failure.c | 16 ++++++++++++++++ >>> 1 file changed, 16 insertions(+) >>> >>> diff --git a/mm/memory-failure.c b/mm/memory-failure.c >>> index d3c830e817e3..23415fe03318 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, >>> + } >>> }; >>> >>> /* >>> @@ -2771,6 +2782,11 @@ int soft_offline_page(unsigned long pfn, int flags) >>> bool try_again = true; >>> struct page *page; >>> >>> + if (!sysctl_enable_soft_offline) { >>> + pr_info("soft offline: %#lx: OS-wide disabled\n", pfn); >>> + return -EINVAL; >> >> IMO, "-EPERM" might sound better ;) >> >> Using "-EPERM" indicates that the operation is not permitted due to >> the OS-wide configuration. > > Miaohe suggested -EOPNOTSUPP. I agree both EOPNOTSUPP and EPERM may be > better than EINVAL. But I wonder how about EAGAIN? With EAGAIN plus > showing "disabled by /proc/sys/vm/enable_soft_offline" in dmesg, users > now should be clear that they can try again with > /proc/sys/vm/enable_soft_offline=1. IMHO, it might not be suitable to use EAGAIN. Because it means "Resource temporarily unavailable" and this can be solved by simply retry later without any further actions taken. But I might be wrong. Thanks. .