Skip to content

Commit 1090302

Browse files
tehcastertorvalds
authored andcommitted
mm, page_owner: don't grab zone->lock for init_pages_in_zone()
init_pages_in_zone() is run under zone->lock, which means a long lock time and disabled interrupts on large machines. This is currently not an issue since it runs early in boot, but a later patch will change that. However, like other pfn scanners, we don't actually need zone->lock even when other cpus are running. The only potentially dangerous operation here is reading bogus buddy page owner due to race, and we already know how to handle that. The worst that can happen is that we skip some early allocated pages, which should not affect the debugging power of page_owner noticeably. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Vlastimil Babka <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Yang Shi <[email protected]> Cc: Laura Abbott <[email protected]> Cc: Vinayak Menon <[email protected]> Cc: zhong jiang <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 0fc542b commit 1090302

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

mm/page_owner.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,17 @@ static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone)
562562
continue;
563563

564564
/*
565-
* We are safe to check buddy flag and order, because
566-
* this is init stage and only single thread runs.
565+
* To avoid having to grab zone->lock, be a little
566+
* careful when reading buddy page order. The only
567+
* danger is that we skip too much and potentially miss
568+
* some early allocated pages, which is better than
569+
* heavy lock contention.
567570
*/
568571
if (PageBuddy(page)) {
569-
pfn += (1UL << page_order(page)) - 1;
572+
unsigned long order = page_order_unsafe(page);
573+
574+
if (order > 0 && order < MAX_ORDER)
575+
pfn += (1UL << order) - 1;
570576
continue;
571577
}
572578

@@ -585,6 +591,7 @@ static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone)
585591
__set_page_owner_handle(page_ext, early_handle, 0, 0);
586592
count++;
587593
}
594+
cond_resched();
588595
}
589596

590597
pr_info("Node %d, zone %8s: page owner found early allocated %lu pages\n",
@@ -595,15 +602,12 @@ static void init_zones_in_node(pg_data_t *pgdat)
595602
{
596603
struct zone *zone;
597604
struct zone *node_zones = pgdat->node_zones;
598-
unsigned long flags;
599605

600606
for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) {
601607
if (!populated_zone(zone))
602608
continue;
603609

604-
spin_lock_irqsave(&zone->lock, flags);
605610
init_pages_in_zone(pgdat, zone);
606-
spin_unlock_irqrestore(&zone->lock, flags);
607611
}
608612
}
609613

0 commit comments

Comments
 (0)