The patch titled Subject: mm, page_alloc: use check_pages_enabled static key to check tail pages has been added to the -mm mm-unstable branch. Its filename is mm-page_alloc-use-check_pages_enabled-static-key-to-check-tail-pages.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-page_alloc-use-check_pages_enabled-static-key-to-check-tail-pages.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Vlastimil Babka <vbabka@xxxxxxx> Subject: mm, page_alloc: use check_pages_enabled static key to check tail pages Date: Wed, 5 Apr 2023 16:28:40 +0200 Commit 700d2e9a36b9 ("mm, page_alloc: reduce page alloc/free sanity checks") has introduced a new static key check_pages_enabled to control when struct pages are sanity checked during allocation and freeing. Mel Gorman suggested that free_tail_pages_check() could use this static key as well, instead of relying on CONFIG_DEBUG_VM. That makes sense, so do that. Also rename the function to free_tail_page_prepare() because it works on a single tail page and has a struct page preparation component as well as the optional checking component. Also remove some unnecessary unlikely() within static_branch_unlikely() statements that Mel pointed out for commit 700d2e9a36b9. Link: https://lkml.kernel.org/r/20230405142840.11068-1-vbabka@xxxxxxx Signed-off-by: Vlastimil Babka <vbabka@xxxxxxx> Suggested-by: Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx> Acked-by: Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx> Cc: Alexander Halbuer <halbuer@xxxxxxxxxxxxxxxxxxx> Cc: Kees Cook <keescook@xxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/hugetlb_vmemmap.c | 2 +- mm/page_alloc.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) --- a/mm/hugetlb_vmemmap.c~mm-page_alloc-use-check_pages_enabled-static-key-to-check-tail-pages +++ a/mm/hugetlb_vmemmap.c @@ -264,7 +264,7 @@ static void vmemmap_remap_pte(pte_t *pte * How many struct page structs need to be reset. When we reuse the head * struct page, the special metadata (e.g. page->flags or page->mapping) * cannot copy to the tail struct page structs. The invalid value will be - * checked in the free_tail_pages_check(). In order to avoid the message + * checked in the free_tail_page_prepare(). In order to avoid the message * of "corrupted mapping in tail page". We need to reset at least 3 (one * head struct page struct and two tail struct page structs) struct page * structs. --- a/mm/page_alloc.c~mm-page_alloc-use-check_pages_enabled-static-key-to-check-tail-pages +++ a/mm/page_alloc.c @@ -1131,7 +1131,7 @@ static inline bool free_page_is_bad(stru return true; } -static int free_tail_pages_check(struct page *head_page, struct page *page) +static int free_tail_page_prepare(struct page *head_page, struct page *page) { struct folio *folio = (struct folio *)head_page; int ret = 1; @@ -1142,7 +1142,7 @@ static int free_tail_pages_check(struct */ BUILD_BUG_ON((unsigned long)LIST_POISON1 & 1); - if (!IS_ENABLED(CONFIG_DEBUG_VM)) { + if (!static_branch_unlikely(&check_pages_enabled)) { ret = 0; goto out; } @@ -1276,9 +1276,9 @@ static __always_inline bool free_pages_p ClearPageHasHWPoisoned(page); for (i = 1; i < (1 << order); i++) { if (compound) - bad += free_tail_pages_check(page, page + i); + bad += free_tail_pages_prepare(page, page + i); if (is_check_pages_enabled()) { - if (unlikely(free_page_is_bad(page + i))) { + if (free_page_is_bad(page + i)) { bad++; continue; } @@ -1627,7 +1627,7 @@ static inline bool check_new_pages(struc for (int i = 0; i < (1 << order); i++) { struct page *p = page + i; - if (unlikely(check_new_page(p))) + if (check_new_page(p)) return true; } } _ Patches currently in -mm which might be from vbabka@xxxxxxx are mm-mmap-vma_merge-use-only-primary-pointers-for-preparing-merge.patch mm-mmap-vma_merge-use-the-proper-vma-pointer-in-case-3.patch mm-mmap-vma_merge-use-the-proper-vma-pointers-in-cases-1-and-6.patch mm-mmap-vma_merge-use-the-proper-vma-pointer-in-case-4.patch mm-mmap-vma_merge-initialize-mid-and-next-in-natural-order.patch mm-mmap-vma_merge-set-mid-to-null-if-not-applicable.patch mm-mmap-vma_merge-set-mid-to-null-if-not-applicable-fix.patch mm-mmap-vma_merge-rename-adj_next-to-adj_start.patch mm-mmap-vma_merge-convert-mergeability-checks-to-return-bool.patch mm-mmap-start-distinguishing-if-vma-can-be-removed-in-mergeability-test.patch mm-mmap-start-distinguishing-if-vma-can-be-removed-in-mergeability-test-fix.patch mm-mremap-simplify-vma-expansion-again.patch mm-page_alloc-use-check_pages_enabled-static-key-to-check-tail-pages.patch