ARM: mm: Speed up page list initialization during boot
Hi,
Quoted 29 lines
During boot, we populate the page lists by using the page freeing mechanism on every individual page. Unfortunately, this is very inefficient because the memory manager spends a lot of time coalescing pairs of adjacent free pages into bigger blocks.
Rather than adding a single order 0 page at a time, we can take advantage of the fact that we know that all the pages are available and free up big blocks of pages at a time instead.
Signed-off-by Chirantan Ekbote <[email protected]>---
arch/arm/mm/init.c| 19 +++++++++++++++++--include/linux/gfp.h| 1 +mm/internal.h| 1 -3 files changed, 18 insertions(+), 3 deletions(-)arch/arm/mm/init.c index renamed from arch/arm/mm/init.c +0
-097c293e..c7fc2d8 100644
arch/arm/mm/init.c +1
-0@@ -22,6 +22,7 @@#include <linux/memblock.h> #include <linux/dma-contiguous.h> #include <linux/sizes.h> +#include <linux/bitops.h> #include <asm/mach-types.h> #include <asm/memblock.h> @@ -469,8 +470,22 @@ static void __init free_unused_memmap(struct
Quoted 1 line
meminfo
*mi)
Quoted 29 lines
#ifdef
CONFIG_HIGHMEM
static inline voidfree_area_high(unsigned long pfn, unsigned long end){arch/arm/mm/init.c +16
-2-for (; pfn < end; pfn++) -free_highmem_page (pfn_to_page (pfn)); +while (pfn < end) { +struct page *page =pfn_to_page (pfn); +unsigned long order =min (__ffs (pfn),MAX_ORDER -1 ); +unsigned long nr_pages =1 << order; +unsigned long rem = end - pfn; + +if (nr_pages > rem) { + order =__fls (rem); + nr_pages =1 << order; + } + +__free_pages_bootmem (page, order); + totalram_pages += nr_pages; + totalhigh_pages += nr_pages; + pfn += nr_pages; + }}
#endifinclude/linux/gfp.h index renamed from include/linux/gfp.h +0
-039b81dc..a63d666 100644
include/linux/gfp.h +0
-0@@ -367,6 +367,7 @@ void *alloc_pages_exact_nid(int nid, size_t size,
Quoted 1 line
gfp_t
gfp_mask);
Quoted 12 lines
#define __get_dma_pages(gfp_mask, order) \ __get_free_pages((gfp_mask) | GFP_DMA, (order))include/linux/gfp.h +2
-0+extern void __free_pages_bootmem (struct page *page,unsigned int +order);extern void
__free_pages(struct page *page, unsigned int order); extern voidfree_pages(unsigned long addr, unsigned int order); extern voidfree_hot_cold_page(struct page *page, int cold); diff --gita/mm/internal.hb/mm/internal.hindex 29e1e76..d2b8738 100644mm/internal.h +0
-0@@ -93,7 +93,6 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm,
Quoted 1 line
unsigned
long address);
Quoted 9 lines
/*
* inmm/page_alloc.c
*/
-extern void__free_pages_bootmem(struct page *page, unsigned int order); extern voidprep_compound_page(struct page *page, unsigned long order); #ifdefCONFIG_MEMORY_FAILUREextern boolis_free_buddy_page(struct page *page);
--
1.9.1.423.g4596e3a
This patch really could save boot time.
Is there any reason this patch is not merged to mainline kernel?
Best Regards,
Jungseung Lee
Quoted 88 lines · Jungseung Lee
Hi,
Quoted 29 lines
During boot, we populate the page lists by using the page freeing mechanism on every individual page. Unfortunately, this is very inefficient because the memory manager spends a lot of time coalescing pairs of adjacent free pages into bigger blocks.
Rather than adding a single order 0 page at a time, we can take advantage of the fact that we know that all the pages are available and free up big blocks of pages at a time instead.
Signed-off-by Chirantan Ekbote <[email protected]>---
arch/arm/mm/init.c| 19 +++++++++++++++++--include/linux/gfp.h| 1 +mm/internal.h| 1 -3 files changed, 18 insertions(+), 3 deletions(-)arch/arm/mm/init.c index renamed from arch/arm/mm/init.c +0
-097c293e..c7fc2d8 100644
arch/arm/mm/init.c +1
-0@@ -22,6 +22,7 @@#include <linux/memblock.h> #include <linux/dma-contiguous.h> #include <linux/sizes.h> +#include <linux/bitops.h> #include <asm/mach-types.h> #include <asm/memblock.h> @@ -469,8 +470,22 @@ static void __init free_unused_memmap(structQuoted 1 line
meminfo
*mi)
Quoted 29 lines
#ifdef
CONFIG_HIGHMEM
static inline voidfree_area_high(unsigned long pfn, unsigned long end){arch/arm/mm/init.c +16
-2-for (; pfn < end; pfn++) -free_highmem_page (pfn_to_page (pfn)); +while (pfn < end) { +struct page *page =pfn_to_page (pfn); +unsigned long order =min (__ffs (pfn),MAX_ORDER -1 ); +unsigned long nr_pages =1 << order; +unsigned long rem = end - pfn; + +if (nr_pages > rem) { + order =__fls (rem); + nr_pages =1 << order; + } + +__free_pages_bootmem (page, order); + totalram_pages += nr_pages; + totalhigh_pages += nr_pages; + pfn += nr_pages; + }}
#endifinclude/linux/gfp.h index renamed from include/linux/gfp.h +0
-039b81dc..a63d666 100644
include/linux/gfp.h +0
-0@@ -367,6 +367,7 @@ void *alloc_pages_exact_nid(int nid, size_t size,Quoted 1 line
gfp_t
gfp_mask);Quoted 12 lines
#define __get_dma_pages(gfp_mask, order) \ __get_free_pages((gfp_mask) | GFP_DMA, (order))include/linux/gfp.h +2
-0+extern void __free_pages_bootmem (struct page *page,unsigned int +order);extern void
__free_pages(struct page *page, unsigned int order); extern voidfree_pages(unsigned long addr, unsigned int order); extern voidfree_hot_cold_page(struct page *page, int cold); diff --gita/mm/internal.hb/mm/internal.hindex 29e1e76..d2b8738 100644mm/internal.h +0
-0@@ -93,7 +93,6 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm,Quoted 1 line
unsigned
long address);
Quoted 9 lines
/*
* inmm/page_alloc.c
*/
-extern void__free_pages_bootmem(struct page *page, unsigned int order); extern voidprep_compound_page(struct page *page, unsigned long order); #ifdefCONFIG_MEMORY_FAILUREextern boolis_free_buddy_page(struct page *page);
--
1.9.1.423.g4596e3a
Quoted 3 lines
This patch really could save boot time.
Is there any reason this patch is not merged to mainline kernel?
Well it was ignored when I originally posted it so I assumed mainline developers weren't really interested. I can re-spin and send a new version if there's interest in getting it merged now.
Quoted 3 lines
Best Regards,
Jungseung Lee
Quoted 89 lines · Chirantan Ekbote
Quoted 88 lines · Jungseung Lee
Hi,
Quoted 29 lines
During boot, we populate the page lists by using the page freeing mechanism on every individual page. Unfortunately, this is very inefficient because the memory manager spends a lot of time coalescing pairs of adjacent free pages into bigger blocks.
Rather than adding a single order 0 page at a time, we can take advantage of the fact that we know that all the pages are available and free up big blocks of pages at a time instead.
Signed-off-by Chirantan Ekbote <[email protected]>---
arch/arm/mm/init.c| 19 +++++++++++++++++--include/linux/gfp.h| 1 +mm/internal.h| 1 -3 files changed, 18 insertions(+), 3 deletions(-)arch/arm/mm/init.c index renamed from arch/arm/mm/init.c +0
-097c293e..c7fc2d8 100644
arch/arm/mm/init.c +1
-0@@ -22,6 +22,7 @@#include <linux/memblock.h> #include <linux/dma-contiguous.h> #include <linux/sizes.h> +#include <linux/bitops.h> #include <asm/mach-types.h> #include <asm/memblock.h> @@ -469,8 +470,22 @@ static void __init free_unused_memmap(structQuoted 1 line
meminfo
*mi)
Quoted 29 lines
#ifdef
CONFIG_HIGHMEM
static inline voidfree_area_high(unsigned long pfn, unsigned long end){arch/arm/mm/init.c +16
-2-for (; pfn < end; pfn++) -free_highmem_page (pfn_to_page (pfn)); +while (pfn < end) { +struct page *page =pfn_to_page (pfn); +unsigned long order =min (__ffs (pfn),MAX_ORDER -1 ); +unsigned long nr_pages =1 << order; +unsigned long rem = end - pfn; + +if (nr_pages > rem) { + order =__fls (rem); + nr_pages =1 << order; + } + +__free_pages_bootmem (page, order); + totalram_pages += nr_pages; + totalhigh_pages += nr_pages; + pfn += nr_pages; + }}
#endifinclude/linux/gfp.h index renamed from include/linux/gfp.h +0
-039b81dc..a63d666 100644
include/linux/gfp.h +0
-0@@ -367,6 +367,7 @@ void *alloc_pages_exact_nid(int nid, size_t size,Quoted 1 line
gfp_t
gfp_mask);Quoted 12 lines
#define __get_dma_pages(gfp_mask, order) \ __get_free_pages((gfp_mask) | GFP_DMA, (order))include/linux/gfp.h +2
-0+extern void __free_pages_bootmem (struct page *page,unsigned int +order);extern void
__free_pages(struct page *page, unsigned int order); extern voidfree_pages(unsigned long addr, unsigned int order); extern voidfree_hot_cold_page(struct page *page, int cold); diff --gita/mm/internal.hb/mm/internal.hindex 29e1e76..d2b8738 100644mm/internal.h +0
-0@@ -93,7 +93,6 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm,Quoted 1 line
unsigned
long address);
Quoted 9 lines
/*
* inmm/page_alloc.c
*/
-extern void__free_pages_bootmem(struct page *page, unsigned int order); extern voidprep_compound_page(struct page *page, unsigned long order); #ifdefCONFIG_MEMORY_FAILUREextern boolis_free_buddy_page(struct page *page);
--
1.9.1.423.g4596e3a
Quoted 7 lines
Quoted 3 lines
This patch really could save boot time.
Is there any reason this patch is not merged to mainline kernel?Well it was ignored when I originally posted it so I assumed mainline developers weren't really interested. I can re-spin and send a new version if there's interest in getting it merged now.
Not getting a reply can be for many reasons: people may be too busy and there may be too much other mail. I generally have a major problem with email in that it's all too easy for stuff to get buried and forgotten. Remember, some of us get a lot of emails a day, and mails which should get a reply do get dropped simply because there isn't enough time to read them and properly write replies to every message that needs a response.
So, it's good practice to resend after a week or so if you think your message has been missed; it may well have been missed and buried under a thousand or more other messages by that time.
In any case, it would be nice for such "speed up" changes to be quantified with some kind of measurement. How much does it speed the boot process up, and in what circumstances?
Thanks.
Signature · 3 lines
RMK's Patch system: http://www.arm.linux.org.uk/developer/patches/ FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
Quoted 92 lines · Chirantan Ekbote
Quoted 1 line
On Mon, Dec 28, 2015 at 2:15 AM, Jungseung Lee <[email protected]>
Quoted 89 lines · wrote:
Quoted 89 lines
Hi,
Quoted 30 lines
During boot, we populate the page lists by using the page freeing mechanism on every individual page. Unfortunately, this is very inefficient because the memory manager spends a lot of time coalescing pairs of adjacent free pages into bigger blocks.
Rather than adding a single order 0 page at a time, we can take advantage of the fact that we know that all the pages are available and free up big blocks of pages at a time instead.
Signed-off-by Chirantan Ekbote <[email protected]>---
arch/arm/mm/init.c| 19 +++++++++++++++++--include/linux/gfp.h| 1
+mm/internal.h| 1 -3 files changed, 18 insertions(+), 3 deletions(-)arch/arm/mm/init.c index renamed from arch/arm/mm/init.c +0
-097c293e..c7fc2d8 100644
arch/arm/mm/init.c +1
-0@@ -22,6 +22,7 @@#include <linux/memblock.h> #include <linux/dma-contiguous.h> #include <linux/sizes.h> +#include <linux/bitops.h> #include <asm/mach-types.h> #include <asm/memblock.h> @@ -469,8 +470,22 @@ static void __init free_unused_memmap(structQuoted 1 line
meminfo
*mi)
Quoted 29 lines
#ifdef
CONFIG_HIGHMEM
static inline voidfree_area_high(unsigned long pfn, unsigned long end){arch/arm/mm/init.c +16
-2-for (; pfn < end; pfn++) -free_highmem_page (pfn_to_page (pfn)); +while (pfn < end) { +struct page *page =pfn_to_page (pfn); +unsigned long order =min (__ffs (pfn),MAX_ORDER -1 ); +unsigned long nr_pages =1 << order; +unsigned long rem = end - pfn; + +if (nr_pages > rem) { + order =__fls (rem); + nr_pages =1 << order; + } + +__free_pages_bootmem (page, order); + totalram_pages += nr_pages; + totalhigh_pages += nr_pages; + pfn += nr_pages; + }}
#endifinclude/linux/gfp.h index renamed from include/linux/gfp.h +0
-039b81dc..a63d666 100644
include/linux/gfp.h +0
-0@@ -367,6 +367,7 @@ void *alloc_pages_exact_nid(int nid, size_tQuoted 1 line
size,
gfp_t
gfp_mask);Quoted 12 lines
#define __get_dma_pages(gfp_mask, order) \ __get_free_pages((gfp_mask) | GFP_DMA, (order))include/linux/gfp.h +2
-0+extern void __free_pages_bootmem (struct page *page,unsigned int +order);extern void
__free_pages(struct page *page, unsigned int order); extern voidfree_pages(unsigned long addr, unsigned int order); extern voidfree_hot_cold_page(struct page *page, int cold); diff --gita/mm/internal.hb/mm/internal.hindex 29e1e76..d2b8738 100644mm/internal.h +0
-0@@ -93,7 +93,6 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm,Quoted 1 line
unsigned
long address);
Quoted 9 lines
/*
* inmm/page_alloc.c
*/
-extern void__free_pages_bootmem(struct page *page, unsigned int order); extern voidprep_compound_page(struct page *page, unsigned long order); #ifdefCONFIG_MEMORY_FAILUREextern boolis_free_buddy_page(struct page *page);
--
1.9.1.423.g4596e3a
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
This patch really could save boot time.
Is there any reason this patch is not merged to mainline kernel?Well it was ignored when I originally posted it so I assumed mainline developers weren't really interested. I can re-spin and send a new version if there's interest in getting it merged now.
Chirantan, please send a new version. It really has benefit.
Quoted 8 lines
Not getting a reply can be for many reasons: people may be too busy and there may be too much other mail. I generally have a major problem with email in that it's all too easy for stuff to get buried and forgotten. Remember, some of us get a lot of emails a day, and mails which should get a reply do get dropped simply because there isn't enough time to read them and properly write replies to every message that needs a response.
Quoted 6 lines
So, it's good practice to resend after a week or so if you think your message has been missed; it may well have been missed and buried under a thousand or more other messages by that time.
In any case, it would be nice for such "speed up" changes to be quantified with some kind of measurement. How much does it speed the boot process
up,
Quoted 1 line
and in what circumstances?
In my circumstance CA15 with huge memory, 400ms is reduced. I can find below sentence from chromium review.
https://chromium-review.googlesource.com/#/c/188971/
This reduces boot time by 260ms on pit and 560ms on pi.
Quoted 7 lines
Thanks.
--
RMK's Patch system: http://www.arm.linux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up according to speedtest.net.
On (01/05/16 18:56), Jungseung Lee wrote:
[..]
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
#ifdef
CONFIG_HIGHMEM
static inline voidfree_area_high(unsigned long pfn, unsigned long end){(quoted diff) +6
-2- for (; pfn < end; pfn++) - free_highmem_page(pfn_to_page(pfn)); + while (pfn < end) { + struct page *page = pfn_to_page(pfn); + unsigned long order = min(__ffs(pfn), MAX_ORDER - 1); + unsigned long nr_pages = 1 << order; + unsigned long rem = end - pfn; +
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ if (nr_pages > rem) { + order = __fls(rem); + nr_pages = 1 << order; + } + + __free_pages_bootmem(page, order); + totalram_pages += nr_pages; + totalhigh_pages += nr_pages;
+ page_zone(page)->managed_pages += nr_pages; ???
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
(quoted diff) +2
-0+ pfn += nr_pages; + }}
-ss
Quoted 22 lines · Sergey Senozhatsky
On (01/05/16 18:56), Jungseung Lee wrote:
[..]Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
#ifdef
CONFIG_HIGHMEM
static inline voidfree_area_high(unsigned long pfn, unsigned long end){(quoted diff) +14
-2- for (; pfn < end; pfn++) - free_highmem_page(pfn_to_page(pfn)); + while (pfn < end) { + struct page *page = pfn_to_page(pfn); + unsigned long order = min(__ffs(pfn), MAX_ORDER - 1); + unsigned long nr_pages = 1 << order; + unsigned long rem = end - pfn; + + if (nr_pages > rem) { + order = __fls(rem); + nr_pages = 1 << order; + } + + __free_pages_bootmem(page, order); + totalram_pages += nr_pages; + totalhigh_pages += nr_pages;
Review
Quoted 1 line
(quoted diff) +1
-0+ page_zone(page)->managed_pages += nr_pages; ???
ah, no. __free_pages_boot_core() seems to do it. sorry for the noise.
-ss