From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94454C43334 for ; Fri, 8 Jul 2022 19:53:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238536AbiGHTxq (ORCPT ); Fri, 8 Jul 2022 15:53:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238512AbiGHTxp (ORCPT ); Fri, 8 Jul 2022 15:53:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DF5D2AC6B for ; Fri, 8 Jul 2022 12:53:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CB878B82915 for ; Fri, 8 Jul 2022 19:53:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63D4BC341C0; Fri, 8 Jul 2022 19:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1657310021; bh=YmgogVgBmdgBAVJXNljbZfccyMnpSvn4RHpr0+5JbEQ=; h=Date:To:From:Subject:From; b=yuYNx2O8cYhJ0WB09Iz/poePkN8IKpDKkfW8aeyiEyapRneFTd0YVmjN29iZllThl Fxo2HizRno+s4Bxo6/sdb4vANsk0OcPegfqXPabY8HhVZv1sJ21kr9aZ68LrXB8T7Z /cx3QWIRnwzJwuf3g0AL9MaBPGP4SJs8+FGAqyZ4= Date: Fri, 08 Jul 2022 12:53:40 -0700 To: mm-commits@vger.kernel.org, akpm@linux-foundation.org, ubizjak@gmail.com, akpm@linux-foundation.org From: Andrew Morton Subject: + mm-page_alloc-use-try_cmpxchg-in-set_pfnblock_flags_mask.patch added to mm-unstable branch Message-Id: <20220708195341.63D4BC341C0@smtp.kernel.org> Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org The patch titled Subject: mm/page_alloc: use try_cmpxchg in set_pfnblock_flags_mask has been added to the -mm mm-unstable branch. Its filename is mm-page_alloc-use-try_cmpxchg-in-set_pfnblock_flags_mask.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-page_alloc-use-try_cmpxchg-in-set_pfnblock_flags_mask.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Uros Bizjak Subject: mm/page_alloc: use try_cmpxchg in set_pfnblock_flags_mask Date: Fri, 8 Jul 2022 16:07:36 +0200 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/20220708140736.8737-1-ubizjak@gmail.com Signed-off-by: Uros Bizjak Cc: Andrew Morton Signed-off-by: Andrew Morton --- mm/page_alloc.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) --- a/mm/page_alloc.c~mm-page_alloc-use-try_cmpxchg-in-set_pfnblock_flags_mask +++ a/mm/page_alloc.c @@ -602,7 +602,7 @@ void set_pfnblock_flags_mask(struct page { unsigned long *bitmap; unsigned long bitidx, word_bitidx; - unsigned long old_word, word; + unsigned long word; BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4); BUILD_BUG_ON(MIGRATE_TYPES > (1 << PB_migratetype_bits)); @@ -618,12 +618,8 @@ void set_pfnblock_flags_mask(struct page flags <<= bitidx; word = READ_ONCE(bitmap[word_bitidx]); - for (;;) { - old_word = cmpxchg(&bitmap[word_bitidx], word, (word & ~mask) | flags); - if (word == old_word) - break; - word = old_word; - } + do { + } while (!try_cmpxchg(&bitmap[word_bitidx], &word, (word & ~mask) | flags)); } void set_pageblock_migratetype(struct page *page, int migratetype) _ Patches currently in -mm which might be from ubizjak@gmail.com are mm-page_alloc-use-try_cmpxchg-in-set_pfnblock_flags_mask.patch compiler-gcch-remove-ancient-workaround-for-gcc-pr-58670.patch