Skip to content

Commit 04ec006

Browse files
ubizjakakpm00
authored andcommitted
mm/page_alloc: use try_cmpxchg in set_pfnblock_flags_mask
Use try_cmpxchg instead of cmpxchg in set_pfnblock_flags_mask. x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of cmpxchg). The main loop improves from: 1c5d: 48 89 c2 mov %rax,%rdx 1c60: 48 89 c1 mov %rax,%rcx 1c63: 48 21 fa and %rdi,%rdx 1c66: 4c 09 c2 or %r8,%rdx 1c69: f0 48 0f b1 16 lock cmpxchg %rdx,(%rsi) 1c6e: 48 39 c1 cmp %rax,%rcx 1c71: 75 ea jne 1c5d <...> to: 1c60: 48 89 ca mov %rcx,%rdx 1c63: 48 21 c2 and %rax,%rdx 1c66: 4c 09 c2 or %r8,%rdx 1c69: f0 48 0f b1 16 lock cmpxchg %rdx,(%rsi) 1c6e: 75 f0 jne 1c60 <...> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Uros Bizjak <[email protected]> Cc: Andrew Morton <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent dcadcf1 commit 04ec006

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

mm/page_alloc.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags,
602602
{
603603
unsigned long *bitmap;
604604
unsigned long bitidx, word_bitidx;
605-
unsigned long old_word, word;
605+
unsigned long word;
606606

607607
BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4);
608608
BUILD_BUG_ON(MIGRATE_TYPES > (1 << PB_migratetype_bits));
@@ -618,12 +618,8 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags,
618618
flags <<= bitidx;
619619

620620
word = READ_ONCE(bitmap[word_bitidx]);
621-
for (;;) {
622-
old_word = cmpxchg(&bitmap[word_bitidx], word, (word & ~mask) | flags);
623-
if (word == old_word)
624-
break;
625-
word = old_word;
626-
}
621+
do {
622+
} while (!try_cmpxchg(&bitmap[word_bitidx], &word, (word & ~mask) | flags));
627623
}
628624

629625
void set_pageblock_migratetype(struct page *page, int migratetype)

0 commit comments

Comments
 (0)