Skip to content

Commit d93d5ab

Browse files
weiyang-linuxtorvalds
authored andcommitted
mm/page_alloc.c: simplify pageblock bitmap access
Due to commit e58469b ("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. Signed-off-by: Wei Yang <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Cc: Mel Gorman <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent 399b795 commit d93d5ab

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

include/linux/pageblock-flags.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,17 @@ void set_pfnblock_flags_mask(struct page *page,
6666
unsigned long mask);
6767

6868
/* Declarations for getting and setting flags. See mm/page_alloc.c */
69-
#define get_pageblock_flags_group(page, start_bitidx, end_bitidx) \
70-
get_pfnblock_flags_mask(page, page_to_pfn(page), \
71-
end_bitidx, \
72-
(1 << (end_bitidx - start_bitidx + 1)) - 1)
73-
#define set_pageblock_flags_group(page, flags, start_bitidx, end_bitidx) \
74-
set_pfnblock_flags_mask(page, flags, page_to_pfn(page), \
75-
end_bitidx, \
76-
(1 << (end_bitidx - start_bitidx + 1)) - 1)
77-
7869
#ifdef CONFIG_COMPACTION
7970
#define get_pageblock_skip(page) \
80-
get_pageblock_flags_group(page, PB_migrate_skip, \
81-
PB_migrate_skip)
71+
get_pfnblock_flags_mask(page, page_to_pfn(page), \
72+
PB_migrate_skip, (1 << (PB_migrate_skip)))
8273
#define clear_pageblock_skip(page) \
83-
set_pageblock_flags_group(page, 0, PB_migrate_skip, \
84-
PB_migrate_skip)
74+
set_pfnblock_flags_mask(page, 0, page_to_pfn(page), \
75+
PB_migrate_skip, (1 << PB_migrate_skip))
8576
#define set_pageblock_skip(page) \
86-
set_pageblock_flags_group(page, 1, PB_migrate_skip, \
87-
PB_migrate_skip)
77+
set_pfnblock_flags_mask(page, (1 << PB_migrate_skip), \
78+
page_to_pfn(page), \
79+
PB_migrate_skip, (1 << PB_migrate_skip))
8880
#else
8981
static inline bool get_pageblock_skip(struct page *page)
9082
{

mm/page_alloc.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,7 @@ static __always_inline unsigned long __get_pfnblock_flags_mask(struct page *page
489489
bitidx &= (BITS_PER_LONG-1);
490490

491491
word = bitmap[word_bitidx];
492-
bitidx += end_bitidx;
493-
return (word >> (BITS_PER_LONG - bitidx - 1)) & mask;
492+
return (word >> bitidx) & mask;
494493
}
495494

496495
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,
532531

533532
VM_BUG_ON_PAGE(!zone_spans_pfn(page_zone(page), pfn), page);
534533

535-
bitidx += end_bitidx;
536-
mask <<= (BITS_PER_LONG - bitidx - 1);
537-
flags <<= (BITS_PER_LONG - bitidx - 1);
534+
mask <<= bitidx;
535+
flags <<= bitidx;
538536

539537
word = READ_ONCE(bitmap[word_bitidx]);
540538
for (;;) {
@@ -551,8 +549,9 @@ void set_pageblock_migratetype(struct page *page, int migratetype)
551549
migratetype < MIGRATE_PCPTYPES))
552550
migratetype = MIGRATE_UNMOVABLE;
553551

554-
set_pageblock_flags_group(page, (unsigned long)migratetype,
555-
PB_migrate, PB_migrate_end);
552+
set_pfnblock_flags_mask(page, (unsigned long)migratetype,
553+
page_to_pfn(page), PB_migrate_end,
554+
MIGRATETYPE_MASK);
556555
}
557556

558557
#ifdef CONFIG_DEBUG_VM

0 commit comments

Comments
 (0)