From patchwork Thu Jan 20 01:11:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 12718158 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 6EED3C433F5 for ; Thu, 20 Jan 2022 01:12:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73CDB6B0072; Wed, 19 Jan 2022 20:12:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E9D76B0073; Wed, 19 Jan 2022 20:12:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D87F6B0074; Wed, 19 Jan 2022 20:12:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0168.hostedemail.com [216.40.44.168]) by kanga.kvack.org (Postfix) with ESMTP id 4F5656B0072 for ; Wed, 19 Jan 2022 20:12:10 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E9857827F84D for ; Thu, 20 Jan 2022 01:12:09 +0000 (UTC) X-FDA: 79048889178.13.61220CA Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf31.hostedemail.com (Postfix) with ESMTP id 6135220004 for ; Thu, 20 Jan 2022 01:12:09 +0000 (UTC) Received: by mail-yb1-f202.google.com with SMTP id k189-20020a25c6c6000000b0061274ece35eso8381545ybf.22 for ; Wed, 19 Jan 2022 17:12:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=tA2eESNey0k0XP9lk3g/bAUxhAQW5/EDDgeejjFfXNg=; b=J3HQT9krlZpsQHQTFN3l8Z8u2Xf/3ewg0BZLCCsSyi7tFH4eLStKDf57djLK731CyH 2r766eOGcq9rdqLNOJrGcFlsrzoPV46P5LdGiKJmson3U5GH8I/is7v0u5OMLh/I51pU n4ocALKdQwW+oeKJENm84eCGpAsDqPaYUxQmMIBz3zGWoVWohLW3g3a+rJsXUAVzrSIl Ecl1bJw/BpuRnv1x/vgqFs/zDoTBSHDe1YyhkOThvZc1vjQnStHhiSL9t0CynG+n5mse Jw2Jhj1G8Ay/lodL/w4dwWnjl3tqe1F/qt6981+t+OpYfhWHQD9DeFMbbgOpYrTHQbuY cfbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=tA2eESNey0k0XP9lk3g/bAUxhAQW5/EDDgeejjFfXNg=; b=DRKzgi+9/EfoUuls3WDiZF88pIVFkVbHsgfAWssjqbMnLLZN14aWFO24NzRz/Id/b7 2nak0MWn3zrSR91uXUUY/Xhvpq1bHjBU86Gas1BEhyHcSttyjhIot2yfTGrPTQUN/Y8K SvsDCyrTEcCWKuHUghBYS66Rjy79BCGRg/3KYDZqpq79edn+6Xmx7YJAUYXHzav1doHa 9EEoJ5B+FbUg3QBx0O+dugsSF93gOl1fYGkivub+EdGA1fwqlmCUKFQhDJIvS5zAj1+K eCR0gyYdmfFr4s3YA/fuaKtm2VNmaQgVVQGVAOZZRgIed7f8fKkTMeRKJ08rOmCD9m7u tqsA== X-Gm-Message-State: AOAM5324wx07hAYmHKbxflHoD8XdLcvPgSuh2FVAFuxKD5ZHJbZzhYcm boi6ONNXZE8l1qGgV8tOmZ+qfds= X-Google-Smtp-Source: ABdhPJz3mwdM+0As6FN3WKubqoUI/B4hcSVbjvP6uZO/jii6WDL2eFvY2vyHyvkgUT+SrC7/zokdGqk= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2ce:200:7641:d112:dd90:7ea1]) (user=pcc job=sendgmr) by 2002:a25:bb45:: with SMTP id b5mr27616743ybk.174.1642641128808; Wed, 19 Jan 2022 17:12:08 -0800 (PST) Date: Wed, 19 Jan 2022 17:11:59 -0800 Message-Id: <20220120011200.1322836-1-pcc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.1.703.g22d0c6ccf7-goog Subject: [PATCH v2] mm/mmzone.c: use try_cmpxchg() in page_cpupid_xchg_last() From: Peter Collingbourne To: Andrey Konovalov , Andrew Morton Cc: Peter Collingbourne , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Peter Zijlstra , Mel Gorman X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6135220004 X-Stat-Signature: hmd84c8rc3wixhfxyezxmai55ip4gbhg Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=J3HQT9kr; spf=pass (imf31.hostedemail.com: domain of 36LboYQMKCA84rrv33v0t.r310x29C-11zAprz.36v@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=36LboYQMKCA84rrv33v0t.r310x29C-11zAprz.36v@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1642641129-937284 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: This will let us avoid an additional read from page->flags when retrying the compare-exchange on some architectures. Suggested-by: Peter Zijlstra Signed-off-by: Peter Collingbourne Link: https://linux-review.googlesource.com/id/I2e1f5b5b080ac9c4e0eb7f98768dba6fd7821693 --- mm/mmzone.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/mmzone.c b/mm/mmzone.c index eb89d6e018e2..d8a9b0e1b526 100644 --- a/mm/mmzone.c +++ b/mm/mmzone.c @@ -89,13 +89,14 @@ int page_cpupid_xchg_last(struct page *page, int cpupid) 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; }