Skip to content

Commit 170a5a7

Browse files
jiangliutorvalds
authored andcommitted
mm: make __free_pages_bootmem() only available at boot time
In order to simpilify management of totalram_pages and zone->managed_pages, make __free_pages_bootmem() only available at boot time. With this change applied, __free_pages_bootmem() will only be used by bootmem.c and nobootmem.c at boot time, so mark it as __init. Other callers of __free_pages_bootmem() have been converted to use free_reserved_page(), which handles totalram_pages and zone->managed_pages in a safer way. This patch also fix a bug in free_pagetable() for x86_64, which should increase zone->managed_pages instead of zone->present_pages when freeing reserved pages. And now we have managed_pages_count_lock to protect totalram_pages and zone->managed_pages, so remove the redundant ppb_lock lock in put_page_bootmem(). This greatly simplifies the locking rules. Signed-off-by: Jiang Liu <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Yinghai Lu <[email protected]> Cc: Wen Congyang <[email protected]> Cc: Tang Chen <[email protected]> Cc: Yasuaki Ishimatsu <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Minchan Kim <[email protected]> Cc: "Michael S. Tsirkin" <[email protected]> Cc: <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Chris Metcalf <[email protected]> Cc: David Howells <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Jeremy Fitzhardinge <[email protected]> Cc: Jianguo Wu <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Kamezawa Hiroyuki <[email protected]> Cc: Konrad Rzeszutek Wilk <[email protected]> Cc: Marek Szyprowski <[email protected]> Cc: Michel Lespinasse <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Rusty Russell <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Will Deacon <[email protected]> Cc: Russell King <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent c3d5f5f commit 170a5a7

File tree

3 files changed

+5
-38
lines changed

3 files changed

+5
-38
lines changed

arch/x86/mm/init_64.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -712,36 +712,22 @@ EXPORT_SYMBOL_GPL(arch_add_memory);
712712

713713
static void __meminit free_pagetable(struct page *page, int order)
714714
{
715-
struct zone *zone;
716-
bool bootmem = false;
717715
unsigned long magic;
718716
unsigned int nr_pages = 1 << order;
719717

720718
/* bootmem page has reserved flag */
721719
if (PageReserved(page)) {
722720
__ClearPageReserved(page);
723-
bootmem = true;
724721

725722
magic = (unsigned long)page->lru.next;
726723
if (magic == SECTION_INFO || magic == MIX_SECTION_INFO) {
727724
while (nr_pages--)
728725
put_page_bootmem(page++);
729726
} else
730-
__free_pages_bootmem(page, order);
727+
while (nr_pages--)
728+
free_reserved_page(page++);
731729
} else
732730
free_pages((unsigned long)page_address(page), order);
733-
734-
/*
735-
* SECTION_INFO pages and MIX_SECTION_INFO pages
736-
* are all allocated by bootmem.
737-
*/
738-
if (bootmem) {
739-
zone = page_zone(page);
740-
zone_span_writelock(zone);
741-
zone->present_pages += nr_pages;
742-
zone_span_writeunlock(zone);
743-
totalram_pages += nr_pages;
744-
}
745731
}
746732

747733
static void __meminit free_pte_table(pte_t *pte_start, pmd_t *pmd)

mm/memory_hotplug.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,9 @@ void get_page_bootmem(unsigned long info, struct page *page,
101101
atomic_inc(&page->_count);
102102
}
103103

104-
/* reference to __meminit __free_pages_bootmem is valid
105-
* so use __ref to tell modpost not to generate a warning */
106-
void __ref put_page_bootmem(struct page *page)
104+
void put_page_bootmem(struct page *page)
107105
{
108106
unsigned long type;
109-
static DEFINE_MUTEX(ppb_lock);
110107

111108
type = (unsigned long) page->lru.next;
112109
BUG_ON(type < MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE ||
@@ -116,17 +113,8 @@ void __ref put_page_bootmem(struct page *page)
116113
ClearPagePrivate(page);
117114
set_page_private(page, 0);
118115
INIT_LIST_HEAD(&page->lru);
119-
120-
/*
121-
* Please refer to comment for __free_pages_bootmem()
122-
* for why we serialize here.
123-
*/
124-
mutex_lock(&ppb_lock);
125-
__free_pages_bootmem(page, 0);
126-
mutex_unlock(&ppb_lock);
127-
totalram_pages++;
116+
free_reserved_page(page);
128117
}
129-
130118
}
131119

132120
#ifdef CONFIG_HAVE_BOOTMEM_INFO_NODE

mm/page_alloc.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -745,14 +745,7 @@ static void __free_pages_ok(struct page *page, unsigned int order)
745745
local_irq_restore(flags);
746746
}
747747

748-
/*
749-
* Read access to zone->managed_pages is safe because it's unsigned long,
750-
* but we still need to serialize writers. Currently all callers of
751-
* __free_pages_bootmem() except put_page_bootmem() should only be used
752-
* at boot time. So for shorter boot time, we shift the burden to
753-
* put_page_bootmem() to serialize writers.
754-
*/
755-
void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
748+
void __init __free_pages_bootmem(struct page *page, unsigned int order)
756749
{
757750
unsigned int nr_pages = 1 << order;
758751
unsigned int loop;

0 commit comments

Comments
 (0)