From patchwork Mon Feb 27 21:42:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 13154223 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 3E72BC64ED8 for ; Mon, 27 Feb 2023 21:42:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 45CC56B0071; Mon, 27 Feb 2023 16:42:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E69E6B0072; Mon, 27 Feb 2023 16:42:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 260AB6B0074; Mon, 27 Feb 2023 16:42:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1400A6B0071 for ; Mon, 27 Feb 2023 16:42:43 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C6B981A0BAA for ; Mon, 27 Feb 2023 21:42:42 +0000 (UTC) X-FDA: 80514396564.12.9FDBFEB Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) by imf28.hostedemail.com (Postfix) with ESMTP id 192FCC0010 for ; Mon, 27 Feb 2023 21:42:40 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=cmg1GhtU; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.208.41 as permitted sender) smtp.mailfrom=ubizjak@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677534161; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=3pF1j/L5vcGNedAFcqAPgWkFtpGwjYImsiIMrNw4zJE=; b=dqLv3nha3oqOWVGW8h0gAUcnqXqN6hxMjbwVgzYFmqTZXU5b1RJKUMcUIRvOv6vdDhzQsz JDjyH62v0G9YLHR4Jl/Grgnb1ujDD5fDZjNIrwTfvIEAv8dJRUQBPvCHNHh/a+QBoMeH3f B3rvRrkWnDJy4G1bKZ5fz+6BWl1Cz/4= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=cmg1GhtU; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf28.hostedemail.com: domain of ubizjak@gmail.com designates 209.85.208.41 as permitted sender) smtp.mailfrom=ubizjak@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677534161; a=rsa-sha256; cv=none; b=nIYsbX2i6yvkw22j1rPL2YefrNQLeWJCrMD109xveyjzuSEFO9Ok2d90W/t9aLa0at4S6f FLYwx03vSs0xYu25XbNcQuC+K31dcKR4l3GCB4JUmfumH723IcbIzT/ArUVovUqjul63pD rKqhWkngSWck0xL1/GicBWev0vBW/Ag= Received: by mail-ed1-f41.google.com with SMTP id ee7so31767793edb.2 for ; Mon, 27 Feb 2023 13:42:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3pF1j/L5vcGNedAFcqAPgWkFtpGwjYImsiIMrNw4zJE=; b=cmg1GhtUWNg0amzNtPEbxGednqlpD557j0u1IKcgpmkITfq1Oz+tJFYMC7p/x9OU2y BOq4SpMn1KAijc2tVeaXciy6iOU2QgbCagR7gL8AooFNzjPQ7VA/U4ECwps8/S8+SWo6 QZmy1bmdHLI9lhRQIke5WNcjRWT0KjR+Shju29zGYbglgTk4Yz6q8jTghwmiPHc6+OSF gy/UOuYfWPdlp6WJSvi1JWsY95llVhIzW/lG1W5/nhTijoHKWbfRKYHdp/l311P3BCzu zzx3icxL/Kz9IVvW7AO12c7BjX1z4zBfUnLokT3yk4lq8llJ0NAfOeqAKBxJb6pNYlj0 OIBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3pF1j/L5vcGNedAFcqAPgWkFtpGwjYImsiIMrNw4zJE=; b=JqlDNQH7zvfr2mCUY6OAtL4I8kUSG5WKeCIPSHmeEkDGnVZkV6EZSHjosE7Jxt1LT/ nV2YCjnNmQHGWv3kyHV3Va3wal8PndedyiSnfKNevkBA3Lyul+adeSvKUm40rUXi1CZu sKpdI1yc7evmOGZ0GNO4xRXKYdySFkLX8Dggq8RBFfwNhixe681WF/ZLfEkjq6U5KjD3 NqxmaQ0ivAp4ZECVOGQXbtnh4mjjB27G3jUaudzumPX0r5VMJWGtRgjDdJwmamXD4mj7 h+Cu87oBrqGnUbWNMunxJqOu6ZxKFYhETGVM5mYBtXFmeEJ9jKeeXX/sdOGHrYsckXe7 pWlg== X-Gm-Message-State: AO0yUKXvKAftmncLGwYCbd5FQJazD/LlbLtK/Vu+RgwO6Cx2C1Z3VM/p p9PrTTHTE1F3NUo5T2ooiUjMIyEJW1ROBA== X-Google-Smtp-Source: AK7set+SHic5PlVPa0PeP9RtaugqvXfIG224So+n+xk6rcAlubCuUE4yJg2fTshm8DbBatHRcZnDXQ== X-Received: by 2002:a17:906:d158:b0:8b1:2f0e:e3a4 with SMTP id br24-20020a170906d15800b008b12f0ee3a4mr222842ejb.26.1677534159118; Mon, 27 Feb 2023 13:42:39 -0800 (PST) Received: from localhost.localdomain ([46.248.82.114]) by smtp.gmail.com with ESMTPSA id rh4-20020a17090720e400b008c801141d58sm3681327ejb.109.2023.02.27.13.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 13:42:38 -0800 (PST) From: Uros Bizjak To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Uros Bizjak , Andrew Morton Subject: [PATCH] mm/rmap: use atomic_try_cmpxchg in set_tlb_ubc_flush_pending Date: Mon, 27 Feb 2023 22:42:28 +0100 Message-Id: <20230227214228.3533299-1-ubizjak@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: 192FCC0010 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: knm9mcme9w3gkozgfwxwj7wpgx3q6ymy X-HE-Tag: 1677534160-356837 X-HE-Meta: U2FsdGVkX19IMl+387cnZw/K8FRDiz6lDlbwEuGfPAo8TI4/TN1cscg6woX39Ai55q5TqlcrQCWSPAzoBHVXBpOXNuC/3+368h4xc4wDrPMmJ6GJ52Wqm+elqEdJSpMpR+OlkKtNFQWaIPi5q2nFv6qzo/x9D4y0+bqcvVonDG+NVO04is9/AbDKsf8VUTMT96cZrfEb4b+wgogfcjoV/c2bRL8r7KilE0dRlewpG4edWHXQirvlyl1CSXPOtJ/rMWUcqv8TZBgvfP/Mw7eTdA9xeJqd5PrEz8vn2lHyrqDZBRlAlabSC0VRkYIeN1Yso3kPs5b9c98JvjUIIsbCjtUQX9mRA3ocqh4FNjkwJOiCF52eugxKrfoSn+Vqmwn5F9J80aZkF3BWLzeH7qKDdZqFNcQWyXPS/Majo/JWeVH0htgTrKa6gZSmTqSAyFfVnD7ebw6aeAH/BQz6d4lkm+6+gnIwfjeuDaDir8bK39HRDT0RhOszSSs30+/leMkse/EjUM4lT+lgJPQ+E48msIRtjbQumiF4X7PUxdM+XjoXKPe4wN/JSTJSUtlNssTfk0Zecwic4muttYlQYJawtOwidekhaF/fdR5HS1PQeD11raXY1lBADdOPx4jUw6pqvMrrJ9m3wSj3CXeRdzTC8tFVNV5jWIY3HzHDV1GTuzfLzY3FI0Yk1rtGblHfqN4xrAvMdXUK+9ocFlBlfbuZF2LUnpMJ2G2bBsv4Dp2nXohIEfzLj2puuHIzttnarHvo7Ydey+A/SsFjX1bNLNFG+jr47jmuOmxkhWSksnjE+QObWfAmut9zn64nUtXthCw68wg+ZMbXCRqyEnJM0GpYVuSN/nMGR3sGcUPLKuynXr30u5aGleLZ6fv1fwcgi6OKvke5cFvPqeLjfC4CsuWG48f89FApxIlDcg+yWq3RuZMN3WbtqRc3yysd0EdOX2fBsxKO5EbSdRPe82jk1W/ RscHHFjc mHhv/yKZgv0mTuMR+8HeUHdOQvtIts8fT3ipodj0vYsvApbzrjdR+VkbjEWEBXhS0VKYiMQF3MKCXKkWP9rbbJvz7xbHA4WR5VzfGFwWlvszG50+IVXbMsNu80jCLCIsovoDHm2x9HTOvp/doPWUPsZNL209W3bB83YcGDD5xZuqFCpPOdyYcmxGBAwxZUEi4IAqtms2fw4ZVSERuC78Y6VEXHTwpZvOl0Rfd4dEHCG+LCVQiE6Loln//DFOTDxiqQ+BxC6+aYusScuJLjUYUaesZ7tsqzKPGxFRZDd2wU3GX+L1q/8xUJiIXs15lUCWLXR0PDtvHfle9iSUyhcQiNSiIkjo0Kf4K8JzNsD5WtCBTCLtRHpqC00XEV5vQ7Rbo1iiwCez5SrlR2peqLd5CsaUr/ANVEBnJhi7WpgZN0fVWZAXHHyIxljL4UHnz08OuoX+RXPr/VOKfuhDt4fwqvaGRLzKQFK6KfQgYnvlK0LhnYGMHXpA+WnWIsi+Lu74QtqpifTlFglbqtliunMex9oyib6XBOU+tjFg1nmZ41fhIOmHDg6r8lyeiFQ== 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: Use atomic_try_cmpxchg instead of atomic_cmpxchg (*ptr, old, new) == old in set_tlb_ubc_flush_pending. 86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg (and related move instruction in front of cmpxchg). Also, try_cmpxchg implicitly assigns old *ptr value to "old" when cmpxchg fails. No functional change intended. Signed-off-by: Uros Bizjak Cc: Andrew Morton --- mm/rmap.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 15ae24585fc4..f964c197fc3c 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -644,7 +644,7 @@ void try_to_unmap_flush_dirty(void) static void set_tlb_ubc_flush_pending(struct mm_struct *mm, bool writable) { struct tlbflush_unmap_batch *tlb_ubc = ¤t->tlb_ubc; - int batch, nbatch; + int batch; arch_tlbbatch_add_mm(&tlb_ubc->arch, mm); tlb_ubc->flush_required = true; @@ -662,11 +662,8 @@ static void set_tlb_ubc_flush_pending(struct mm_struct *mm, bool writable) * overflow. Reset `pending' and `flushed' to be 1 and 0 if * `pending' becomes large. */ - nbatch = atomic_cmpxchg(&mm->tlb_flush_batched, batch, 1); - if (nbatch != batch) { - batch = nbatch; + if (!atomic_try_cmpxchg(&mm->tlb_flush_batched, &batch, 1)) goto retry; - } } else { atomic_inc(&mm->tlb_flush_batched); }