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 701E9C7EE30 for ; Wed, 25 Jun 2025 12:21:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13DF66B00CD; Wed, 25 Jun 2025 08:21:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EF336B00D1; Wed, 25 Jun 2025 08:21:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02AA26B00D2; Wed, 25 Jun 2025 08:21:17 -0400 (EDT) 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 E78D46B00CD for ; Wed, 25 Jun 2025 08:21:17 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id AC22D8029E for ; Wed, 25 Jun 2025 12:21:17 +0000 (UTC) X-FDA: 83593832994.24.A647562 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) by imf09.hostedemail.com (Postfix) with ESMTP id 1D411140007 for ; Wed, 25 Jun 2025 12:21:13 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=dbqPp1zP; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf09.hostedemail.com: domain of lance.yang@linux.dev designates 91.218.175.183 as permitted sender) smtp.mailfrom=lance.yang@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750854076; a=rsa-sha256; cv=none; b=Put5vLHtxOja5xcqY88QqJsc79eR6IZvaF70ZFFoeEXdVCxjBbNYuTi5RJ008nR/fp7VTl OOZB0PABP52lPEepWvu9nfWk2tBxSl+JGxryX1Kda0xZzzggAYoKsIxOK4JH/fnHTZX+Zx c5FyxU6Hli3VocK04X8qH0Cemirin04= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=dbqPp1zP; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf09.hostedemail.com: domain of lance.yang@linux.dev designates 91.218.175.183 as permitted sender) smtp.mailfrom=lance.yang@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750854076; 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:in-reply-to:references:references:dkim-signature; bh=wqF4hhowZcujiHY+iHQl6x5APphUIOsbur9usB3fHMI=; b=l4ZKkGwXBvEWO9JbxJAFoBZSxZ7cYb3DJvfAxvcC72/RlFfUdWqoLIOwqc5evImhJymAJh zKybK/qwZCY+lBHwYbgHq4XSjAKafAAZU4inSI/exUghMcba5qTQ09tt+3pJXQt1erCwQ1 HczrGYDVM7hL6clsJ1E4tBD7K4eBAeM= Message-ID: <42f1d84f-2d17-43b7-8fa2-83322fcca44f@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1750854071; 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=wqF4hhowZcujiHY+iHQl6x5APphUIOsbur9usB3fHMI=; b=dbqPp1zP9dlPKWTDlI3t3zLN5/ONrptH3RYgCcrl9omGqZ7+bmrO3bJa0JRrkvhXraycoV elWuByVDPJUxyjtr6uiYD7om3L3B+0RvEw5odBoxkKBn51UWDL3LIG2VCW5LCytZ2sryAb zKos2fVOnRiQvX68sWQjMUop6cK7z4g= Date: Wed, 25 Jun 2025 20:20:59 +0800 MIME-Version: 1.0 Subject: Re: [PATCH v4 3/4] mm: Support batched unmap for lazyfree large folios during reclamation Content-Language: en-US To: David Hildenbrand Cc: akpm@linux-foundation.org, baolin.wang@linux.alibaba.com, chrisl@kernel.org, kasong@tencent.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, lorenzo.stoakes@oracle.com, ryan.roberts@arm.com, v-songbaohua@oppo.com, x86@kernel.org, ying.huang@intel.com, zhengtangquan@oppo.com, Lance Yang , Barry Song <21cnbao@gmail.com> References: <2c19a6cf-0b42-477b-a672-ed8c1edd4267@redhat.com> <20250624162503.78957-1-ioworker0@gmail.com> <27d174e0-c209-4851-825a-0baeb56df86f@redhat.com> <938c4726-b93e-46df-bceb-65c7574714a6@linux.dev> <5ba95609-302b-456a-a863-2bd5df51baf2@redhat.com> <6179dd30-5351-4a79-b0d6-f0e85650a926@redhat.com> <5db6fb4c-079d-4237-80b3-637565457f39@redhat.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: <5db6fb4c-079d-4237-80b3-637565457f39@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Stat-Signature: cte1aktwxz4go3pbt3wb7pws6pqs8h8r X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 1D411140007 X-HE-Tag: 1750854073-883008 X-HE-Meta: U2FsdGVkX185saZUTRYosUkBSLvCgzV7DQjJROsPNqkdnCVnbMlJU34dzuvThcDcHj7xhQQWjpVNVJuLCaaYrE07pdU8foINdDt23BS3yMXTD/T79WuTMnLLC7i1vqNvI8LlCQ7kaQlZqlyAuEAI8KFF8goptN8F1FD9Jq6KxGxq858bPtZQb+jH6j8kS3tzyFiM8Dn5cnp/KULHQcR+yTe3BbyJpHEpw2lStzHlEW59VaL8jM9GQyrG493YYZ1aiLfw6vOdBJStcZEz7ki4l6+VRmYy7EWxLdO7doph+yrLIRxw41BlWLrz0x8oLB+Ne5HSlhDMBEKX6NBxGnHjf/WmtP9B35mlgcv1C7XeImNXp+Y1Lo6PhzyBpBqWRIPLuGx1fdnbOmKLo9DBpQ6bYQmeV+uzhR/3lCbX4N99RuA9An0aLpK56h60ExbcqwOCvmJ8Jp3BDGuanXS5W6p4D88w80TXisrrrLLZDFAgdzzR18A4DL+sv88sZSHF7l4T7e799WSXUROTbmVrmfa6eObfACnNweQyy95mVExn0jRSZHrhD4JyCJgQENisoAHPRqF8A81NneV1stc3TIPp015vFXkcawgUkhpOinxbk8nGbLGXodgHpN53YW4NKVeOL98N6wFxX7Ul0v4LaNNniK3W2ayOPFEl448LJ3inuLQOkfKSF+LoKo1W8iO5j2XrI7h4vsTzt6d236F1xswIVxhFc5bdYseTW9tZDo6H9YUCYK/L43NjvXfWS2S+ZVzK5rvbc/3VqOdLeUXViQFSwa/yxJupP1qhBHfWh9j7tKkuaZ+FR/isz98UEiDotKO8wPOvdxB5QYVWmREhZDGHQYhvobN+ZcqsK1AOAQXcZ6P10OKIArvJvfmWWQPy4VK2zXw+RmBVKbQhIe7rln7NvQDON6SOAtcconVr8Kn6a2QaB9u5iwoz5Rj7HNfBk7sM8ZDSzIgM41i4Xx1ni/I kJq6Cejl AkN4V5WdCl552tQcmGjCO56+9FogtTvnZmIFZ5M+baC52n1OPbfgi6ZzM/P7H2vcKH+gzOAFRYuD3cHOAwmbJC1RMZklhaVwcermDqPXNHiJiWF0PZ8o5q8pkrIcE8jU680I0tANsNXP8ehkBbumLo+Ka6srH+OhGOjcccGUGgiuXcKJIaxGT5U3ARpGL1jMCQXYsAR3UTRfHOFbl4++NOPyqUTMoS46xNVN4VH40abDU3aPnS/KBSeBO7g== 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 2025/6/25 20:09, David Hildenbrand wrote: >> >> Somehow, I feel we could combine your cleanup code—which handles a batch >> size of "nr" between 1 and nr_pages—with the >> "if (nr_pages == folio_nr_pages(folio)) goto walk_done" check. > > Yeah, that's what I was suggesting. It would have to be part of the > cleanup I think. > > I'm still wondering if there is a case where > > if (nr_pages == folio_nr_pages(folio)) >     goto walk_done; > > would be wrong when dealing with small folios. > >> In practice, this would let us skip almost all unnecessary checks, >> except for a few rare corner cases. >> >> For those corner cases where "nr" truly falls between 1 and nr_pages, >> we can just leave them as-is—performing the redundant check inside >> page_vma_mapped_walk(). > > I mean, batching mapcount+refcount updates etc. is always a win. If we > end up doing some unnecessary pte_none() checks, that might be > suboptimal but mostly noise in contrast to the other stuff we will > optimize out 🙂 > > Agreed that if we can easily avoid these pte_none() checks, we should do > that. Optimizing that for "nr_pages == folio_nr_pages(folio)" makes sense. Hmm... I have a question about the reference counting here ... if (vma->vm_flags & VM_LOCKED) mlock_drain_local(); folio_put(folio); /* We have already batched the entire folio */ Does anyone else still hold a reference to this folio after folio_put()? if (nr_pages == folio_nr_pages(folio)) goto walk_done; continue; walk_abort: ret = false; walk_done: page_vma_mapped_walk_done(&pvmw); break; } Thanks, Lance