Skip to content

Commit 5f24ce5

Browse files
aarcange-rhtorvalds
authored andcommitted
thp: remove PG_buddy
PG_buddy can be converted to _mapcount == -2. So the PG_compound_lock can be added to page->flags without overflowing (because of the sparse section bits increasing) with CONFIG_X86_PAE=y and CONFIG_X86_PAT=y. This also has to move the memory hotplug code from _mapcount to lru.next to avoid any risk of clashes. We can't use lru.next for PG_buddy removal, but memory hotplug can use lru.next even more easily than the mapcount instead. Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 21ae5b0 commit 5f24ce5

7 files changed

Lines changed: 52 additions & 29 deletions

File tree

‎fs/proc/page.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,17 @@ u64 stable_page_flags(struct page *page)
116116
if (PageHuge(page))
117117
u |= 1 << KPF_HUGE;
118118

119-
u |= kpf_copy_bit(k, KPF_LOCKED, PG_locked);
120-
121119
/*
122-
* Caveats on high order pages:
123-
* PG_buddy will only be set on the head page; SLUB/SLQB do the same
124-
* for PG_slab; SLOB won't set PG_slab at all on compound pages.
120+
* Caveats on high order pages: page->_count will only be set
121+
* -1 on the head page; SLUB/SLQB do the same for PG_slab;
122+
* SLOB won't set PG_slab at all on compound pages.
125123
*/
124+
if (PageBuddy(page))
125+
u |= 1 << KPF_BUDDY;
126+
127+
u |= kpf_copy_bit(k, KPF_LOCKED, PG_locked);
128+
126129
u |= kpf_copy_bit(k, KPF_SLAB, PG_slab);
127-
u |= kpf_copy_bit(k, KPF_BUDDY, PG_buddy);
128130

129131
u |= kpf_copy_bit(k, KPF_ERROR, PG_error);
130132
u |= kpf_copy_bit(k, KPF_DIRTY, PG_dirty);

‎include/linux/memory_hotplug.h‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ struct mem_section;
1313
#ifdef CONFIG_MEMORY_HOTPLUG
1414

1515
/*
16-
* Types for free bootmem.
17-
* The normal smallest mapcount is -1. Here is smaller value than it.
16+
* Types for free bootmem stored in page->lru.next. These have to be in
17+
* some random range in unsigned long space for debugging purposes.
1818
*/
19-
#define SECTION_INFO (-1 - 1)
20-
#define MIX_SECTION_INFO (-1 - 2)
21-
#define NODE_INFO (-1 - 3)
19+
enum {
20+
MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE = 12,
21+
SECTION_INFO = MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE,
22+
MIX_SECTION_INFO,
23+
NODE_INFO,
24+
MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE = NODE_INFO,
25+
};
2226

2327
/*
2428
* pgdat resizing functions

‎include/linux/mm.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,27 @@ static inline void init_page_count(struct page *page)
397397
atomic_set(&page->_count, 1);
398398
}
399399

400+
/*
401+
* PageBuddy() indicate that the page is free and in the buddy system
402+
* (see mm/page_alloc.c).
403+
*/
404+
static inline int PageBuddy(struct page *page)
405+
{
406+
return atomic_read(&page->_mapcount) == -2;
407+
}
408+
409+
static inline void __SetPageBuddy(struct page *page)
410+
{
411+
VM_BUG_ON(atomic_read(&page->_mapcount) != -1);
412+
atomic_set(&page->_mapcount, -2);
413+
}
414+
415+
static inline void __ClearPageBuddy(struct page *page)
416+
{
417+
VM_BUG_ON(!PageBuddy(page));
418+
atomic_set(&page->_mapcount, -1);
419+
}
420+
400421
void put_page(struct page *page);
401422
void put_pages_list(struct list_head *pages);
402423

‎include/linux/page-flags.h‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@
4848
* struct page (these bits with information) are always mapped into kernel
4949
* address space...
5050
*
51-
* PG_buddy is set to indicate that the page is free and in the buddy system
52-
* (see mm/page_alloc.c).
53-
*
5451
* PG_hwpoison indicates that a page got corrupted in hardware and contains
5552
* data with incorrect ECC bits that triggered a machine check. Accessing is
5653
* not safe since it may cause another machine check. Don't touch!
@@ -96,7 +93,6 @@ enum pageflags {
9693
PG_swapcache, /* Swap page: swp_entry_t in private */
9794
PG_mappedtodisk, /* Has blocks allocated on-disk */
9895
PG_reclaim, /* To be reclaimed asap */
99-
PG_buddy, /* Page is free, on buddy lists */
10096
PG_swapbacked, /* Page is backed by RAM/swap */
10197
PG_unevictable, /* Page is "unevictable" */
10298
#ifdef CONFIG_MMU
@@ -233,7 +229,6 @@ PAGEFLAG(OwnerPriv1, owner_priv_1) TESTCLEARFLAG(OwnerPriv1, owner_priv_1)
233229
* risky: they bypass page accounting.
234230
*/
235231
TESTPAGEFLAG(Writeback, writeback) TESTSCFLAG(Writeback, writeback)
236-
__PAGEFLAG(Buddy, buddy)
237232
PAGEFLAG(MappedToDisk, mappedtodisk)
238233

239234
/* PG_readahead is only used for file reads; PG_reclaim is only for writes */
@@ -461,7 +456,7 @@ static inline int PageTransCompound(struct page *page)
461456
#define PAGE_FLAGS_CHECK_AT_FREE \
462457
(1 << PG_lru | 1 << PG_locked | \
463458
1 << PG_private | 1 << PG_private_2 | \
464-
1 << PG_buddy | 1 << PG_writeback | 1 << PG_reserved | \
459+
1 << PG_writeback | 1 << PG_reserved | \
465460
1 << PG_slab | 1 << PG_swapcache | 1 << PG_active | \
466461
1 << PG_unevictable | __PG_MLOCKED | __PG_HWPOISON | \
467462
__PG_COMPOUND_LOCK)

‎mm/memory_hotplug.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ static void release_memory_resource(struct resource *res)
8282

8383
#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE
8484
#ifndef CONFIG_SPARSEMEM_VMEMMAP
85-
static void get_page_bootmem(unsigned long info, struct page *page, int type)
85+
static void get_page_bootmem(unsigned long info, struct page *page,
86+
unsigned long type)
8687
{
87-
atomic_set(&page->_mapcount, type);
88+
page->lru.next = (struct list_head *) type;
8889
SetPagePrivate(page);
8990
set_page_private(page, info);
9091
atomic_inc(&page->_count);
@@ -94,15 +95,16 @@ static void get_page_bootmem(unsigned long info, struct page *page, int type)
9495
* so use __ref to tell modpost not to generate a warning */
9596
void __ref put_page_bootmem(struct page *page)
9697
{
97-
int type;
98+
unsigned long type;
9899

99-
type = atomic_read(&page->_mapcount);
100-
BUG_ON(type >= -1);
100+
type = (unsigned long) page->lru.next;
101+
BUG_ON(type < MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE ||
102+
type > MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE);
101103

102104
if (atomic_dec_return(&page->_count) == 1) {
103105
ClearPagePrivate(page);
104106
set_page_private(page, 0);
105-
reset_page_mapcount(page);
107+
INIT_LIST_HEAD(&page->lru);
106108
__free_pages_bootmem(page, 0);
107109
}
108110

‎mm/page_alloc.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ __find_combined_index(unsigned long page_idx, unsigned int order)
449449
* (c) a page and its buddy have the same order &&
450450
* (d) a page and its buddy are in the same zone.
451451
*
452-
* For recording whether a page is in the buddy system, we use PG_buddy.
453-
* Setting, clearing, and testing PG_buddy is serialized by zone->lock.
452+
* For recording whether a page is in the buddy system, we set ->_mapcount -2.
453+
* Setting, clearing, and testing _mapcount -2 is serialized by zone->lock.
454454
*
455455
* For recording page's order, we use page_private(page).
456456
*/
@@ -483,7 +483,7 @@ static inline int page_is_buddy(struct page *page, struct page *buddy,
483483
* as necessary, plus some accounting needed to play nicely with other
484484
* parts of the VM system.
485485
* At each level, we keep a list of pages, which are heads of continuous
486-
* free pages of length of (1 << order) and marked with PG_buddy. Page's
486+
* free pages of length of (1 << order) and marked with _mapcount -2. Page's
487487
* order is recorded in page_private(page) field.
488488
* So when we are allocating or freeing one, we can derive the state of the
489489
* other. That is, if we allocate a small block, and both were
@@ -5574,7 +5574,6 @@ static struct trace_print_flags pageflag_names[] = {
55745574
{1UL << PG_swapcache, "swapcache" },
55755575
{1UL << PG_mappedtodisk, "mappedtodisk" },
55765576
{1UL << PG_reclaim, "reclaim" },
5577-
{1UL << PG_buddy, "buddy" },
55785577
{1UL << PG_swapbacked, "swapbacked" },
55795578
{1UL << PG_unevictable, "unevictable" },
55805579
#ifdef CONFIG_MMU

‎mm/sparse.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,10 @@ static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages)
671671
static void free_map_bootmem(struct page *page, unsigned long nr_pages)
672672
{
673673
unsigned long maps_section_nr, removing_section_nr, i;
674-
int magic;
674+
unsigned long magic;
675675

676676
for (i = 0; i < nr_pages; i++, page++) {
677-
magic = atomic_read(&page->_mapcount);
677+
magic = (unsigned long) page->lru.next;
678678

679679
BUG_ON(magic == NODE_INFO);
680680

0 commit comments

Comments
 (0)