From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (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 2BBA58460 for ; Tue, 14 Apr 2026 02:34:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776134051; cv=none; b=ti+EOTFnumRDfFcNgHlVfIbIsdHXCnEpUdsV/CDSiEG/i/vmMZiyyn1Z8TgbBdbNSdBKOmcTKw0ZqGoWXLaDMvpzHQlu2sNdJ7G3QQQLTyPxxUVy5AQ6qE13u6gSw4zlQG781G5poiH7X5yMm+ZVDbvL7DNlF5h/MVlbyjKpJ/8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776134051; c=relaxed/simple; bh=6Mxd+v5E8/IBt4rOHVJYzoP31YUZHoktmzqhsESw93c=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=mAervZGdCiXPlb/FlotEZ26A4mMMTY/ieyC6rQA7hkDe2k9ruw/HDgcfjHYMg2h1ztuD1g10QdlbkZrG2uteLl/+sviSbHkZ8saHAcGttwqety6QEHtIO4GDnkzzsJ/23ClQDRTelWkrMTBXWlRhd6vRUIDbQsStkj7BYe1NQsU= 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=YMSIsHOb; arc=none smtp.client-ip=95.215.58.170 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="YMSIsHOb" Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776134048; 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=vw6s/HiBgFDsTXtMvscroT4fKbZCyCeW0iTze1OcKV8=; b=YMSIsHObqjSgUKpGmW7VPicOKfXENbGzne3HXT8+8KeT1nH3cFGRtcU90fcbhRJ37dfUUd DCkmYS6TlpRbNe3kRUHce9SLxBoEsRBGNMEcjUgoWQfhm//49hI7CoBuBLi+jMnwFj92jV cGZXASiaDO0RoydpvGcPc8QexRtGP3Y= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.500.181\)) Subject: Re: [PATCH 03/49] mm/sparse: fix vmemmap page accounting for HVOed DAX X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <2b51659e-5527-4e15-a0a8-41f30f589d07@kernel.org> Date: Tue, 14 Apr 2026 10:33:18 +0800 Cc: Muchun Song , Andrew Morton , Oscar Salvador , Michael Ellerman , Madhavan Srinivasan , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Nicholas Piggin , Christophe Leroy , aneesh.kumar@linux.ibm.com, joao.m.martins@oracle.com, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <65E94431-F4A3-4C8B-B7B9-2ED3EF431DA7@linux.dev> References: <20260405125240.2558577-1-songmuchun@bytedance.com> <20260405125240.2558577-4-songmuchun@bytedance.com> <2b51659e-5527-4e15-a0a8-41f30f589d07@kernel.org> To: "David Hildenbrand (Arm)" X-Migadu-Flow: FLOW_OUT > On Apr 14, 2026, at 02:41, David Hildenbrand (Arm) = wrote: >=20 > On 4/5/26 14:51, Muchun Song wrote: >> When HVO is enabled for DAX, the vmemmap page accounting is wrong = since >> it only accounts for non-HVO case. >>=20 >> Fix the accounting by introducing section_vmemmap_pages() that = returns >> the exact number of vmemmap pages needed for the given pfn range. >>=20 >> Fixes: 15995a352474 ("mm: report per-page metadata information") >> Signed-off-by: Muchun Song >> --- >> mm/sparse-vmemmap.c | 30 ++++++++++++++++++++++++++---- >> 1 file changed, 26 insertions(+), 4 deletions(-) >>=20 >> diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c >> index 7aa9a97498eb..0ef96b1afbcc 100644 >> --- a/mm/sparse-vmemmap.c >> +++ b/mm/sparse-vmemmap.c >> @@ -724,6 +724,27 @@ static int fill_subsection_map(unsigned long = pfn, unsigned long nr_pages) >> return rc; >> } >>=20 >> +static int __meminit section_vmemmap_pages(unsigned long pfn, = unsigned long nr_pages, >> + struct vmem_altmap *altmap, struct dev_pagemap *pgmap) >> +{ >> + unsigned int order =3D pgmap ? pgmap->vmemmap_shift : 0; >> + unsigned long pages_per_compound =3D 1L << order; >> + >> + VM_BUG_ON(!IS_ALIGNED(pfn | nr_pages, min(pages_per_compound, = PAGES_PER_SECTION))); >> + VM_BUG_ON(pfn_to_section_nr(pfn) !=3D pfn_to_section_nr(pfn + = nr_pages - 1)); >> + >> + if (!vmemmap_can_optimize(altmap, pgmap)) >> + return DIV_ROUND_UP(nr_pages * sizeof(struct page), = PAGE_SIZE); >> + >> + if (order < PFN_SECTION_SHIFT) >> + return VMEMMAP_RESERVE_NR * nr_pages / = pages_per_compound; >> + >> + if (IS_ALIGNED(pfn, pages_per_compound)) >> + return VMEMMAP_RESERVE_NR; >=20 > This makes me wonder whether that is really the right place to update > the counter. Can't we update the counter where we actually = allocate/free > the pages, so we don't have to re-calculate that? The vmemmap pages are allocated via vmemmap_populate(). Different architectures may implement their own versions of vmemmap_populate() (though this is relatively rare), leading to the accounting being scattered across various locations. As for vmemmap_free(), there is no generic implementation; since each architecture implements its own version, the accounting would be dispersed across different architectures, making the implementation appear quite complex. Thanks, Muhcun >=20 > --=20 > Cheers, >=20 > David