From mboxrd@z Thu Jan 1 00:00:00 1970 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 A479EC52D7C for ; Wed, 14 Aug 2024 03:27:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33A916B0082; Tue, 13 Aug 2024 23:27:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2EB066B0083; Tue, 13 Aug 2024 23:27:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B2BE6B0085; Tue, 13 Aug 2024 23:27:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id F18E96B0082 for ; Tue, 13 Aug 2024 23:27:21 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 95EF41A0B95 for ; Wed, 14 Aug 2024 03:27:21 +0000 (UTC) X-FDA: 82449415482.09.DFF8446 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) by imf11.hostedemail.com (Postfix) with ESMTP id A054840010 for ; Wed, 14 Aug 2024 03:27:19 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=bur.io header.s=fm1 header.b=iIs5JmJb; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=qSks5wzh; spf=pass (imf11.hostedemail.com: domain of boris@bur.io designates 103.168.172.152 as permitted sender) smtp.mailfrom=boris@bur.io; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723606003; a=rsa-sha256; cv=none; b=U6OIO8mp0ni+DsaodivrTBp8UxGJXD4TqYoOxdzEdn34tcwq8KsalLQpuclAG+U+2Sw1wv GqzuXPFf9utn/mBJFQUEuBdTPa6lTHv752Sp4vejH6RIfvIR00CY4e2HWPJ5xyDfNXwHkl Xw8a/OKqI9WRT3DhyAHyJa2mjqLvnrM= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=bur.io header.s=fm1 header.b=iIs5JmJb; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=qSks5wzh; spf=pass (imf11.hostedemail.com: domain of boris@bur.io designates 103.168.172.152 as permitted sender) smtp.mailfrom=boris@bur.io; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723606003; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BICAXi1j/GottHbD3QelZ6gwfxW/NVqoVR6n2xmDzVM=; b=0VtynYEbOuUNTcoOCecxoKiC9GZez3PYToUMIlrrpfO4t62j3KP/j8FvBMA8kbqFmFA9BQ gYgwU0iLmYYZVN6jQUPlghjnyQipQeulSc13OmfLO/wkOwnPlIYTLlMwteaHjp7u6NXbYK I296cE9qRKLvafs/eC+jWHqrCUAu6Cg= Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id CBE711151AD0; Tue, 13 Aug 2024 23:27:18 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 13 Aug 2024 23:27:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bur.io; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1723606038; x=1723692438; bh=BICAXi1j/G ottHbD3QelZ6gwfxW/NVqoVR6n2xmDzVM=; b=iIs5JmJbf35Sy7a/GiZy3ncoB+ YyQqDX+xxS5VDQkg96RBQOS+5wyDrvb3g5V4WHKeN/A0qzq8czrGw77fQyM5EN35 446W2kgGbUQPZfZRZdMO4ZR2f/5xAXDiRPrz24yTok1jLCs5/IwKqPSfrv4gOuun 27r1A8Ul/auvfQuLBsuTCcKMSeEQKXsyKdrGii6H4PoiISl5vrulmeEKFXZ/Ycme U52yaU+L/8/XMoqEnHa6tylUNxgdG/yCE6pczzcx0hDaw5/8dDRsKoJxuvoqe3ZC +owW9HtAmqjwKtwUcikq4wEo8IYgOW6CGpXGcx0gEHL23P0pZglGzLImaH8A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723606038; x=1723692438; bh=BICAXi1j/GottHbD3QelZ6gwfxW/ NVqoVR6n2xmDzVM=; b=qSks5wzheJvromZNzzjoplfm08alLWkXLdrGInEPIkVA SjqsHcI1HOzjAIDcEXqndajiUw15R7y+Pfo9V7cbifrGWqm7KmmbLZnjcPYHAf9B dozMVK8LC3S/ChbpXLkDRPZ8retfvGBD57MDpLJQrH51VCVPum5uyfjqyJP4E4oT ciQ5tJ2y9Mt0eQj+PAyo4x+fK4MWW6N6y9FQOiCol1XrKt9XRMEiXr3DAObEldL/ 5Ekevu86AWK1505d/UZSh8pNsNyIMUzmJDbB7GO7i3yeMgMa/Y4H2dwogF7bNsw8 sv7ihd+GYN4xLLwNMVzryibkhQGSxfey1f+XkCYOTw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtfedgjedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvden ucfhrhhomhepuehorhhishcuuehurhhkohhvuceosghorhhishessghurhdrihhoqeenuc ggtffrrghtthgvrhhnpeekvdekffejleelhfevhedvjeduhfejtdfhvdevieeiiedugfeu gfdtjefgfeeljeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpegsohhrihhssegsuhhrrdhiohdpnhgspghrtghpthhtohepgedpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepfihilhhlhiesihhnfhhrrgguvggrugdrohhrghdprh gtphhtthhopehshhgrkhgvvghlrdgsuhhttheslhhinhhugidruggvvhdprhgtphhtthho pehlihhnuhigqdhmmheskhhvrggtkhdrohhrghdprhgtphhtthhopehlihhnmhhirghohh gvsehhuhgrfigvihdrtghomh X-ME-Proxy: Feedback-ID: i083147f8:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 13 Aug 2024 23:27:17 -0400 (EDT) Date: Tue, 13 Aug 2024 20:27:15 -0700 From: Boris Burkov To: Matthew Wilcox Cc: Shakeel Butt , linux-mm@kvack.org, linmiaohe@huawei.com Subject: Re: [PATCH RFC] mm: fix refcount check in mapping_evict_folio Message-ID: <20240814032715.GA400993@zen.localdomain> References: <5qxfn7y43mf6vkkk6adfgenilahe5uykscz7muxq7tjmjijxg3@dpshd4mrcxgn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: oorgs9tpw3fpf6rcixoctg6gcndthymz X-Rspamd-Queue-Id: A054840010 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1723606039-769581 X-HE-Meta: U2FsdGVkX1/KgMShgNKGqiYFb4tIUFw9Lrq2hiCavOQRFpKWyMIJfBSJHTEIUX0yaGzCaI4IHGVuoklXgSM0OL0OSYOkh/oWfQYaLPQxIC9tYgweUpU9hVYKRuK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JncHJpqyovZYMt8x7h3SGU= 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: List-Subscribe: List-Unsubscribe: On Wed, Aug 14, 2024 at 04:15:25AM +0100, Matthew Wilcox wrote: > On Tue, Aug 13, 2024 at 12:58:09PM -0700, Shakeel Butt wrote: > > > + /* > > > + * The refcount will be elevated if any page in the folio is mapped. > > > + * > > > + * The refcounts break down as follows: > > > + * 1 per mapped page > > > + * 1 from folio_attach_private, if private is set > > > + * 1 from allocating the page in the first place > > > + * 1 from the caller > > > + */ > > > > I think the above explanation is correct at least from my code > > inspection. Most of the callers are related to memory failure. I would > > reword the "1 per mapped page" to "1 per page in page cache" or > > something as mapped here might mean mapped in page tables. > > It's not though. The "1 from allocating the page in the first place" > is donated to the page cache. It's late here and I don't have the > ability to work through what's really going on here. Can you explain what you mean by "donated to the page cache" more precisely? Perhaps there is something better btrfs can do with its refcounting as it calls alloc_pages_bulk_array, then filemap_add_folio, and finally folio_attach_private. But I am not sure which of those refcounts we can (or should?) drop. Thanks, Boris