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 2FC44C27C77 for ; Fri, 14 Jun 2024 16:49:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 952306B015D; Fri, 14 Jun 2024 12:42:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C7EE16B015E; Fri, 14 Jun 2024 12:42:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 356D56B0142; Fri, 14 Jun 2024 12:42:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 24BC06B0173 for ; Fri, 14 Jun 2024 12:40:51 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DEBAB160883 for ; Fri, 14 Jun 2024 16:40:50 +0000 (UTC) X-FDA: 82230058260.01.6BF424F Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by imf12.hostedemail.com (Postfix) with ESMTP id E7BEE40019 for ; Fri, 14 Jun 2024 16:40:48 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=IEdVO+Si; spf=pass (imf12.hostedemail.com: domain of jiaqiyan@google.com designates 209.85.208.169 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=1718383246; 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=6N6pWwte8VFmLbcY/vhwWLg5RRbCqF65dXNS8n7ZcdA=; b=xAonJQM3ZbDfqY9RKCwlAw14SfV7hzrMiK32Go6DmDq0rLHt6RXcL96SAVtG7iezmnjELr HCwXv2WP3C81cBrdfC7OAS5a/Wpdc4t49QxcB3a73NN7fmQfDnPDu8BU7ESRcvcILLz5Gj /Pmmabs0QX5bqc0p4yQmTR+N9+GFcPk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718383246; a=rsa-sha256; cv=none; b=g8aEUr9iHZpBKt0X+quXCPhvFli9P0NYpvariiz6EFDLiPiavwrtYq6UF/s44sH03VgiDX V5nG0LpSP2LyEuPP4fRfPHPMt+bTVNaCI7Xk9GhI4lSOVBjawOiz/xmpAeMsCJFbPEsu/D GhRhUo7/8h3hc4mVOTbOAWhb7L2xkdE= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=IEdVO+Si; spf=pass (imf12.hostedemail.com: domain of jiaqiyan@google.com designates 209.85.208.169 as permitted sender) smtp.mailfrom=jiaqiyan@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2ec0f3b9cfeso12960551fa.0 for ; Fri, 14 Jun 2024 09:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718383247; x=1718988047; 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=6N6pWwte8VFmLbcY/vhwWLg5RRbCqF65dXNS8n7ZcdA=; b=IEdVO+SiNq7sF1z5ToHflsxGV3rzSvalEzliYxwHq0wTxds3fjcMZ9mQ6RoXbJBpSQ be/CuQcWamn/C5buDHZMNCAdh+RBQA3Z9cT5KqnXKBC2Wz8oMAWx/uYeE+53X5GMVuac E7Drsej8QZ5RqArIl1MzOiYvYvr0JpFNXpAdd6IaCCcGA54fLbRzsEMWPkRWMlcNlhcu uCa7r1iCfVVfmJz/szNRODrnuR++lMqu5TVeKjhkEk2ltjwg4+LYi0po0hlNiaj2Zzw5 FVCh2FQMnuFNy1wB0U4H8t8sR3arecdpAtmeOJWCFQnuj7AcSj6GJ39H4Y6oyGQFZeSn 3D9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718383247; x=1718988047; 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=6N6pWwte8VFmLbcY/vhwWLg5RRbCqF65dXNS8n7ZcdA=; b=iQgEVe2ioWawLpNkRpf16VKqfa+LflSinKA/ziiEfoHpF/S2dUwL6N+8XROKvn1+od Bi8WkfyBioV73i0ec6wgKddmnVIZxNj5nXbc6VgacmrfnuD1nIfFuk6MUEgqMKeP/Rtg ZNh924Tdr7IG11u1K7YKXhRTZklnCa4KTHuhrrGxrnfu+5/iOosB6rjjabTQ+8ub1P5Z tCD8vSLunxbtwVhIULEj/soVSIOhdLHRHy2lZjOLer13TUauG12nZ2nC/i0ksSSU9eCa qJey6eeIxBK7odFWf7c6YfOjsgCR+rExcTbu7YkSBFfCvXqnqPLwmXEdgKnlI9kSijWg sN2Q== X-Forwarded-Encrypted: i=1; AJvYcCX4xIPl2OYYpX1WHxdOH5UTV7wA5Q0di09Qaka+V43BV8TUTHZPdOBizILGKGdymtMspDjoOfTrM4U09UMx/BVo0+k= X-Gm-Message-State: AOJu0YwhjjDsKI27RSPhb9DjBpHs2K8tW3i8AcfA4deriiWl7vq7UkYS OP9ZaJF15YplulCZ1j1vizad8TdLN/jHcR7sB99W+00f/yFKaq/0z7lF4Pc41UBMZKwxMHl65tk BWo7GPPOSh+e+KvIpH5Y0Nlg3+IJEL8azjcN3 X-Google-Smtp-Source: AGHT+IH4PaRix9qpyJ1JsEJsH3dIxJd3lDLxxYmObDN8Ly1c+eahxQ5IY2EEyAYetWZChHlpR8fSMk+66JC39s4R/Bo= X-Received: by 2002:a2e:9dd4:0:b0:2ec:453:e46e with SMTP id 38308e7fff4ca-2ec0e5a0442mr21871161fa.42.1718383246745; Fri, 14 Jun 2024 09:40:46 -0700 (PDT) MIME-Version: 1.0 References: <20240611215544.2105970-1-jiaqiyan@google.com> <20240611215544.2105970-2-jiaqiyan@google.com> <1e6ecf75-c489-7711-3289-e4a396ca9484@huawei.com> In-Reply-To: <1e6ecf75-c489-7711-3289-e4a396ca9484@huawei.com> From: Jiaqi Yan Date: Fri, 14 Jun 2024 09:40:35 -0700 Message-ID: Subject: Re: [PATCH v2 1/3] mm/memory-failure: userspace controls soft-offlining pages To: Miaohe Lin 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, nao.horiguchi@gmail.com, jane.chu@oracle.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E7BEE40019 X-Stat-Signature: u45fqnwjwegifpot9xhzob6gtbfkqjfu X-HE-Tag: 1718383248-600104 X-HE-Meta: U2FsdGVkX195duuWntdV9MA+3ZyW5HOOpBr7RiPG2pvMREnmi79/D/garvNJb9eG5I/WbSsYnbtUn+EJXOOxy+N62aPTfBfBLXv6McK8UActo7zrH/0B8490I2MQAYP9ySRHOcoqltVtZfDcNUy5Ww8+2aTAPMaKhFaAQ6NfYNfUjpfwPVTO23dagafYD78t9XJMqmrEo9BOgpYmdXm/1RKZf8jMQnhu+hg/t7Vu4JcH8/LxXog5F0TP3gV0Y5xwNTd+8xvh6/RE2iKwmMhTmqfxK8WpfKCi8rBw/mZPPSXhztZkVwlyRFmuEDIEfjSiwo3UI4ssyy6XsJ9TSUdN4GH1zh9o6l7FJalbjRLv2WqQSlrOW7tpo+42Vmw+KFzfbnkl8yrl1+iTwvi4RjWbXUT8xQ5bv+thGdoSMTjgI1U/K29XOIBwRoUT85Gqz5A69MlrR3R+ujbjSUrJiBHOQLeC3cIc2ywefFTzzHW+3a5zjcArbWPC5Fdhe6xpwxJ4SyGVcNdU+jatjTEebzPwBwCBhpsDMbTwZdBhueRcs8ZTFSSU8RO5xJE53gXP0tTCH0pqgaGqkhkfR6/LyKChfryh1EOVuAy12gAY9aJpUprUTg47MPqSzkvK19XPbD9/iv1Qvau6hXrry0TcGQ4F0lM/9fugfLggAlr4BbLzp8WcNxGjcP00NonAYBDr8q0Ric+jsJetZ91lNeP6TlXz3pJAgBlWNrzNYi3kvc09k0fbRz+Al89rQb6w7xKnbhzUJQP+Ovg980ntk3ThLe4V/Q1zAAGX5ymLU+B17wzwA7MbHH02RwktGqN8gHVI0YfdgedCvfx0D3ujh7vNHTicq05vVZFu1c+CU35ET2T5/xO/9kNFHHtXdOb+jxdcattK1eaQdcdIu74gfpSMRBXr7JglPJpuImwpB48iTW+PrU/V7U2pPu/+IsTe6MIVs6dA+eB5wQsoAM6iLdYJWdv DxHO6Onr LVPxfCgmK/32sconRlk3XiUgYKBGvRjGoR1pvTXJlSrrTLw3cViibWNa6HGuQQOnqq6W+RIG8pA9SelSj4q8+42Zt4JRpI+pe+X1kmgAoUvgp44iE26DgSBZL/XcrGKkIhhNzi2PTs3mhjdbwni3jYVagEVvL/v7QB3g/TeSrfzn7pOCFNZvBLcKro8n+NT34L1MCa7Yf0ZZEDHT0uhTvn19cbzBt8pAHZedjKmWVwWc6DH2fV5OW9yCM6ovWcisOfj8xqOqlMS9zuw0iafJQhaA+iO5I3V8pU1X2 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 Thu, Jun 13, 2024 at 8:28=E2=80=AFPM Miaohe Lin w= rote: > > On 2024/6/12 5:55, 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. > > > > Thanks for your update. > > > 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. > > s/mmap hugepages MAP_FAILED/fails to mmap 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: > > s/doing/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 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 these 3 typos 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_mo= stly; > > > > static int sysctl_memory_failure_recovery __read_mostly =3D 1; > > > > +static int sysctl_enable_soft_offline __read_mostly =3D 1; > > + > > atomic_long_t num_poisoned_pages __read_mostly =3D ATOMIC_LONG_INIT(0)= ; > > > > static bool hw_memory_failure __read_mostly =3D false; > > @@ -141,6 +143,15 @@ static struct ctl_table memory_failure_table[] =3D= { > > .extra1 =3D SYSCTL_ZERO, > > .extra2 =3D SYSCTL_ONE, > > }, > > + { > > + .procname =3D "enable_soft_offline", > > + .data =3D &sysctl_enable_soft_offline, > > + .maxlen =3D sizeof(sysctl_enable_soft_offline), > > + .mode =3D 0644, > > + .proc_handler =3D proc_dointvec_minmax, > > + .extra1 =3D SYSCTL_ZERO, > > + .extra2 =3D SYSCTL_ONE, > > + } > > }; > > > > /* > > @@ -2771,6 +2782,11 @@ int soft_offline_page(unsigned long pfn, int fla= gs) > > bool try_again =3D true; > > struct page *page; > > > > + if (!sysctl_enable_soft_offline) { > > + pr_info("soft offline: %#lx: OS-wide disabled\n", pfn); > > + return -EINVAL; > > + } > > + > > IMHO, callers might reach here with page refcnt increased. So we have to = take care of releasing it first? Ah, I think you are right when MF_COUNT_INCREASED. I will move this after the pfn_to_online_page check, and release if disable= d. > Also will it be better to return -EOPNOTSUPP or some other better errno? > > Thanks. > .