Skip to content

Commit 504e070

Browse files
yang-shitorvalds
authored andcommitted
mm: thp: replace DEBUG_VM BUG with VM_WARN when unmap fails for split
When debugging the bug reported by Wang Yugui [1], try_to_unmap() may fail, but the first VM_BUG_ON_PAGE() just checks page_mapcount() however it may miss the failure when head page is unmapped but other subpage is mapped. Then the second DEBUG_VM BUG() that check total mapcount would catch it. This may incur some confusion. As this is not a fatal issue, so consolidate the two DEBUG_VM checks into one VM_WARN_ON_ONCE_PAGE(). [1] https://lore.kernel.org/linux-mm/[email protected]/ Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Yang Shi <[email protected]> Reviewed-by: Zi Yan <[email protected]> Acked-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Hugh Dickins <[email protected]> Cc: Alistair Popple <[email protected]> Cc: Jan Kara <[email protected]> Cc: Jue Wang <[email protected]> Cc: "Matthew Wilcox (Oracle)" <[email protected]> Cc: Miaohe Lin <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Naoya Horiguchi <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: Peter Xu <[email protected]> Cc: Ralph Campbell <[email protected]> Cc: Shakeel Butt <[email protected]> Cc: Wang Yugui <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 22061a1 commit 504e070

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

mm/huge_memory.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,15 +2352,15 @@ static void unmap_page(struct page *page)
23522352
{
23532353
enum ttu_flags ttu_flags = TTU_IGNORE_MLOCK | TTU_SYNC |
23542354
TTU_RMAP_LOCKED | TTU_SPLIT_HUGE_PMD;
2355-
bool unmap_success;
23562355

23572356
VM_BUG_ON_PAGE(!PageHead(page), page);
23582357

23592358
if (PageAnon(page))
23602359
ttu_flags |= TTU_SPLIT_FREEZE;
23612360

2362-
unmap_success = try_to_unmap(page, ttu_flags);
2363-
VM_BUG_ON_PAGE(!unmap_success, page);
2361+
try_to_unmap(page, ttu_flags);
2362+
2363+
VM_WARN_ON_ONCE_PAGE(page_mapped(page), page);
23642364
}
23652365

23662366
static void remap_page(struct page *page, unsigned int nr)
@@ -2671,7 +2671,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
26712671
struct deferred_split *ds_queue = get_deferred_split_queue(head);
26722672
struct anon_vma *anon_vma = NULL;
26732673
struct address_space *mapping = NULL;
2674-
int count, mapcount, extra_pins, ret;
2674+
int extra_pins, ret;
26752675
pgoff_t end;
26762676

26772677
VM_BUG_ON_PAGE(is_huge_zero_page(head), head);
@@ -2730,7 +2730,6 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
27302730
}
27312731

27322732
unmap_page(head);
2733-
VM_BUG_ON_PAGE(compound_mapcount(head), head);
27342733

27352734
/* block interrupt reentry in xa_lock and spinlock */
27362735
local_irq_disable();
@@ -2748,9 +2747,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
27482747

27492748
/* Prevent deferred_split_scan() touching ->_refcount */
27502749
spin_lock(&ds_queue->split_queue_lock);
2751-
count = page_count(head);
2752-
mapcount = total_mapcount(head);
2753-
if (!mapcount && page_ref_freeze(head, 1 + extra_pins)) {
2750+
if (page_ref_freeze(head, 1 + extra_pins)) {
27542751
if (!list_empty(page_deferred_list(head))) {
27552752
ds_queue->split_queue_len--;
27562753
list_del(page_deferred_list(head));
@@ -2770,16 +2767,9 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
27702767
__split_huge_page(page, list, end);
27712768
ret = 0;
27722769
} else {
2773-
if (IS_ENABLED(CONFIG_DEBUG_VM) && mapcount) {
2774-
pr_alert("total_mapcount: %u, page_count(): %u\n",
2775-
mapcount, count);
2776-
if (PageTail(page))
2777-
dump_page(head, NULL);
2778-
dump_page(page, "total_mapcount(head) > 0");
2779-
BUG();
2780-
}
27812770
spin_unlock(&ds_queue->split_queue_lock);
2782-
fail: if (mapping)
2771+
fail:
2772+
if (mapping)
27832773
xa_unlock(&mapping->i_pages);
27842774
local_irq_enable();
27852775
remap_page(head, thp_nr_pages(head));

0 commit comments

Comments
 (0)