mm/page_alloc.c: replace the definition of NR_MIGRATETYPE_BITS with PB_migratetype_bits
Subsystems (4)
PATCH 1/4 mm/page_alloc.c: replace the definition of NR_MIGRATETYPE_BITS with PB_migratetype_bits
We already have the definition of PB_migratetype_bits and current NR_MIGRATETYPE_BITS looks like a cyclic definition.
Just use PB_migratetype_bits is enough.
--- include/linux/mmzone.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/mmzone.h +1 -2
@@ -88,8 +88,7 @@ static inline bool is_migrate_movable(int mt)extern int page_group_by_mobility_disabled; -#define NR_MIGRATETYPE_BITS (PB_migrate_end - PB_migrate + 1) -#define MIGRATETYPE_MASK ((1UL << NR_MIGRATETYPE_BITS) - 1) +#define MIGRATETYPE_MASK ((1UL << PB_migratetype_bits) - 1)#define get_pageblock_migratetype (page) \ get_pfnblock_flags_mask(page, page_to_pfn(page), \
Signature · 1 line
2.20.1 (Apple Git-117)
PATCH 2/4 mm/page_alloc.c: extract the common part in pfn_to_bitidx()
The return value calculation is the same both for SPARSEMEM or not.
Just took it out.
--- mm/page_alloc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/page_alloc.c +1 -2
@@ -459,11 +459,10 @@ static inline int pfn_to_bitidx(struct page *page, unsigned long pfn) {#ifdef CONFIG_SPARSEMEM pfn &= (PAGES_PER_SECTION -1 ); -return (pfn >> pageblock_order) *NR_PAGEBLOCK_BITS ;#else pfn = pfn -round_down (page_zone (page)->zone_start_pfn, pageblock_nr_pages); -return (pfn >> pageblock_order) *NR_PAGEBLOCK_BITS ;#endif /* CONFIG_SPARSEMEM */ +return (pfn >> pageblock_order) *NR_PAGEBLOCK_BITS ; }/**
Signature · 1 line
2.20.1 (Apple Git-117)
PATCH 3/4 mm/page_alloc.c: simplify pageblock bitmap access
In reply to Wei YangFrom commit e58469bafd05 ("mm: page_alloc: use word-based accesses for get/set pageblock bitmaps"), pageblock bitmap is accessed with word-based access. This operation could be simplified a little.
Intuitively, if we want to get a bit range [start_idx, end_idx] in a word, we can do like this:
mask = (1 << (end_bitidx - start_bitidx + 1)) - 1;
ret = (word >> start_idx) & mask;And also if we want to set a bit range [start_idx, end_idx] with flags, we can do the same by just shift start_bitidx.
By doing so we reduce some instructions for these two helper functions:
Before Patched
set_pfnblock_flags_mask 209 198(-5%)
get_pfnblock_flags_mask 101 87(-13%)Since the syntax is changed a little, we need to check the whole 4-bit migrate_type instead of part of it.
--- include/linux/pageblock-flags.h | 22 +++++++--------------- mm/page_alloc.c | 13 ++++++------- 2 files changed, 13 insertions(+), 22 deletions(-)
include/linux/pageblock-flags.h +7 -15
@@ -66,25 +66,17 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long mask);/* Declarations for getting and setting flags. See mm/page_alloc.c */ -#define get_pageblock_flags_group (page, start_bitidx, end_bitidx) \ - get_pfnblock_flags_mask(page, page_to_pfn(page), \ - end_bitidx, \ - (1 << (end_bitidx - start_bitidx + 1)) - 1) -#define set_pageblock_flags_group (page, flags, start_bitidx, end_bitidx) \ - set_pfnblock_flags_mask(page, flags, page_to_pfn(page), \ - end_bitidx, \ - (1 << (end_bitidx - start_bitidx + 1)) - 1) -#ifdef CONFIG_COMPACTION #define get_pageblock_skip (page) \ - get_pageblock_flags_group(page, PB_migrate_skip, \ - PB_migrate_skip) + get_pfnblock_flags_mask(page, page_to_pfn(page), \ + PB_migrate_skip, (1 << (PB_migrate_skip)))#define clear_pageblock_skip (page) \ - set_pageblock_flags_group(page, 0, PB_migrate_skip, \ - PB_migrate_skip) + set_pfnblock_flags_mask(page, 0, page_to_pfn(page), \ + PB_migrate_skip, (1 << PB_migrate_skip))#define set_pageblock_skip (page) \ - set_pageblock_flags_group(page, 1, PB_migrate_skip, \ - PB_migrate_skip) + set_pfnblock_flags_mask(page, (1 << PB_migrate_skip), \ + page_to_pfn(page), \ + PB_migrate_skip, (1 << PB_migrate_skip))#else static inline bool get_pageblock_skip (struct page *page) {
mm/page_alloc.c +6 -7
@@ -489,8 +489,7 @@ static __always_inline unsigned long __get_pfnblock_flags_mask(struct page *page bitidx &= (BITS_PER_LONG -1 ); word = bitmap[word_bitidx]; - bitidx += end_bitidx; -return (word >> (BITS_PER_LONG - bitidx -1 )) & mask; +return (word >> bitidx) & mask; } unsigned long get_pfnblock_flags_mask(struct page *page, unsigned long pfn,
@@ -532,9 +531,8 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags,VM_BUG_ON_PAGE (!zone_spans_pfn (page_zone (page), pfn), page); - bitidx += end_bitidx; - mask <<= (BITS_PER_LONG - bitidx -1 ); - flags <<= (BITS_PER_LONG - bitidx -1 ); + mask <<= bitidx; + flags <<= bitidx; word =READ_ONCE (bitmap[word_bitidx]);for (;;) {
@@ -551,8 +549,9 @@ void set_pageblock_migratetype(struct page *page, int migratetype) migratetype < MIGRATE_PCPTYPES)) migratetype =MIGRATE_UNMOVABLE ; -set_pageblock_flags_group (page, (unsigned long )migratetype, - PB_migrate, PB_migrate_end); +set_pfnblock_flags_mask (page, (unsigned long )migratetype, +page_to_pfn (page), PB_migrate_end, +MIGRATETYPE_MASK ); }#ifdef CONFIG_DEBUG_VM
Signature · 1 line
2.20.1 (Apple Git-117)
PATCH 4/4 mm/page_alloc.c: remove unnecessary end_bitidx for [set|get]_pfnblock_flags_mask()
In reply to Wei YangAfter previous cleanup, the end_bitidx is not necessary any more.
--- include/linux/mmzone.h | 3 +-- include/linux/pageblock-flags.h | 8 +++----- mm/page_alloc.c | 15 +++++---------- 3 files changed, 9 insertions(+), 17 deletions(-)
include/linux/mmzone.h +1 -2
@@ -91,8 +91,7 @@ extern int page_group_by_mobility_disabled;#define MIGRATETYPE_MASK ((1UL << PB_migratetype_bits) - 1)#define get_pageblock_migratetype (page) \ - get_pfnblock_flags_mask(page, page_to_pfn(page), \ - PB_migrate_end, MIGRATETYPE_MASK) + get_pfnblock_flags_mask(page, page_to_pfn(page), MIGRATETYPE_MASK)struct free_area {struct list_head free_list[MIGRATE_TYPES ];
include/linux/pageblock-flags.h +3 -5
@@ -56,27 +56,25 @@ struct page;unsigned long get_pfnblock_flags_mask (struct page *page,unsigned long pfn, -unsigned long end_bitidx,unsigned long mask);void set_pfnblock_flags_mask (struct page *page,unsigned long flags,unsigned long pfn, -unsigned long end_bitidx,unsigned long mask);/* Declarations for getting and setting flags. See mm/page_alloc.c */ #ifdef CONFIG_COMPACTION #define get_pageblock_skip (page) \ get_pfnblock_flags_mask(page, page_to_pfn(page), \ - PB_migrate_skip, (1 << (PB_migrate_skip))) + (1 << (PB_migrate_skip)))#define clear_pageblock_skip (page) \ set_pfnblock_flags_mask(page, 0, page_to_pfn(page), \ - PB_migrate_skip, (1 << PB_migrate_skip)) + (1 << PB_migrate_skip))#define set_pageblock_skip (page) \ set_pfnblock_flags_mask(page, (1 << PB_migrate_skip), \ page_to_pfn(page), \ - PB_migrate_skip, (1 << PB_migrate_skip)) + (1 << PB_migrate_skip))#else static inline bool get_pageblock_skip (struct page *page) {
mm/page_alloc.c +5 -10
@@ -469,14 +469,13 @@ static inline int pfn_to_bitidx(struct page *page, unsigned long pfn)* get_pfnblock_flags_mask - Return the requested group of flags for the pageblock_nr_pages block of pages * @page: The page within the block of interest * @pfn: The target page frame number -* @end_bitidx: The last bit of interest to retrieve * @mask: mask of bits that the caller is interested in * * Return: pageblock_bits flags */ -static __always_inline unsigned long __get_pfnblock_flags_mask (struct page *page, +static __always_inline +unsigned long __get_pfnblock_flags_mask (struct page *page,unsigned long pfn, -unsigned long end_bitidx,unsigned long mask) {unsigned long *bitmap;
@@ -493,15 +492,14 @@ static __always_inline unsigned long __get_pfnblock_flags_mask(struct page *page }unsigned long get_pfnblock_flags_mask (struct page *page,unsigned long pfn, -unsigned long end_bitidx,unsigned long mask) { -return __get_pfnblock_flags_mask (page, pfn, end_bitidx, mask); +return __get_pfnblock_flags_mask (page, pfn, mask); } static __always_inline int get_pfnblock_migratetype(struct page *page, unsigned long pfn) { -return __get_pfnblock_flags_mask (page, pfn, PB_migrate_end,MIGRATETYPE_MASK ); +return __get_pfnblock_flags_mask (page, pfn,MIGRATETYPE_MASK ); }/**
@@ -509,12 +507,10 @@ static __always_inline int get_pfnblock_migratetype(struct page *page, unsigned* @page: The page within the block of interest * @flags: The flags to set * @pfn: The target page frame number -* @end_bitidx: The last bit of interest * @mask: mask of bits that the caller is interested in */ void set_pfnblock_flags_mask (struct page *page,unsigned long flags,unsigned long pfn, -unsigned long end_bitidx,unsigned long mask) {unsigned long *bitmap;
@@ -550,8 +546,7 @@ void set_pageblock_migratetype(struct page *page, int migratetype) migratetype =MIGRATE_UNMOVABLE ;set_pfnblock_flags_mask (page, (unsigned long )migratetype, -page_to_pfn (page), PB_migrate_end, -MIGRATETYPE_MASK ); +page_to_pfn (page),MIGRATETYPE_MASK ); }#ifdef CONFIG_DEBUG_VM
Signature · 1 line
2.20.1 (Apple Git-117)