From patchwork Sat Dec 7 08:29:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mateusz Guzik X-Patchwork-Id: 13898198 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 3BBA6E7717B for ; Sat, 7 Dec 2024 08:29:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2F536B0326; Sat, 7 Dec 2024 03:29:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DD6B6B0327; Sat, 7 Dec 2024 03:29:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A5666B0328; Sat, 7 Dec 2024 03:29:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 66C726B0326 for ; Sat, 7 Dec 2024 03:29:46 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A888A1A0159 for ; Sat, 7 Dec 2024 08:29:45 +0000 (UTC) X-FDA: 82867488690.08.32E62FA Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) by imf22.hostedemail.com (Postfix) with ESMTP id 84361C0002 for ; Sat, 7 Dec 2024 08:29:24 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="CLnz/EFN"; spf=pass (imf22.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.218.47 as permitted sender) smtp.mailfrom=mjguzik@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733560167; a=rsa-sha256; cv=none; b=VCcpQUviB+/bEx23P+u33Y8GsbENobDMWtWb4ueae33njGxk205EPcOKaTakYL23eg0OR4 fMWeRipvW6yIsWisPO8RF28MKulN2e9FUGOvuIpWv0+4P8hnlvp0cd63C9EJtQMIxe03ri ZGqwhOisvEWRbHp7XwITRxSEHDNF4QY= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="CLnz/EFN"; spf=pass (imf22.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.218.47 as permitted sender) smtp.mailfrom=mjguzik@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733560167; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=UHRpLCsjp7NA8B9f3U/OeguW63g2isrOeZ3w47qo3nE=; b=fZcE8z9bRBLnZAcA3wZDQ7UsfBPw6fT8iiCnFWzYaRyO3JneORz/0oleYR9BLUNNP67qu8 agOeTYuDhNSPQPUoZYN+nvNf6VQBHqle14hKjUrL8UJu6DnApQYUXncvtXljxqFj/D1AbV h1HDuXoGy4fztD42xVIBs/B4bxPLOGk= Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-aa650ccbe0eso46894466b.2 for ; Sat, 07 Dec 2024 00:29:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733560182; x=1734164982; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UHRpLCsjp7NA8B9f3U/OeguW63g2isrOeZ3w47qo3nE=; b=CLnz/EFNNRAhWtYdnbVLA3TcBR95FoAu6GgDPVPEg5EOLZP0SpbRzfDeGAzJqt8r6/ I8WE3igb6TjZZeGhUjsflfJSn+pZvF85sIOh41MdLranTlVFskn5c2U91DzADR+ngC0L yzxo8E8lvqQ47CdMCWloK3l3HzozmuGySZ3EY5FpNf7PN+ALq+62OKaaNoKKAMxiGar6 lujJ2nWV3oAftpDkBJCHFfclltdnKRiqOfxPiY5zEfu4YqCYajJZhTyMDMlSAAgnGdox IYpJJy4TH7fBCLDPUpIGTLeiPChvnnHmzUJDz5o+b/GQRurLBsbwI6D/P1fY0E+JouOO TXsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733560182; x=1734164982; 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=UHRpLCsjp7NA8B9f3U/OeguW63g2isrOeZ3w47qo3nE=; b=Ruud1fYy8DJIvUiHeeZsAWK8AihK0KN8R6/GupSsYGZ8wdp46xx0e8cM4fZ9unwQIf lg56MOmJg0KQbPD5C5x4nH2/suK/O4jLSNxpN7pKmvH80h523jvK05kQXxOAZKlVpzDY 3cyjBSVPwdbv4z7nP4EUNaYWa4CwiG/cwXWCdhEFKRgBDcZ66AD4T9iW4hCGTYWm/r/e 14PTlnVc6KK5F1y4x7ow4pXu42m/bqF9nsGw/g20njerAL0wG99zohhJtaZK1fO4zUaQ 0XYVDEMvVV16HYnd8IZbl2ttlucll42V/Il0LB6y13wezySrNTMg667YVnAQCS2KuNXF gh7w== X-Forwarded-Encrypted: i=1; AJvYcCWHXyfy0/Lmo33NkbQhM5ufwQWeC5JO+6DreTNojDsoOD18Ftgj2UJxWy46/R+wJPNhj8e6ncq1Lg==@kvack.org X-Gm-Message-State: AOJu0YwytUEa+dxMzzhuVAF5bzeYPsROmhC1JG10kSKFNo1QkC90qUXJ OGcSj+5qVCuZTRVCIR0uyFWBOWRYnhqjzXbIXYefUmj4DlnCUiuo X-Gm-Gg: ASbGnctMf+jJWczjV58XGLqZOaE8n+IDMKNAYLUzp5Ey6nDs3i4/oUbPZK5EhdakJXS GaCLWtLtKRSfvNLBBSatmIeMdmaHv/kUSPZXb17GBN/mGTo13d6YLM+ExavWdaCvv6OILp5pq+j D3orF7GSfNJ5QJzhpvoivYo7f84eOJFlfVc7++Z6SclUmolhqe+bZ+9zvCCkl6Y5K7+rr3E8iPh 8ard/c0QXYpNHHkYkiQOhQJEcorwLyeWd+S0oPPAOYFXglEb7hYfpVMV7qzGXbupg== X-Google-Smtp-Source: AGHT+IHHbCeDcdHrgL4CiKBpE8mvUaNfoWyY4qgAovF0EVGhfx93UBqzothSVAYiF0RUjOjLwebxYA== X-Received: by 2002:a17:906:4c2:b0:aa6:538e:a314 with SMTP id a640c23a62f3a-aa6538ea56cmr68764766b.37.1733560181988; Sat, 07 Dec 2024 00:29:41 -0800 (PST) Received: from f.. (cst-prg-17-59.cust.vodafone.cz. [46.135.17.59]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa6590f5457sm37579766b.195.2024.12.07.00.29.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Dec 2024 00:29:40 -0800 (PST) From: Mateusz Guzik To: yuzhao@google.com Cc: akpm@linux-foundation.org, willy@infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Mateusz Guzik Subject: [PATCH] mm: remove an avoidable load of page refcount in page_ref_add_unless Date: Sat, 7 Dec 2024 09:29:31 +0100 Message-ID: <20241207082931.1707465-1-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 84361C0002 X-Stat-Signature: 9oce5dbcsczdew4aem3huuk9y33pm3dd X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1733560164-826954 X-HE-Meta: U2FsdGVkX19Bt9J/UJoFt5GDL6GAJkfdeGQgw9PuN1ZSV0Zld10/H8cZCY/CPiW2yH/49+cOj2F9JnUcNNx0Uqi2VAghd7/faZAMFDFoDEoK6MI1xNQ8U5mrWy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cKTvJRG/A0ug04qCp5u0lREbtVifOhBhUyP8cYnYu3e2AeVFrVbOa8iQRWMeuDknwhFrRDUBp6yR8t8BmMAbyVJH5f0eEejRhw0jASFxu2uFiEwcq9Lqsr6X2qDRG/WXOpp7p7vg11XbAxSaBxMV2zNz3K+xRWHO3modAHZPsq0NH6z4CFVTpwCmAfYRySJteSbPUBgANUdpGzpvEgy98Jbzl+QAxxOr1lJJM/NijrtxPVSF296qPRjUmqeR+UBiaDdnhk4BJuldyEw5nlGCUCgBgbmah5yLk8WvIGpww== X-Bogosity: Ham, tests=bogofilter, spamicity=0.001565, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Explicitly pre-checking the count adds nothing as atomic_add_unless starts with doing the same thing. iow no functional changes. disasm of stock filemap_get_read_batch from perf top while running readseek2_processes -t 24: 0.04 │ cb: mov 0x34(%rbx),%eax # first load 73.11 │ test %eax,%eax │ ↓ je 1bd 0.09 │ mov 0x34(%rbx),%eax # second load 1.01 │ d9: test %eax,%eax │ ↓ je 1bd 0.06 │ lea 0x1(%rax),%edx 0.00 │ lea 0x34(%rbx),%r14 0.00 │ lock cmpxchg %edx,0x34(%rbx) 14.06 │ ↑ jne d9 Signed-off-by: Mateusz Guzik --- I did not bother benchmarking, I don't think there is anything warranting it for this one. fwiw it plausibly is worth few % in a microbenchmark at higher core count. include/linux/page_ref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/page_ref.h b/include/linux/page_ref.h index 8c236c651d1d..fa203894876f 100644 --- a/include/linux/page_ref.h +++ b/include/linux/page_ref.h @@ -234,7 +234,7 @@ static inline bool page_ref_add_unless(struct page *page, int nr, int u) rcu_read_lock(); /* avoid writing to the vmemmap area being remapped */ - if (!page_is_fake_head(page) && page_ref_count(page) != u) + if (!page_is_fake_head(page)) ret = atomic_add_unless(&page->_refcount, nr, u); rcu_read_unlock();