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 5610CC7EE30 for ; Wed, 25 Jun 2025 12:36:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC5B16B00D1; Wed, 25 Jun 2025 08:35:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9CD16B00D2; Wed, 25 Jun 2025 08:35:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8C2C6B00D4; Wed, 25 Jun 2025 08:35:59 -0400 (EDT) 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 C7CB76B00D1 for ; Wed, 25 Jun 2025 08:35:59 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7594DB7CEA for ; Wed, 25 Jun 2025 12:35:59 +0000 (UTC) X-FDA: 83593870038.02.006D582 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) by imf30.hostedemail.com (Postfix) with ESMTP id 3136D80004 for ; Wed, 25 Jun 2025 12:35:56 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=wgPth1dx; spf=pass (imf30.hostedemail.com: domain of lance.yang@linux.dev designates 91.218.175.184 as permitted sender) smtp.mailfrom=lance.yang@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750854957; 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=MBhxaGgNjA37rFka6DmFsDUeF2nq5c9Khk7gfBsLM70=; b=tiFHcGpDH0psVlmRArHsT2fmhsXlCCxMGxdvwL0xnx0ZbNxDZ4nBVAe4+bG5R5yrXnZHeJ Z7l3/MMk3FhdmQjOBhmPJXp0vbYXzY9GWnEsttQZQkGbo/TGYKfMi9JdJ385456BIBsMlJ /uWQSvr73jgRhUNez3TgeW9RujE872E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750854957; a=rsa-sha256; cv=none; b=UAZcwXuNEzwPKgClrbeuW+k2aZnwWvVjTRLBGd2maqaYDAa5NciXeUnhrWoTqvYgrePVlq 1MT9tyr0AvK4NpPYjIu5eiDR1dQMW0LqwHhO4+o6ZwZ22bK4FJC3CrQZQga63RAfJy2huJ QEV4um3pxfOCl3A4lV0zu/xwf0+CdIw= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=wgPth1dx; spf=pass (imf30.hostedemail.com: domain of lance.yang@linux.dev designates 91.218.175.184 as permitted sender) smtp.mailfrom=lance.yang@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1750854955; 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=MBhxaGgNjA37rFka6DmFsDUeF2nq5c9Khk7gfBsLM70=; b=wgPth1dxQCRD0V3ed0dRj9oL9K1dKtEq8pPfSmknpZbvJKt1zMt+3QNhkKNfMfZLceO8Qz cPxPaRoBL8WCkPE1QYq1+gDJ6MBR7/n0ZwmoPuZBokr0YeUZSOSOzHn8u4cZN1bumaSLjB Pe1sgLMQ9jKHyZ+aeQC6qLoBmCS1cY8= Date: Wed, 25 Jun 2025 20:35:37 +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> <42f1d84f-2d17-43b7-8fa2-83322fcca44f@linux.dev> <9bb1e917-891d-4e1b-915f-98cdd5fc578b@redhat.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: <9bb1e917-891d-4e1b-915f-98cdd5fc578b@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 3136D80004 X-Stat-Signature: 8ja7i1hnpkn3d959wrj5wwpwjnuwoiea X-Rspam-User: X-HE-Tag: 1750854956-454284 X-HE-Meta: U2FsdGVkX1+LTAYCldgVauv5J0irvs4cM/vLrqNhxqTMEYHcupNT5owhrsT7jRQOF+dRi9edXcPf17uYozALXULZtDX6VgAjzMVDkvgxSClcTwnlVZZKc/MGGXsUyqUeSrfD/kuK4i8QUeIX4vkchK2m73fmyx2bOMlTq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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:25, David Hildenbrand wrote: > On 25.06.25 14:20, Lance Yang wrote: >> >> >> 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()? > > The caller of the unmap operation should better hold a reference :) Ah, you're right. I should have realized that :( Thanks, Lance > > Also, I am not sure why we don't perform a > > folio_put_refs(folio, nr_pages); > > ... :) >