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 96B00C27C79 for ; Mon, 17 Jun 2024 23:17:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F8376B02A2; Mon, 17 Jun 2024 19:17:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A7866B02A3; Mon, 17 Jun 2024 19:17:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 070446B02A4; Mon, 17 Jun 2024 19:17:21 -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 DBD696B02A2 for ; Mon, 17 Jun 2024 19:17:20 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 568BD140183 for ; Mon, 17 Jun 2024 23:17:20 +0000 (UTC) X-FDA: 82241943840.19.74D7D2C Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by imf22.hostedemail.com (Postfix) with ESMTP id 79F4CC000D for ; Mon, 17 Jun 2024 23:17:18 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=pAEscnyG; spf=pass (imf22.hostedemail.com: domain of jiaqiyan@google.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=jiaqiyan@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=1718666232; 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=y26m8KMuV8p2bUSqQESXrG+REwA97eviu6gSbQ4tKIc=; b=L/xToWU7KZV9CZ8ecHw9Tm7Y8dVXZ74Q571T/1lSP65jG+QsVxTKllIBPYqXMvDza46H/C RTgZuLESy9Q7u9H/xkoXpezkM9SKA7673rSejOCr1psXuXPulPCHmd/fCKsecdiFu4y+kD 8xJqpdywOPr9fueWfb5i0tKg4rDWBH8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718666232; a=rsa-sha256; cv=none; b=zNSPJQeN92+sYv2lO1nMSpt0eVfWUM/dSFoyT8So3UpVFSpsEO7eghhYp7jO4OJ2KJRgWG 14b9eTNtzmMZqCj147w0Xc9UF9cHVisf2NVnXXcsIqGmMstR7kHjEtRXNhWB9DXVPpeKTM IM3m2vSS1DkJ+Qgt+YMXYfTHV9If3Mo= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=pAEscnyG; spf=pass (imf22.hostedemail.com: domain of jiaqiyan@google.com designates 209.85.128.44 as permitted sender) smtp.mailfrom=jiaqiyan@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4217990f997so35475715e9.2 for ; Mon, 17 Jun 2024 16:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718666237; x=1719271037; 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=y26m8KMuV8p2bUSqQESXrG+REwA97eviu6gSbQ4tKIc=; b=pAEscnyGNk3N6pJjNGEdPI5b/1LcRWdwjB39MZmGdBVEKupeomJIoe60gkYxdKEiWQ zH18E/FkDLxq3Qo1h1EmmF15r+cNEdePwmTqMBOkNBhtBymqEVKCdQseQsPBi175Esxg JXQWyAzhKbgDyeAsIMMuGiAvdwq023glI7mZV/u8zPcDh+NdjEVFVpmX+oo592P3Q4tU 4Nf/ONvMYG2VhS3WDzCO4I9AH8ISN1QCNxr0sT+U8AjqvgEVbUb2IowT661lIJZYSGpR GuAt86rxucJM6k8DAMpRPdx3pBcQnP9C/zPPlwaGn0jfwnOEvu6qBjJ4IDIyPRaxv4FM xVFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718666237; x=1719271037; 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=y26m8KMuV8p2bUSqQESXrG+REwA97eviu6gSbQ4tKIc=; b=WuQiyQWzHYzydZ/XGxtyMXoFKjAoGtYGDfQw6/255Qc0+gm9kEWuh8AU0mqOz4ZAuX KV6vvK4Xxr4uLTr4JuMLgqB1P1x/zqjiiaAWaesqytgfhqU/DKqr/4ANpfS2nNsCcvL9 NPMtZOkD0aEa/oQmLQi8T3cHUDgJ4b+XaDA8I1KzQamNIZ7oXC2aSU+xkEzrjT3gGkTB 0KZCMNh5ZueIQ/0VmCf0NzTbdrPjUuhH9A16k3J33tlwmG+0yry6pmEBunQzp9908WHa IUwWzWc/WRCt18YcHwH09fGoEqM27lYOPRRrjmXNy9qXey+GTUDp1ezcr0784eYEFPDC S4/g== X-Forwarded-Encrypted: i=1; AJvYcCXR7vXYSzlSjzG2tk1B19P/tNDLaErAXlhP/sv6uDeDLx0pXfoTvLXPEMHLddyw60wsbj4EqQY7/sM8WdE9X5fWu+s= X-Gm-Message-State: AOJu0YzQr4UWeJ86KGOHpV5ccG9/7yPZgDVScNTW/z0J6uc9fUTfKIbR W1pV7LKiul32MNOOI7kFDartMyNdb+HkgadaOdGZuy655FWUaCeAIhU1Ytvg4VAO+fwC/ZsVj1Q ZlN8JZVeRY1KqeO9TkJUmPNKWZVtS+TgCXyWI X-Google-Smtp-Source: AGHT+IF4HzjtSiEJm/JF7RZmDBSylbGJKMvF570CPPPNOrU07F5yzEv/z3JKNLnewEVpPcf1lCjwtP+ww+rMlM3/Cw4= X-Received: by 2002:a5d:468a:0:b0:360:709c:5040 with SMTP id ffacd0b85a97d-3607a736520mr8281019f8f.2.1718666236739; Mon, 17 Jun 2024 16:17:16 -0700 (PDT) MIME-Version: 1.0 References: <20240617170545.3820912-1-jiaqiyan@google.com> <20240617170545.3820912-2-jiaqiyan@google.com> <20240617121348.4ee672a1d6bc9202b3ad0e08@linux-foundation.org> In-Reply-To: <20240617121348.4ee672a1d6bc9202b3ad0e08@linux-foundation.org> From: Jiaqi Yan Date: Mon, 17 Jun 2024 16:17:01 -0700 Message-ID: Subject: Re: [PATCH v3 1/3] mm/memory-failure: userspace controls soft-offlining pages To: Andrew Morton , linmiaohe@huawei.com Cc: nao.horiguchi@gmail.com, jane.chu@oracle.com, ioworker0@gmail.com, muchun.song@linux.dev, 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: onjo44g8enjjg69ooemsa33wijjwiku9 X-Rspamd-Queue-Id: 79F4CC000D X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1718666238-881505 X-HE-Meta: U2FsdGVkX18t9opoOd3URn8j+NQpUUh7ci9PM6K5Ogb7b7OxKOtTp1ZsMEdMqjysf+GjM62QJEEHCDxFIUKe1d9nwezyJPecwgK78bOIlWtPjGNPS4QVoYYunwtCeScLM0LBZEMcpmrhbW6qB21tV5sR36GF0OSLEfG2Zn4fR95HQIsxO7sgJHMKDtRAGSItMNuKvOktGqkzaNjO5/GNWFmVyA8VXDvPzI7A2tNB2GJ2IerY3VfE8iq4buJhRObe74cdz/8Ty6O7V3b2ENw0ty/ceeN5Kyu9kYg1n41KHyooSChxswC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kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Jun 17, 2024 at 12:13=E2=80=AFPM Andrew Morton wrote: > > On Mon, 17 Jun 2024 17:05:43 +0000 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 it is in-use; 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 failed to mmap hugepages 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 > > doing so: > > 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 at /proc/sys/vm/enable_soft_offline. By default its value > > is set to 1 to preserve existing behavior in kernel. When set to 0, > > soft-offline (e.g. MADV_SOFT_OFFLINE) will fail with EOPNOTSUPP. > > > > Seems reasonable. A very simple patch. Thanks for taking a look, Andrew! > > Is there sufficient instrumentation in place for userspace to be able > to know that these errors are occurring? To be able to generally > monitor the machine's health? For corrected memory errors, in general they are available in kernel logs. On X86 Machine Check handling will log unparsed MCs (one needs to read mci_status to know what exactly the error is). On ARM, GHES logs parsed CPER (already containing error type and error severity). The shortcoming is logs are rate limited. So in a burst of corrected memory errors the user may not be able to figure out exactly how many there were. For uncorrectable memory errors, num_poisoned_pages is a reliable counter. > > > @@ -2783,6 +2795,12 @@ int soft_offline_page(unsigned long pfn, int fla= gs) > > return -EIO; > > } > > > > + if (!sysctl_enable_soft_offline) { > > + pr_info("%#lx: OS-wide disabled\n", pfn); > > This doesn't seem a very good message. There's no indication that it > comes from the memory failure code at all. If the sysadmin sees this > come out in the kernels logs, he/she will have to grep the kernel > sources just to figure out where the message came from. Perhaps we can > be more helpful here.. For sure. I took it for granted that any pr_info will have the "Memory failure: " prefix, but now realize there is a `#undef pr_fmt` + `#define pr_fmt(fmt) "" fmt` just above unpoison_memory. I propose to do `#define pr_fmt(fmt) "Soft offline: " fmt` above mf_isolate_folio, so that any soft-offline related code generates logs with the same following format: "Soft offline: 0x${pfn}: ${detailed_message}" If everyone thinks this is reasonable, in v4 I can insert a new commit to make the log formats unified. > > > + put_ref_page(pfn, flags); > > + return -EOPNOTSUPP; > > + } > > + > > mutex_lock(&mf_mutex); > > > >