From patchwork Sun Jan 19 18:06:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaqi Yan X-Patchwork-Id: 13944559 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 14F6BC02187 for ; Sun, 19 Jan 2025 18:06:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BB236B0088; Sun, 19 Jan 2025 13:06:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 86A8B280002; Sun, 19 Jan 2025 13:06:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E48D280001; Sun, 19 Jan 2025 13:06:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4AA2F6B0088 for ; Sun, 19 Jan 2025 13:06:22 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id DFB35C2378 for ; Sun, 19 Jan 2025 18:06:21 +0000 (UTC) X-FDA: 83024980962.26.E59F907 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf25.hostedemail.com (Postfix) with ESMTP id 1FB54A0016 for ; Sun, 19 Jan 2025 18:06:19 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=QGN+FPE8; spf=pass (imf25.hostedemail.com: domain of 3Gj-NZwgKCBE0zr7zFr4x55x2v.t532z4BE-331Crt1.58x@flex--jiaqiyan.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3Gj-NZwgKCBE0zr7zFr4x55x2v.t532z4BE-331Crt1.58x@flex--jiaqiyan.bounces.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=1737309980; 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:in-reply-to:references:references:dkim-signature; bh=vgfFFIARtCStVkFiN3Y7mh6lovuYIVjrCOS7aUtFuQ0=; b=xmYi/HDwkEFLNzM9r/NiYn/hGVCbGpnFiAeqPyqG6yGLMqthsjdkGzh5ekKSAhKZZYv7wA Fz3coAVyqUE6R7ZGVIfAKtM3QGkLdmVPhGNzTuEYHPdueCP4vTdDZ7LI3AuGScpAu5DLe7 5g8xbXuy0z556OeBKwMUbbpo9xIeS6Y= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=QGN+FPE8; spf=pass (imf25.hostedemail.com: domain of 3Gj-NZwgKCBE0zr7zFr4x55x2v.t532z4BE-331Crt1.58x@flex--jiaqiyan.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3Gj-NZwgKCBE0zr7zFr4x55x2v.t532z4BE-331Crt1.58x@flex--jiaqiyan.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737309980; a=rsa-sha256; cv=none; b=o5n9LGTNfiHWfWFX2u2Wb12GQ4J8hrh/Aw0pnMvGIRRBBfyHj2v3b6rTCLzFdRAVspeuxD nVhAGVQ/7LAHxetayaQbMdonnECkT+v1kfro7Zw/rrToD0c7WxQ9+HKcgyw+4Lluj9ijBy Xys/NW8Lro7sb9zS82MDJn8EndssFog= Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2163a2a1ec2so117556595ad.1 for ; Sun, 19 Jan 2025 10:06:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737309979; x=1737914779; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vgfFFIARtCStVkFiN3Y7mh6lovuYIVjrCOS7aUtFuQ0=; b=QGN+FPE8CJzbqrRZbdFPJa6snd6Qt5QwKwaQt0MZ67zakNaxWgnDRZCu95+IKtnHVa OYczOAdzNxpW/d1Gk2osmmh3i4alc+goPACuP4InAjCrefLGEHSTRP8z10qrdT6QUsh/ 66Z22wTQfV8yapFWoYCHJpXUtl+xOXGY/s5Q9ykMXkbgQ+af0ged75YhivwzfOi1HpN2 iMUlyN0ewQFqew6vFo/lYRGqZrnUfxrxw5YgLOedXoDxq//TLSjAxj0kXOnruuwfxHeZ V4WvzwoGRaJ4IVhQuEVwUirwRWQtjqksbj4+1//kMg381EyhpmzclHwQRoUlSPofripy n+xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737309979; x=1737914779; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vgfFFIARtCStVkFiN3Y7mh6lovuYIVjrCOS7aUtFuQ0=; b=tDnqbp2OxjJx9tgd/ZEmCa8mHyWUVXnr3hjAJsMOYBYj+Xdy8mL8bFYGPS5b2/9yGA Lzpqn7NZ/cS8LBM1yAj19NSQ8CgJc+fmxEgdmiV/YHM1xatdDEv/jxdDxe0Q7YN2rSBd r6qnjkRe2V7Q6YOiZ/VKlZ9JoTblUqqX2EgXuOEnXyOsF0XqoZB0HnDasTjKd3UP3NH9 W4/tnofPLTat2uiLe0HtoZ7+g14dScrWXzJhw5Alyt9sb3uTl5cQp731NWMBkQ2rifAE xedf41HiQT+5Rw/LgWzpUxyU8SCwejX+unRuSd0JW/dSgJ3RSsl4d/6GzZwgYDtbEFJN 2EFw== X-Forwarded-Encrypted: i=1; AJvYcCV2205Sgm18rSjyGUPy3jyCJ/KEebeIuSQwmqVeRp7+U8OW71lRqS+HkWIjlBRpCqeVOovQYXAoqA==@kvack.org X-Gm-Message-State: AOJu0YyphbzRsllIg+85co7upx1BMS8K8UadtnbcaY2g0iisxNuGxa03 mkCnmMOSxwiYvbjOrh/bFq3MWlYAttOR9nmESz55CbkEuLvR1iyYz8m5Srlpur6VAH1Pybw8EjP rhvIVMijVtQ== X-Google-Smtp-Source: AGHT+IHAS67bXCUJs2OIQ7UfIjBMR7UVyDySNgDtOcvl1WDYTlpoiA2k8t5+Ag+yzr17DwX0g6JuMamqP59O8Q== X-Received: from plge12.prod.google.com ([2002:a17:902:cf4c:b0:219:21b2:3071]) (user=jiaqiyan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f606:b0:216:4016:5aea with SMTP id d9443c01a7336-21c355835ecmr179457375ad.29.1737309978916; Sun, 19 Jan 2025 10:06:18 -0800 (PST) Date: Sun, 19 Jan 2025 18:06:08 +0000 In-Reply-To: <20250119180608.2132296-1-jiaqiyan@google.com> Mime-Version: 1.0 References: <20250119180608.2132296-1-jiaqiyan@google.com> X-Mailer: git-send-email 2.48.0.rc2.279.g1de40edade-goog Message-ID: <20250119180608.2132296-3-jiaqiyan@google.com> Subject: [RFC PATCH v1 2/2] mm/hugetlb: immature fix to handle HWPoisoned folio From: Jiaqi Yan To: nao.horiguchi@gmail.com, linmiaohe@huawei.com, sidhartha.kumar@oracle.com, muchun.song@linux.dev Cc: jane.chu@oracle.com, akpm@linux-foundation.org, osalvador@suse.de, rientjes@google.com, jthoughton@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jiaqi Yan X-Rspamd-Queue-Id: 1FB54A0016 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ouaht1djt4jt6kgoki6x3acbozxjaean X-HE-Tag: 1737309979-439007 X-HE-Meta: U2FsdGVkX18PGTB9opopDAZj1AFeiCwdjg+SJ11Q8NTuJmkcaEkOmZLFsjVELv5S4j/mJt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prTUHpYQGX+rXpFk/8sryKV05P/x7N/TAr6QXwPuiv5J4S8puubuT2ADHbwQIreSwmfMhJZzbBcvUbAKbVl2LDnPsgrHj8/28Cmqc6hHQJanok0epZq86TAWqUa9xmcQecanXlEXfTghiEEESbZMuU5HaLT4KvNHkNMxipho5dFLIen/zlI5i9EPwZmEOSORMCrlYCuOGbaZYwfVyo4qFY98QqN7/Zb4fDUbZudvFq9UcNy6wF/IbtOnEoaBvsRV8tld4NWWsXL2qmF8ziWesbAk6yldaljoLWPPDUu3gOp+lH4fYSEBfkM1SGkRPW3cooop+z2CxMgMKzWIv2lee80gbrJBN6/zLsDezo6cjyXGIXhf1d+AlNvC4ktGgNt88f8QPwDVJ7u/VNChVuIGnBgz4PVuZ+ZEZ+vNXDbLLGpW74AbAa/QWhPCg12wgXdq44VSP9izYkA/IiPL3FYllVUln/YURjPKn 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: The fix has two steps 1. Decrement HWPoison HugeTLB huge folio's refcount when it is 1. It is done in folios_put_refs during truncating or eviting HugeTLB file. 2. Dissolve HugeTLB HWpoison folio in free_huge_folio. Again, just for demo purpose, not a proper fix, especially step 1. Signed-off-by: Jiaqi Yan --- mm/hugetlb.c | 6 ++++++ mm/swap.c | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 87761b042ed04..b28e0bc7f199f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1818,6 +1818,7 @@ void free_huge_folio(struct folio *folio) int nid = folio_nid(folio); struct hugepage_subpool *spool = hugetlb_folio_subpool(folio); bool restore_reserve; + bool hwpoison = folio_test_hwpoison(folio); unsigned long flags; VM_BUG_ON_FOLIO(folio_ref_count(folio), folio); @@ -1869,6 +1870,11 @@ void free_huge_folio(struct folio *folio) remove_hugetlb_folio(h, folio, true); spin_unlock_irqrestore(&hugetlb_lock, flags); update_and_free_hugetlb_folio(h, folio, true); + } else if (hwpoison) { + remove_hugetlb_folio(h, folio, false); + h->max_huge_pages--; + spin_unlock_irqrestore(&hugetlb_lock, flags); + update_and_free_hugetlb_folio(h, folio, true); } else { arch_clear_hugetlb_flags(folio); enqueue_hugetlb_folio(h, folio); diff --git a/mm/swap.c b/mm/swap.c index 746a5ceba42c9..d6b4d4cb4004f 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -961,7 +961,14 @@ void folios_put_refs(struct folio_batch *folios, unsigned int *refs) continue; } - if (!folio_ref_sub_and_test(folio, nr_refs)) + folio_ref_sub(folio, nr_refs); + + if (folio_test_hugetlb(folio) && + folio_ref_count(folio) == 1 && + folio_test_hwpoison(folio)) + folio_ref_dec(folio); + + if (folio_ref_count(folio) > 0) continue; /* hugetlb has its own memcg */