From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 283A73D9DB2 for ; Thu, 4 Jun 2026 10:14:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568059; cv=none; b=k0P5OqFh3jXYmeDEk4kmZpivz6LoLPxqBBjgkiecaRQYj91k/OPFJcKBTnoOzzzGBh9lcfuArFm1ImZuWHo9UkGfxcCHEYH+j/KMUqZCtdAi2LDsXZGvnVqtP1VMwSRAc9t43CKeqJpo5x10rsA1kQdg2gFJaev/eB8hcLTmdE4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568059; c=relaxed/simple; bh=+6t2uJbioeMEUXVzNwnYIks8M+Uq9bE3+ytykv4a81Q=; h=MIME-Version:Date:Content-Type:From:Message-ID:Subject:To:Cc; b=riZd3+jU5ED6oAWmPZWz+3Z3JbLcE9jBz575Ot61jK+f4XYs0s7lVCWWCkrstQwQSmBIJBiQ7qBKBy/eg0yV0uwlXHGB1euFfN/6SEzChmYFzJvWfAhuLzXpgy6ddkPLiNN5+f//kXOaHU5CitNyvPc1nE6pK973zQr25rMHaqU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=LUHVzuY3; arc=none smtp.client-ip=91.218.175.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="LUHVzuY3" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1780568055; h=from:from: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; bh=7RfhhlRPTYpJBSTipt+K7Og5rEq460EM63qs0/sDLck=; b=LUHVzuY3zlA8yMvEm4KGrph0ydiDR1tpJyRdE8KJDoSM7tTSMishMY0f7qxorNGfZosiJe 0pI2MWrrlDyPIO4L0xXorUqOGkvTOJprF0+y7WZayICs8B7imwyX7NdE7trFVmtG8GOEFQ 53RCu8Ki9lt36gS2ovr7uUgr2N03ypk= Date: Thu, 04 Jun 2026 10:13:58 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: ilya.gladyshev@linux.dev Message-ID: <5dabf3a748fee0c7b142c74367e7586f5db1ed1e@linux.dev> TLS-Required: No Subject: [PATCH v3 0/2] mm: improve folio refcount scalability To: ilya.gladyshev@linux.dev Cc: ivgorbunov@me.com, Liam.Howlett@oracle.com, akpm@linux-foundation.org, apopple@nvidia.com, artem.kuzin@huawei.com, baolin.wang@linux.alibaba.com, david@kernel.org, foxido@foxido.dev, harry.yoo@oracle.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, lorenzo.stoakes@oracle.com, mhocko@suse.com, muchun.song@linux.dev, rppt@kernel.org, surenb@google.com, torvalds@linuxfoundation.org, vbabka@suse.cz, willy@infradead.org, yuzhao@google.com, ziy@nvidia.com, pfalcato@suse.de, kirill@shutemov.name X-Migadu-Flow: FLOW_OUT This is v3 of this series with minor changes since v2 [0]: - Fix inverted check in second patch - Rename "unless_zero" functions with "unless_frozen" - Replace set_page_count(1) with init_page_count() Small note: We've had to change our email addresses mid-series; apologies if it confuses anyone. Also sorry for long delay, I will resume my work o= n this. Original cover letter posted below: Intro =3D=3D=3D=3D=3D This patch optimizes small file read performance and overall folio refcou= nt scalability by refactoring page_ref_add_unless [core of folio_try_get]. This is alternative approach to previous attempts to fix small read performance by avoiding refcount bumps [1][2]. Overview =3D=3D=3D=3D=3D=3D=3D=3D Current refcount implementation is using zero counter as locked (dead/fro= zen) state, which required CAS loop for increments to avoid temporary unlocks = in try_get functions. These CAS loops became a serialization point for other= wise scalable and fast read side. Proposed implementation separates "locked" logic from the counting, allow= ing the use of optimistic fetch_add() instead of CAS. For more details, pleas= e refer to the commit message of the patch itself. Proposed logic maintains the same public API as before, including all exi= sting memory barrier guarantees. Performance =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Performance was measured using a simple custom benchmark based on will-it-scale[3]. This benchmark spawns N pinned threads/processes that execute the following loop: `` char buf[] fd =3D open(/* same file in tmpfs */); while (true) { pread(fd, buf, /* read size =3D */ 64, /* offset =3D */0) } `` While this is a synthetic load, it does highlight existing issue and doesn't differ a lot from benchmarking in [2] patch. This benchmark measures operations per second in the inner loop and the results across all workers. Performance was tested on top of v6.15 kernel on two platforms. Since threads and processes showed similar performance = on both systems, only the thread results are provided below. The performance improvement scales linearly between the CPU counts shown. Platform 1: 2 x E5-2690 v3, 12C/12T each [disabled SMT] #threads | vanilla | patched | boost (%) 1 | 1343381 | 1344401 | +0.1 2 | 2186160 | 2455837 | +12.3 5 | 5277092 | 6108030 | +15.7 10 | 5858123 | 7506328 | +28.1 12 | 6484445 | 8137706 | +25.5 /* Cross socket NUMA */ 14 | 3145860 | 4247391 | +35.0 16 | 2350840 | 4262707 | +81.3 18 | 2378825 | 4121415 | +73.2 20 | 2438475 | 4683548 | +92.1 24 | 2325998 | 4529737 | +94.7 Platform 2: 2 x AMD EPYC 9654, 96C/192T each [enabled SMT] #threads | vanilla | patched | boost (%) 1 | 1077276 | 1081653 | +0.4 5 | 4286838 | 4682513 | +9.2 10 | 1698095 | 1902753 | +12.1 20 | 1662266 | 1921603 | +15.6 49 | 1486745 | 1828926 | +23.0 97 | 1617365 | 2052635 | +26.9 /* Cross socket NUMA */ 105 | 1368319 | 1798862 | +31.5 136 | 1008071 | 1393055 | +38.2 168 | 879332 | 1245210 | +41.6 /* SMT */ 193 | 905432 | 1294833 | +43.0 289 | 851988 | 1313110 | +54.1 353 | 771288 | 1347165 | +74.7 [0]: https://lore.kernel.org/lkml/cover.1776350895.git.gorbunov.ivan@h-pa= rtners.com/ [1]: https://lore.kernel.org/linux-mm/CAHk-=3Dwj00-nGmXEkxY=3D-=3DZ_qP6ki= GUziSFvxHJ9N-cLWry5zpA@mail.gmail.com/ [2]: https://lore.kernel.org/linux-mm/20251017141536.577466-1-kirill@shut= emov.name/ [3]: https://github.com/antonblanchard/will-it-scale --- Link to v2: https://lore.kernel.org/lkml/cover.1776350895.git.gorbunov.iv= an@h-partners.com/ --- Gladyshev Ilya (1): mm: implement page refcount locking via dedicated bit Gorbunov Ivan (1): mm: drop page refcount zero state semantics drivers/pci/p2pdma.c | 4 +-- include/linux/mm.h | 2 +- include/linux/page-flags.h | 13 +++++++ include/linux/page_ref.h | 57 ++++++++++++++++++++++++------ kernel/liveupdate/kexec_handover.c | 6 ++-- lib/test_hmm.c | 4 +-- mm/hugetlb.c | 2 +- mm/internal.h | 2 +- mm/memremap.c | 4 +-- mm/mm_init.c | 6 ++-- mm/page_alloc.c | 4 +-- 11 files changed, 77 insertions(+), 27 deletions(-) base-commit: 6f3ed7fec72fc8979b2a8c7219c0a9fcfc8d07b5 --=20 2.43.0