Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/page_owner: correct owner information for early allocated pages

Extended memory to store page owner information is initialized some time
later than that page allocator starts. Until initialization, many pages
can be allocated and they have no owner information. This make debugging
using page owner harder, so some fixup will be helpful.

This patch fixes up this situation by setting fake owner information
immediately after page extension is initialized. Information doesn't tell
the right owner, but, at least, it can tell whether page is allocated or
not, more correctly.

On my testing, this patch catches 13343 early allocated pages, although
they are mostly allocated from page extension feature. Anyway, after
then, there is no page left that it is allocated and has no page owner
flag.

Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Dave Hansen <dave@sr71.net>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Jungsoo Son <jungsoo.son@lge.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Joonsoo Kim and committed by
Linus Torvalds
61cf5feb 48c96a36

+91 -2
+91 -2
mm/page_owner.c
··· 10 10 static bool page_owner_disabled = true; 11 11 bool page_owner_inited __read_mostly; 12 12 13 + static void init_early_allocated_pages(void); 14 + 13 15 static int early_page_owner_param(char *buf) 14 16 { 15 17 if (!buf) ··· 38 36 return; 39 37 40 38 page_owner_inited = true; 39 + init_early_allocated_pages(); 41 40 } 42 41 43 42 struct page_ext_operations page_owner_ops = { ··· 187 184 page_ext = lookup_page_ext(page); 188 185 189 186 /* 190 - * Pages allocated before initialization of page_owner are 191 - * non-buddy and have no page_owner info. 187 + * Some pages could be missed by concurrent allocation or free, 188 + * because we don't hold the zone lock. 192 189 */ 193 190 if (!test_bit(PAGE_EXT_OWNER, &page_ext->flags)) 194 191 continue; ··· 200 197 } 201 198 202 199 return 0; 200 + } 201 + 202 + static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone) 203 + { 204 + struct page *page; 205 + struct page_ext *page_ext; 206 + unsigned long pfn = zone->zone_start_pfn, block_end_pfn; 207 + unsigned long end_pfn = pfn + zone->spanned_pages; 208 + unsigned long count = 0; 209 + 210 + /* Scan block by block. First and last block may be incomplete */ 211 + pfn = zone->zone_start_pfn; 212 + 213 + /* 214 + * Walk the zone in pageblock_nr_pages steps. If a page block spans 215 + * a zone boundary, it will be double counted between zones. This does 216 + * not matter as the mixed block count will still be correct 217 + */ 218 + for (; pfn < end_pfn; ) { 219 + if (!pfn_valid(pfn)) { 220 + pfn = ALIGN(pfn + 1, MAX_ORDER_NR_PAGES); 221 + continue; 222 + } 223 + 224 + block_end_pfn = ALIGN(pfn + 1, pageblock_nr_pages); 225 + block_end_pfn = min(block_end_pfn, end_pfn); 226 + 227 + page = pfn_to_page(pfn); 228 + 229 + for (; pfn < block_end_pfn; pfn++) { 230 + if (!pfn_valid_within(pfn)) 231 + continue; 232 + 233 + page = pfn_to_page(pfn); 234 + 235 + /* 236 + * We are safe to check buddy flag and order, because 237 + * this is init stage and only single thread runs. 238 + */ 239 + if (PageBuddy(page)) { 240 + pfn += (1UL << page_order(page)) - 1; 241 + continue; 242 + } 243 + 244 + if (PageReserved(page)) 245 + continue; 246 + 247 + page_ext = lookup_page_ext(page); 248 + 249 + /* Maybe overraping zone */ 250 + if (test_bit(PAGE_EXT_OWNER, &page_ext->flags)) 251 + continue; 252 + 253 + /* Found early allocated page */ 254 + set_page_owner(page, 0, 0); 255 + count++; 256 + } 257 + } 258 + 259 + pr_info("Node %d, zone %8s: page owner found early allocated %lu pages\n", 260 + pgdat->node_id, zone->name, count); 261 + } 262 + 263 + static void init_zones_in_node(pg_data_t *pgdat) 264 + { 265 + struct zone *zone; 266 + struct zone *node_zones = pgdat->node_zones; 267 + unsigned long flags; 268 + 269 + for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) { 270 + if (!populated_zone(zone)) 271 + continue; 272 + 273 + spin_lock_irqsave(&zone->lock, flags); 274 + init_pages_in_zone(pgdat, zone); 275 + spin_unlock_irqrestore(&zone->lock, flags); 276 + } 277 + } 278 + 279 + static void init_early_allocated_pages(void) 280 + { 281 + pg_data_t *pgdat; 282 + 283 + drain_all_pages(NULL); 284 + for_each_online_pgdat(pgdat) 285 + init_zones_in_node(pgdat); 203 286 } 204 287 205 288 static const struct file_operations proc_page_owner_operations = {