From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) (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 B7C98396B6F for ; Sat, 28 Feb 2026 07:56:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772265422; cv=none; b=QxDOM8rQO1ZIaRvIqx9wrMkO1F6eRuWuWBadVmnisM1H65H0Qx84oOutmowPMDABLTcyn3z9B70DVxikceqBycqAlKa9VuDzhb7gJJ21Tm36HHHYZC2B9Yu11xVtD1gRRGYo1DLZAQWIykz3+/bEA4uMHh1xo0kWxc6Bz4f8XfE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772265422; c=relaxed/simple; bh=xY3CCkrkAo9GW3Midv3sGtmSu/eziC9wWMZDlFs4HMM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=rTKuG7w2WtAnt632DdhDi8dAnnRl83NB6ClhZJsgutg3sinCYNo09i+yfAeP+mz0o8How7UHHCjYci8eX0Pp1FBb4nKB48vlcGHK7mRhmExOjaPofh4jv4RS+tkVFqIJzCBQIiUjV186Tsd0/Zrdvffwewo56RjIy8GJNXtK2to= 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=lQlO0ig7; arc=none smtp.client-ip=95.215.58.179 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="lQlO0ig7" Message-ID: <1a97fd34-f44e-40bb-806b-7c251d232d27@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1772265417; 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=g4bcAGMvPk6yqnejowgBetfBiy6M1jtDvJ5m57sFLgo=; b=lQlO0ig77PO3To4Pd+DwuX7PWhqQ049o94x7Gf5klkXZa1bvKe4deq2pXuS9OKkN0RJaKI NYpZdndBn0gi2q/eUMXmt0gWLGIMtzadziYyT0OMW0pDglsiQ64TL+lCivo9IxIiCwToAA qilj9pQMiTbCf1OFIXwIhJT9FO2q8GE= Date: Sat, 28 Feb 2026 15:56:29 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH mm-unstable v2 1/5] mm: consolidate anonymous folio PTE mapping into helpers Content-Language: en-US To: Nico Pache Cc: aarcange@redhat.com, akpm@linux-foundation.org, anshuman.khandual@arm.com, apopple@nvidia.com, baohua@kernel.org, baolin.wang@linux.alibaba.com, byungchul@sk.com, catalin.marinas@arm.com, cl@gentwo.org, corbet@lwn.net, dave.hansen@linux.intel.com, david@kernel.org, dev.jain@arm.com, gourry@gourry.net, hannes@cmpxchg.org, hughd@google.com, jackmanb@google.com, jack@suse.cz, jannh@google.com, jglisse@google.com, joshua.hahnjy@gmail.com, kas@kernel.org, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, mathieu.desnoyers@efficios.com, matthew.brost@intel.com, mhiramat@kernel.org, mhocko@suse.com, linux-mm@kvack.org, peterx@redhat.com, pfalcato@suse.de, rakie.kim@sk.com, raquini@redhat.com, rdunlap@infradead.org, richard.weiyang@gmail.com, rientjes@google.com, rostedt@goodmis.org, rppt@kernel.org, ryan.roberts@arm.com, shivankg@amd.com, sunnanyong@huawei.com, surenb@google.com, thomas.hellstrom@linux.intel.com, tiwai@suse.de, usamaarif642@gmail.com, vbabka@suse.cz, vishal.moola@gmail.com, wangkefeng.wang@huawei.com, will@kernel.org, willy@infradead.org, yang@os.amperecomputing.com, ying.huang@linux.alibaba.com, ziy@nvidia.com, zokeefe@google.com, linux-kernel@vger.kernel.org References: <20260226012929.169479-1-npache@redhat.com> <20260226012929.169479-2-npache@redhat.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Lance Yang In-Reply-To: <20260226012929.169479-2-npache@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2026/2/26 09:29, Nico Pache wrote: > The anonymous page fault handler in do_anonymous_page() open-codes the > sequence to map a newly allocated anonymous folio at the PTE level: > - construct the PTE entry > - add rmap > - add to LRU > - set the PTEs > - update the MMU cache. > > Introduce a two helpers to consolidate this duplicated logic, mirroring the > existing map_anon_folio_pmd_nopf() pattern for PMD-level mappings: > > map_anon_folio_pte_nopf(): constructs the PTE entry, takes folio > references, adds anon rmap and LRU. This function also handles the > uffd_wp that can occur in the pf variant. > > map_anon_folio_pte_pf(): extends the nopf variant to handle MM_ANONPAGES > counter updates, and mTHP fault allocation statistics for the page fault > path. > > The zero-page read path in do_anonymous_page() is also untangled from the > shared setpte label, since it does not allocate a folio and should not > share the same mapping sequence as the write path. Make nr_pages = 1 > rather than relying on the variable. This makes it more clear that we > are operating on the zero page only. > > This refactoring will also help reduce code duplication between mm/memory.c > and mm/khugepaged.c, and provides a clean API for PTE-level anonymous folio > mapping that can be reused by future callers. > > Signed-off-by: Nico Pache > --- The refactoring looks good to me. With the change David suggested (removing nr_pages parameter from map_anon_folio_pte_pf() and using folio_order() instead internally), Reviewed-by: Lance Yang