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 X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09475C433E0 for ; Fri, 19 Feb 2021 10:52:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 711FF64ED5 for ; Fri, 19 Feb 2021 10:52:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 711FF64ED5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E55A78D0015; Fri, 19 Feb 2021 05:52:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DDE2D8D000A; Fri, 19 Feb 2021 05:52:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C80D38D0015; Fri, 19 Feb 2021 05:52:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0219.hostedemail.com [216.40.44.219]) by kanga.kvack.org (Postfix) with ESMTP id A7B7B8D000A for ; Fri, 19 Feb 2021 05:52:55 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 636428126 for ; Fri, 19 Feb 2021 10:52:55 +0000 (UTC) X-FDA: 77834704710.21.ED9C221 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf14.hostedemail.com (Postfix) with ESMTP id 46921C0001EE for ; Fri, 19 Feb 2021 10:52:50 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id o7so3779839pgl.1 for ; Fri, 19 Feb 2021 02:52:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XbL3Iq/tlQKaMY7+ENkq1giGyxHjMyxq30iguX+T2Xg=; b=b8+RCL0XLP/mP/uuf0ArdrG6YUP6u0r+K23hdKtgbqZc86K+O3Pc1oAqgfR71Rxq5J ZL12a/lWwfL8quq3c7jBYlA2HrYyhLeYh3RHrIoQ7jPVYRNBsQHGo1wVKXEq8HIOxxDm ClzL1VxCWxVmEj2noq/OdiHMzW/cD+q6i0DBBWRa7DiMosPfUt5c1WbmYTkJvd8xhgCJ yqQw7+IPoHnLFqfg5ZyNRo2DjXtcN/S+eG3NO+Di1clk6Luj5OTK8JM+VQ/9mQ2LSVDN W20iL+miSRqojFd0211tau7RINh/q8ZTzCbJrl/QMe/NLNsKjEATn+IF061FOWdjejUY MLIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XbL3Iq/tlQKaMY7+ENkq1giGyxHjMyxq30iguX+T2Xg=; b=OiiWOG5v+gtDTdFDUY+hw6a0WbE9umBTwqdnNC7E9gPo9RaRS0T1VR0YystJuWtUOL 9jkJN4vk5TcRUJoOvIZYSjxNep8DGDHDg3ADc9oty0aLisHfVY54t8eNzWy7QpwFgGdd iFzD75MprOeGAHhuo32nAj0+lJ/JU8Ed/sNuUhm1i5H9Xj8MhtfjSJ9/62LpC6EVxjv2 HWwsqfmYaJDY3980NPa5spUzxe0OJCJRRdAlTZZ4DmtLglms9vX7lxDM+LN8iRoadDNU NbAIHpumIeRSqrIWykhpLzI8a/jN284EDhL3wbYxB1V/Ny/axDdw9uRyyCzBqUd0aTNR IyXA== X-Gm-Message-State: AOAM5334esocAHPkM724Usfb92Lb9yzQ3C7xWSNEAl/Pr1pQGXqjNU5g SzCzuEw5pwzNZdFi3sdicTrE/w== X-Google-Smtp-Source: ABdhPJxniWBzV0gBHXJrKBk5wa91AXlRmw0Gkx8HF/+cf1IdDPvx6EuhKmDKQSmuJ4tPyNqQGJ2Qfw== X-Received: by 2002:aa7:9393:0:b029:1ec:bf17:9270 with SMTP id t19-20020aa793930000b02901ecbf179270mr8890456pfe.70.1613731973970; Fri, 19 Feb 2021 02:52:53 -0800 (PST) Received: from localhost.localdomain ([139.177.225.250]) by smtp.gmail.com with ESMTPSA id x1sm9662193pgj.37.2021.02.19.02.52.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Feb 2021 02:52:53 -0800 (PST) From: Muchun Song To: corbet@lwn.net, mike.kravetz@oracle.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, rdunlap@infradead.org, oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, almasrymina@google.com, rientjes@google.com, willy@infradead.org, osalvador@suse.de, mhocko@suse.com, song.bao.hua@hisilicon.com, david@redhat.com, naoya.horiguchi@nec.com, joao.m.martins@oracle.com Cc: duanxiongchun@bytedance.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Muchun Song Subject: [PATCH v16 5/9] mm: hugetlb: set the PageHWPoison to the raw error page Date: Fri, 19 Feb 2021 18:49:50 +0800 Message-Id: <20210219104954.67390-6-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210219104954.67390-1-songmuchun@bytedance.com> References: <20210219104954.67390-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Stat-Signature: wcbx9staadtsttzdpuhbp7ftakhi55fg X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 46921C0001EE Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf14; identity=mailfrom; envelope-from=""; helo=mail-pg1-f180.google.com; client-ip=209.85.215.180 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613731970-817978 Content-Transfer-Encoding: quoted-printable 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: Because we reuse the first tail vmemmap page frame and remap it with read-only, we cannot set the PageHWPosion on some tail pages. So we can use the head[4].private (There are at least 128 struct page structures associated with the optimized HugeTLB page, so using head[4].private is safe) to record the real error page index and set the raw error page PageHWPoison later. Signed-off-by: Muchun Song Reviewed-by: Oscar Salvador Acked-by: David Rientjes --- mm/hugetlb.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++= ------ mm/hugetlb_vmemmap.c | 12 -------- mm/hugetlb_vmemmap.h | 17 +++++++++++ 3 files changed, 91 insertions(+), 21 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index bcf856974c48..f0877411f790 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1305,6 +1305,74 @@ static inline void destroy_compound_gigantic_page(= struct page *page, unsigned int order) { } #endif =20 +#ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP +static inline void hwpoison_subpage_deliver(struct hstate *h, struct pag= e *head) +{ + struct page *page; + + if (!PageHWPoison(head) || !free_vmemmap_pages_per_hpage(h)) + return; + + page =3D head + page_private(head + 4); + + /* + * Move PageHWPoison flag from head page to the raw error page, + * which makes any subpages rather than the error page reusable. + */ + if (page !=3D head) { + SetPageHWPoison(page); + ClearPageHWPoison(head); + } +} + +static inline void hwpoison_subpage_set(struct hstate *h, struct page *h= ead, + struct page *page) +{ + if (!PageHWPoison(head)) + return; + + if (free_vmemmap_pages_per_hpage(h)) { + set_page_private(head + 4, page - head); + } else if (page !=3D head) { + /* + * Move PageHWPoison flag from head page to the raw error page, + * which makes any subpages rather than the error page reusable. + */ + SetPageHWPoison(page); + ClearPageHWPoison(head); + } +} + +static inline void hwpoison_subpage_clear(struct hstate *h, struct page = *head) +{ + if (!PageHWPoison(head) || !free_vmemmap_pages_per_hpage(h)) + return; + + set_page_private(head + 4, 0); +} +#else +static inline void hwpoison_subpage_deliver(struct hstate *h, struct pag= e *head) +{ +} + +static inline void hwpoison_subpage_set(struct hstate *h, struct page *h= ead, + struct page *page) +{ + if (PageHWPoison(head) && page !=3D head) { + /* + * Move PageHWPoison flag from head page to the raw error page, + * which makes any subpages rather than the error page reusable. + */ + SetPageHWPoison(page); + ClearPageHWPoison(head); + } +} + +static inline void hwpoison_subpage_clear(struct hstate *h, struct page = *head) +{ +} +#endif + static int update_and_free_page(struct hstate *h, struct page *page) __releases(&hugetlb_lock) __acquires(&hugetlb_lock) { @@ -1351,6 +1419,8 @@ static int update_and_free_page(struct hstate *h, s= truct page *page) return -ENOMEM; } =20 + hwpoison_subpage_deliver(h, page); + for (i =3D 0; i < pages_per_huge_page(h); i++) { page[i].flags &=3D ~(1 << PG_locked | 1 << PG_error | 1 << PG_referenced | 1 << PG_dirty | @@ -1795,22 +1865,17 @@ int dissolve_free_huge_page(struct page *page) goto retry; } =20 - /* - * Move PageHWPoison flag from head page to the raw error page, - * which makes any subpages rather than the error page reusable. - */ - if (PageHWPoison(head) && page !=3D head) { - SetPageHWPoison(page); - ClearPageHWPoison(head); - } + hwpoison_subpage_set(h, head, page); ClearHPageFreed(page); list_del(&head->lru); h->free_huge_pages--; h->free_huge_pages_node[nid]--; h->max_huge_pages--; rc =3D update_and_free_page(h, head); - if (rc) + if (rc) { h->max_huge_pages++; + hwpoison_subpage_clear(h, head); + } } out: spin_unlock(&hugetlb_lock); diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c index 29a3380f3b20..f7ab3d99250a 100644 --- a/mm/hugetlb_vmemmap.c +++ b/mm/hugetlb_vmemmap.c @@ -181,18 +181,6 @@ #define RESERVE_VMEMMAP_NR 2U #define RESERVE_VMEMMAP_SIZE (RESERVE_VMEMMAP_NR << PAGE_SHIFT) =20 -/* - * How many vmemmap pages associated with a HugeTLB page that can be fre= ed - * to the buddy allocator. - * - * Todo: Returns zero for now, which means the feature is disabled. We w= ill - * enable it once all the infrastructure is there. - */ -static inline unsigned int free_vmemmap_pages_per_hpage(struct hstate *h= ) -{ - return 0; -} - static inline unsigned long free_vmemmap_pages_size_per_hpage(struct hst= ate *h) { return (unsigned long)free_vmemmap_pages_per_hpage(h) << PAGE_SHIFT; diff --git a/mm/hugetlb_vmemmap.h b/mm/hugetlb_vmemmap.h index e5547d53b9f5..a37771b0b82a 100644 --- a/mm/hugetlb_vmemmap.h +++ b/mm/hugetlb_vmemmap.h @@ -13,6 +13,18 @@ #ifdef CONFIG_HUGETLB_PAGE_FREE_VMEMMAP int alloc_huge_page_vmemmap(struct hstate *h, struct page *head); void free_huge_page_vmemmap(struct hstate *h, struct page *head); + +/* + * How many vmemmap pages associated with a HugeTLB page that can be fre= ed + * to the buddy allocator. + * + * Todo: Returns zero for now, which means the feature is disabled. We w= ill + * enable it once all the infrastructure is there. + */ +static inline unsigned int free_vmemmap_pages_per_hpage(struct hstate *h= ) +{ + return 0; +} #else static inline int alloc_huge_page_vmemmap(struct hstate *h, struct page = *head) { @@ -22,5 +34,10 @@ static inline int alloc_huge_page_vmemmap(struct hstat= e *h, struct page *head) static inline void free_huge_page_vmemmap(struct hstate *h, struct page = *head) { } + +static inline unsigned int free_vmemmap_pages_per_hpage(struct hstate *h= ) +{ + return 0; +} #endif /* CONFIG_HUGETLB_PAGE_FREE_VMEMMAP */ #endif /* _LINUX_HUGETLB_VMEMMAP_H */ --=20 2.11.0