From patchwork Tue Mar 22 21:43:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12789131 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0993CC433FE for ; Tue, 22 Mar 2022 21:43:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 980B06B00DA; Tue, 22 Mar 2022 17:43:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 908ED6B00DB; Tue, 22 Mar 2022 17:43:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 782C16B00DC; Tue, 22 Mar 2022 17:43:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id 6327D6B00DA for ; Tue, 22 Mar 2022 17:43:12 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2F9F3A4DBE for ; Tue, 22 Mar 2022 21:43:12 +0000 (UTC) X-FDA: 79273348224.29.083D8DE Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf19.hostedemail.com (Postfix) with ESMTP id B84D71A002F for ; Tue, 22 Mar 2022 21:43:11 +0000 (UTC) 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 A7685B81DAC; Tue, 22 Mar 2022 21:43:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62FC5C340EC; Tue, 22 Mar 2022 21:43:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1647985389; bh=2fw4V34BMaBWwfa8lGQogtWOuNUo51fHy2VVhad5FVo=; h=Date:To:From:In-Reply-To:Subject:From; b=D7QK0v64JEml4OOpBVivrX3z4qSiP2SDe5UdQuX3UlhEiMIHfQPkkgU4uAJB8jteg sZ4NAuP5Um3Dm43Lb3SkTtv57rTWTycCqbYmn8JFKuny/gNuIXoRX/ep8FiUsc/plw gYt3rdYhPPhssQf7sBV2MS9moa43MVB9DbfnMhpk= Date: Tue, 22 Mar 2022 14:43:08 -0700 To: peterz@infradead.org,mgorman@suse.de,andreyknvl@gmail.com,pcc@google.com,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220322143803.04a5e59a07e48284f196a2f9@linux-foundation.org> Subject: [patch 091/227] mm/mmzone.c: use try_cmpxchg() in page_cpupid_xchg_last() Message-Id: <20220322214309.62FC5C340EC@smtp.kernel.org> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B84D71A002F X-Stat-Signature: ubz9wj9wp48upfkm9jykt3wce9nfpndh X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=D7QK0v64; dmarc=none; spf=pass (imf19.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-HE-Tag: 1647985391-987560 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Peter Collingbourne Subject: mm/mmzone.c: use try_cmpxchg() in page_cpupid_xchg_last() This will let us avoid an additional read from page->flags when retrying the compare-exchange on some architectures. Link: https://lkml.kernel.org/r/20220120011200.1322836-1-pcc@google.com Link: https://linux-review.googlesource.com/id/I2e1f5b5b080ac9c4e0eb7f98768dba6fd7821693 Signed-off-by: Peter Collingbourne Suggested-by: Peter Zijlstra Cc: Andrey Konovalov Cc: Mel Gorman Signed-off-by: Andrew Morton --- mm/mmzone.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/mm/mmzone.c~mm-mmzonec-use-try_cmpxchg-in-page_cpupid_xchg_last +++ a/mm/mmzone.c @@ -89,13 +89,14 @@ int page_cpupid_xchg_last(struct page *p unsigned long old_flags, flags; int last_cpupid; + old_flags = READ_ONCE(page->flags); do { - old_flags = flags = page->flags; - last_cpupid = page_cpupid_last(page); + flags = old_flags; + last_cpupid = (flags >> LAST_CPUPID_PGSHIFT) & LAST_CPUPID_MASK; flags &= ~(LAST_CPUPID_MASK << LAST_CPUPID_PGSHIFT); flags |= (cpupid & LAST_CPUPID_MASK) << LAST_CPUPID_PGSHIFT; - } while (unlikely(cmpxchg(&page->flags, old_flags, flags) != old_flags)); + } while (unlikely(!try_cmpxchg(&page->flags, &old_flags, flags))); return last_cpupid; }