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 AC59DC54E64 for ; Mon, 25 Mar 2024 20:41:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35D5D6B008A; Mon, 25 Mar 2024 16:41:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30DC06B0092; Mon, 25 Mar 2024 16:41:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D5D66B0098; Mon, 25 Mar 2024 16:41:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0BB086B008A for ; Mon, 25 Mar 2024 16:41:31 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CC9721A078A for ; Mon, 25 Mar 2024 20:41:30 +0000 (UTC) X-FDA: 81936731940.15.F2F6715 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf19.hostedemail.com (Postfix) with ESMTP id 5A0FC1A000E for ; Mon, 25 Mar 2024 20:41:26 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=NiHmlwCX; dmarc=none; spf=none (imf19.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711399288; a=rsa-sha256; cv=none; b=EdNP7dtNJu/nYilla79rlKlbjnW4mSUbL+x18O6QYPDGgHvuNwrW6c8RwhL9nvBfO/Q831 +tHY39buNaZDpVY7cNKKruLQCI9NkHrDNMW1PW4dRV1Uol2yD3Le2bsqX03oGdurabxxKF 1c32QbHPFeaMSDH4gFvMtiQHU4Bm+7o= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=NiHmlwCX; dmarc=none; spf=none (imf19.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711399288; 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=0icdOYvBfczQVvEJDek72+T+UPwfLX66qrhrQKmpSOg=; b=HUib9+O4yYdu+hKbFJS4UK9sKosTfK7gHt9k46WLjC/AfM+bQ5hyVsJ+yztNq7lq5mGR15 wXdaOIRT2H6VnGkUkA7vC+KWAu6LtO+h30CpKBBrLos/L4Fir9SyY3v2ayAQvXMiqQ8VsC RsuwBMMhggVDrx9LBUqQMo8RYVd6IRs= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=0icdOYvBfczQVvEJDek72+T+UPwfLX66qrhrQKmpSOg=; b=NiHmlwCXYy4iOGzVbpU+fdLeV8 wEFrmlzoqShMKViw1J7imGwlGpXK8CTceVWmKQtaSRVbnjSveIN1e5QniIqU+apdY3A95zVTVN+Ob 2t61zgFkVbBgIg39yxZZ+ZOrhP9xwf0PTM4HJcB22900kMCFqW8Thj2lbUe7NNbj8LvjBijR1vKHo K7JPPtPQrMo6OBCVgQ8AxF6WvmJHrhhH8P/0lHsCaaDYmlVXlDkrdhk4F6q2dmiYXAY0PoodJxJRL J0zNj7rQDg27p5SLmKxnORbxK9cWNRVl4ROwiCQiEaO0kEhLV+cbTTGPVkFid25/KWHUckFmIUJaZ 3+omlLGw==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1ror8E-0000000HIUH-15ot; Mon, 25 Mar 2024 20:41:22 +0000 Date: Mon, 25 Mar 2024 20:41:22 +0000 From: Matthew Wilcox To: Andrew Morton Cc: Vlastimil Babka , Luis Chamberlain , linux-mm@kvack.org, David Hildenbrand , Miaohe Lin , Muchun Song , Oscar Salvador Subject: Re: [PATCH 5/9] mm: Turn folio_test_hugetlb into a PageType Message-ID: References: <20240321142448.1645400-1-willy@infradead.org> <20240321142448.1645400-6-willy@infradead.org> <7ee2bb8c-441a-418b-ba3a-d305f69d31c8@suse.cz> <20240325114813.38108944f75bb005141c1299@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240325114813.38108944f75bb005141c1299@linux-foundation.org> X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5A0FC1A000E X-Stat-Signature: aenejn4c7b3cdykjggnz3w433eorkhot X-HE-Tag: 1711399286-289175 X-HE-Meta: U2FsdGVkX1+OIBJXp+5FIIkJl9a8zWQgFjfSbyrAqDxqxKY+9KzLij5N8sr8jP7pOQCFEoK20yQHgZg2BY32KAo+SPNBbWlM6Lg8wLRCtHVOlxBSomOnrIfYk1ri/Ndh6kCdNZrR9afgidpA5cHgUKhdPaNrfoZVCyFTbwMDN4xyA9Pbz72+LnXgeSwio0c709LqTL62aZved/EZ83SdeToTdr6Kj5Sex15aA1SMfD965NAOfD3Utd4RhwHp676LbNm6MFYjz5foGAoaSslbAsr0/lEMjEgPCIW3gNo8pKoVljPRRxa9Nw1S1iWsXisM2I+4BNObzzEEBC40htNPabsMzjeCprZFr1lOyKAIz3eeWilVzYO6O4u8muHWiaFvWIJP0B0YXUBWTIhJcLPOG8F8bxw4o+jIo5i4/kcz3v/klu0u3ANapYq2j8Da0SWDx/fkfYNJSCVRvW6ERVo2Uk4rQfRmcCwk7cauzkBpTshOdm09DDjMCulIj47VbRuE3oCXDrXHfUreIy1gLP9e8d56tYIZYMzTEiq199heznzStjaAf4mT3QaklmEBn1mTopK0f0O/KdEjYcMq1eS1OgAIXjqqas9khFjZp5XGO+maJiPWAQZPYoH/FQESOIWAtp6CYSl/lF4RzWVqg0lPwdZqzdxDf3ZYonI7iW234TEi1kozVlnC94lTgzYqjryt8UjoTPhOtQlY9OjhDy7oKwMujP8P+aQke3v4l4f9CHlU5/jGObSN5Xg5WDOIAtHH1uhyqAgFlRtld/yd3ElZeQXkaXiP1PJiaFEYdE6iqalxMd6MCbkKu1WvDQWmktznFzRr+ET9kN/vVU0cBPp8Bc3BdVxNa8nQL77LoO9dD/Z8kVHq2OprqRuclzaKj0GHcyxpD8t+6quJaYh4UIsrghtCECYUrbisZBPhjtkMzIKLwvNbpRor6XhJ4ERcy/Z/rJRYjB0/+bcJ67Ks+V4 a5zkmh6T 3zv9cnBYaR1QhGi8OYtZEG1UasK9i14wZqebQ4huSxWFYx0Xzx2ala76gipukNYQaXG3+aJPCOJMRR8VmoL9L1JhEWaqSlSLZ1qh8j5S1OHCEK6IlfsmlE/XYNt0bZ4h9ID5Ce+SOvmi4w7KpD+Ozl191UV4aGWWT3enrddi4wjYXhqZO1x10iUxAiwCuM1mS2OBYXg6SdC5uF98KmVdGqahuWwSV9zQ5oLe3ErzsrOqsO9QIMEcojRAemg== 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 Mon, Mar 25, 2024 at 11:48:13AM -0700, Andrew Morton wrote: > On Mon, 25 Mar 2024 08:57:52 +0100 Vlastimil Babka wrote: > > Reported-by: Luis Chamberlain > > Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218227 > > Fixes: 9c5ccf2db04b ("mm: remove HUGETLB_PAGE_DTOR") > > Cc: > > Thanks. > > The patch doesn't work as a standalone thing. No, it depends on both mm: support page_mapcount() on page_has_type() pages mm: create FOLIO_FLAG_FALSE and FOLIO_TYPE_OPS macros I was assuming both would get backported as dependencies. If you want a standalone patch, something like this would do the trick. > Matthew, could you please redo this patch (and its vmcore fix) and send > as a standalone -stable patch? It could be that the "Various > significant MM patches" will need a redo afterwards. I'd rather keep the mapcount patch separate for upstream purposes. I've build-tested against 6.6.22 with allmodconfig and then with HUGETLB=n (but otherwise allmodconfig) diff --git a/include/linux/mm.h b/include/linux/mm.h index bf5d0b1b16f4..5e15004eab8c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1192,6 +1192,9 @@ static inline int page_mapcount(struct page *page) { int mapcount = atomic_read(&page->_mapcount) + 1; + /* Handle page_has_type() pages */ + if (mapcount < 0) + mapcount = 0; if (unlikely(PageCompound(page))) mapcount += folio_entire_mapcount(page_folio(page)); diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 5c02720c53a5..4d5f750551c5 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -190,7 +190,6 @@ enum pageflags { /* At least one page in this folio has the hwpoison flag set */ PG_has_hwpoisoned = PG_error, - PG_hugetlb = PG_active, PG_large_rmappable = PG_workingset, /* anon or file-backed */ }; @@ -815,29 +814,6 @@ TESTPAGEFLAG_FALSE(LargeRmappable, large_rmappable) #define PG_head_mask ((1UL << PG_head)) -#ifdef CONFIG_HUGETLB_PAGE -int PageHuge(struct page *page); -SETPAGEFLAG(HugeTLB, hugetlb, PF_SECOND) -CLEARPAGEFLAG(HugeTLB, hugetlb, PF_SECOND) - -/** - * folio_test_hugetlb - Determine if the folio belongs to hugetlbfs - * @folio: The folio to test. - * - * Context: Any context. Caller should have a reference on the folio to - * prevent it from being turned into a tail page. - * Return: True for hugetlbfs folios, false for anon folios or folios - * belonging to other filesystems. - */ -static inline bool folio_test_hugetlb(struct folio *folio) -{ - return folio_test_large(folio) && - test_bit(PG_hugetlb, folio_flags(folio, 1)); -} -#else -TESTPAGEFLAG_FALSE(Huge, hugetlb) -#endif - #ifdef CONFIG_TRANSPARENT_HUGEPAGE /* * PageHuge() only returns true for hugetlbfs pages, but not for @@ -893,18 +869,6 @@ PAGEFLAG_FALSE(HasHWPoisoned, has_hwpoisoned) TESTSCFLAG_FALSE(HasHWPoisoned, has_hwpoisoned) #endif -/* - * Check if a page is currently marked HWPoisoned. Note that this check is - * best effort only and inherently racy: there is no way to synchronize with - * failing hardware. - */ -static inline bool is_page_hwpoison(struct page *page) -{ - if (PageHWPoison(page)) - return true; - return PageHuge(page) && PageHWPoison(compound_head(page)); -} - /* * For pages that are never mapped to userspace (and aren't PageSlab), * page_type may be used. Because it is initialised to -1, we invert the @@ -921,6 +885,7 @@ static inline bool is_page_hwpoison(struct page *page) #define PG_offline 0x00000100 #define PG_table 0x00000200 #define PG_guard 0x00000400 +#define PG_hugetlb 0x00000800 #define PageType(page, flag) \ ((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE) @@ -1012,6 +977,37 @@ PAGE_TYPE_OPS(Table, table, pgtable) */ PAGE_TYPE_OPS(Guard, guard, guard) +#ifdef CONFIG_HUGETLB_PAGE +PAGE_TYPE_OPS(HeadHugeTLB, hugetlb, hugetlb) + +/** + * PageHuge - Determine if the folio belongs to hugetlbfs. + * @page: The page to test. + * + * Context: Any context. + * Return: True for hugetlbfs folios, false for anon folios or folios + * belonging to other filesystems. + */ +static inline bool PageHuge(const struct page *page) +{ + return folio_test_hugetlb(page_folio(page)); +} +#else +TESTPAGEFLAG_FALSE(Huge, hugetlb) +#endif + +/* + * Check if a page is currently marked HWPoisoned. Note that this check is + * best effort only and inherently racy: there is no way to synchronize with + * failing hardware. + */ +static inline bool is_page_hwpoison(struct page *page) +{ + if (PageHWPoison(page)) + return true; + return PageHuge(page) && PageHWPoison(compound_head(page)); +} + extern bool is_free_buddy_page(struct page *page); PAGEFLAG(Isolated, isolated, PF_ANY); @@ -1078,7 +1074,7 @@ static __always_inline void __ClearPageAnonExclusive(struct page *page) */ #define PAGE_FLAGS_SECOND \ (0xffUL /* order */ | 1UL << PG_has_hwpoisoned | \ - 1UL << PG_hugetlb | 1UL << PG_large_rmappable) + 1UL << PG_large_rmappable) #define PAGE_FLAGS_PRIVATE \ (1UL << PG_private | 1UL << PG_private_2) diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h index 1478b9dd05fa..e010618f9326 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -135,6 +135,7 @@ IF_HAVE_PG_ARCH_X(arch_3) #define DEF_PAGETYPE_NAME(_name) { PG_##_name, __stringify(_name) } #define __def_pagetype_names \ + DEF_PAGETYPE_NAME(hugetlb), \ DEF_PAGETYPE_NAME(offline), \ DEF_PAGETYPE_NAME(guard), \ DEF_PAGETYPE_NAME(table), \ diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 2f675ef045d4..a2face7fbef8 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -675,8 +675,8 @@ static int __init crash_save_vmcoreinfo_init(void) VMCOREINFO_NUMBER(PG_head_mask); #define PAGE_BUDDY_MAPCOUNT_VALUE (~PG_buddy) VMCOREINFO_NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE); -#ifdef CONFIG_HUGETLB_PAGE - VMCOREINFO_NUMBER(PG_hugetlb); +#define PAGE_HUGETLB_MAPCOUNT_VALUE (~PG_hugetlb) + VMCOREINFO_NUMBER(PAGE_HUGETLB_MAPCOUNT_VALUE); #define PAGE_OFFLINE_MAPCOUNT_VALUE (~PG_offline) VMCOREINFO_NUMBER(PAGE_OFFLINE_MAPCOUNT_VALUE); #endif diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5e6c4d367d33..30b713d330ca 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1630,7 +1630,7 @@ static inline void __clear_hugetlb_destructor(struct hstate *h, { lockdep_assert_held(&hugetlb_lock); - folio_clear_hugetlb(folio); + __folio_clear_hugetlb(folio); } /* @@ -1717,7 +1717,7 @@ static void add_hugetlb_folio(struct hstate *h, struct folio *folio, h->surplus_huge_pages_node[nid]++; } - folio_set_hugetlb(folio); + __folio_set_hugetlb(folio); folio_change_private(folio, NULL); /* * We have to set hugetlb_vmemmap_optimized again as above @@ -1971,7 +1971,7 @@ static void __prep_new_hugetlb_folio(struct hstate *h, struct folio *folio) { hugetlb_vmemmap_optimize(h, &folio->page); INIT_LIST_HEAD(&folio->lru); - folio_set_hugetlb(folio); + __folio_set_hugetlb(folio); hugetlb_set_folio_subpool(folio, NULL); set_hugetlb_cgroup(folio, NULL); set_hugetlb_cgroup_rsvd(folio, NULL); @@ -2074,22 +2074,6 @@ static bool prep_compound_gigantic_folio_for_demote(struct folio *folio, return __prep_compound_gigantic_folio(folio, order, true); } -/* - * PageHuge() only returns true for hugetlbfs pages, but not for normal or - * transparent huge pages. See the PageTransHuge() documentation for more - * details. - */ -int PageHuge(struct page *page) -{ - struct folio *folio; - - if (!PageCompound(page)) - return 0; - folio = page_folio(page); - return folio_test_hugetlb(folio); -} -EXPORT_SYMBOL_GPL(PageHuge); - /* * Find and lock address space (mapping) in write mode. *