From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) (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 4D33B237180 for ; Sat, 20 Jun 2026 18:19:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.186 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781979575; cv=none; b=JG/cA02Fh2NB3S1I9RqN0x+wMlFDOFW/ckthE1iWpoqCx8+2zD+T5E54BKbeAQIQVCXHBybd76YmPAepsh4XC9NcXKZrCW7YKn9WzbISVW6HWX80aqAF2YtikRV+BcHiIdgehSslZMAxiWxRsJUalsAJkQywQLIwsVFXKyI8g24= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781979575; c=relaxed/simple; bh=ywKzET1/W9QCjuDUoBFC08wFsMsn2rEmmOspkAnJHK0=; h=MIME-Version:Date:Content-Type:From:Message-ID:Subject:To:Cc: In-Reply-To:References; b=VBya4KccWKvRBlJsKK046oJ2JBEOGQNCQ+4+eW0fGhKe3rxys+iBLj7j0ee0DZQV1wMWWgGR0OOhTN+qfggbyjjuXX5FCK3MGOlEDwcxPljkHLSpgWlQw1fz3aRHJY5nOiwZS9AR0kBXzLsm9S1wvLo4Xy23AKuOT+kRXjlj0Iw= 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=qg5TC9lP; arc=none smtp.client-ip=91.218.175.186 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="qg5TC9lP" 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=1781979570; 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: in-reply-to:in-reply-to:references:references; bh=DnwXLv+Azv/S4ZnnUQ/iGBMtsIq6jPezKtzzdS8ZdTU=; b=qg5TC9lPET+ZPm+CqSrRWXvxLxYfqvorf7kKl5EmuS7w+oZtjA/TvyGRB7tWRX/enDcja4 M35DQ8sQUAJGyY09EvvwcnNsA/vHPNVTYWI02Pg3hIlkQQX1dkFPepLl6A4BLHsCHKt56J fro1AoDGwrayAXwGSN2fsJFive34UEo= Date: Sat, 20 Jun 2026 18:19:27 +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: TLS-Required: No Subject: Re: [PATCH v4 0/2] mm: improve folio refcount scalability To: "Andrew Morton" Cc: ivgorbunov@me.com, Liam.Howlett@oracle.com, 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 In-Reply-To: <20260608154734.8e4115fde4e2e14a3b6892fb@linux-foundation.org> References: <20260608154734.8e4115fde4e2e14a3b6892fb@linux-foundation.org> X-Migadu-Flow: FLOW_OUT > > > > > This patch optimizes small file read performance and overall folio re= fcount > > scalability by refactoring page_ref_add_unless [core of folio_try_ge= t]. > > This is alternative approach to previous attempts to fix small read > > performance by avoiding refcount bumps [1][2]. > > > Thanks. Nice numbers. > > AI review had some things to say: > https://sashiko.dev/#/patchset/df26082871b4c65b2bd38d409026237c0857283= 6@linux.dev Among some minor issues, it also pointed out a funny ABA race: ``` T1/T2 work with pages of type X. T3 works with pages of type Y. T1: page_dec_and_test() T1: -> sub refcount [1 -> 0] T1: -> *interrupted* (very bad hypervisor, for example) T2: optimistic get() [0 -> 1] T2: put page back [1 -> 0] T2: calls dtor for type X, returns into the allocator T3: receives page of type Y, sets refcount to 1 T3: page_dec_and_test() T3: -> sub refcount [1 -> 0] *T1 resumes execution* T1: -> CAS [0->LOCKED] T1: BUG: calls dtor of type X on page of type Y ``` While this race seems unrealistic to me because of the full allocator cycle between the two atomic operations, I wasn't able to prove it at the first attempt. Maybe there is some synchronization in allocator that forbids at least X !=3D Y, or something. I'll try to research fixes/proofs a little bit more, but I am afraid that unless someone wise with mm/ knowledge comes up with some fact that I missed, this patch indeed has a major (but unrealistic) flaw. -- Sorry for the delay, grass was more touchable than ever Ilya Gladyshev