From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.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 E2CCF3E8684 for ; Thu, 23 Apr 2026 12:05:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776945912; cv=none; b=RYi7cuxfoCj4HTGMjWm0M2SnyPg8Z5/c8xdIyoi+lp/X4U62rmMSVXCAUAGenW/B9VmDkWbSCNk/6OK2dzsUsiasxzWQuhjhvmvYuJhuLPxySqa5JrFKYmUp5VBLznp0m9em6VBLsXPgcxp7t/tIkPjQ7iyZYURg2kJmXKPq1TE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776945912; c=relaxed/simple; bh=5OaBzsf7cKxFIRXNvzBh+90KjF2F++EZ2r6JaRZV6h0=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=fDFebP24TyaEOvx2NadqlyukHsQyuHQ+R5lp9Yj9W3DpjS0d6NcRi2UObHc1YuA4ViXS5H2AJapS1F2zVWNmWdV0i18JophUAeIOdbEbO6ycWLRyj+tpjiyn1GzFUkqb5YyZh6JydYokbI6Ur7yjhIUFQjD2ZJyyKH3WwIvmF9M= 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=loE9WOAK; arc=none smtp.client-ip=91.218.175.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="loE9WOAK" Content-Type: text/plain; charset=utf-8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776945907; 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=r2ijiexG6FD3eVhJKFQEv8cSP6rYZ0EZ6ENNdT32YGY=; b=loE9WOAKvvpSicNxVCnhTWQ4U0StHn5NBmnVSl5HthVRJaAX8DQNdOjl3sOEec+wJmyBYR 1I3Zw2WfbSOPvDxPo108yOvJgV+wKg5hjlhLbbMfR3YdbIw5ptwEft6Vu75oO/LqQ7QLk6 GK737O+gWWCesjjYSz+fM9tScT+YnzI= 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 v5 v5 4/6] mm/sparse-vmemmap: Fix DAX vmemmap accounting with optimization X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <1cbae635-a115-4270-bae2-64145d16f936@kernel.org> Date: Thu, 23 Apr 2026 20:04:21 +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: <1ADE7CE5-F02D-42B2-B7AC-FE0D6E86042D@linux.dev> References: <20260423071911.1962859-1-songmuchun@bytedance.com> <20260423071911.1962859-5-songmuchun@bytedance.com> <1cbae635-a115-4270-bae2-64145d16f936@kernel.org> To: "David Hildenbrand (Arm)" X-Migadu-Flow: FLOW_OUT > On Apr 23, 2026, at 18:40, David Hildenbrand (Arm) = wrote: >=20 > On 4/23/26 09:19, Muchun Song wrote: >> When vmemmap optimization is enabled for DAX, the nr_memmap_pages >> counter in /proc/vmstat is incorrect. The current code always = accounts >> for the full, non-optimized vmemmap size, but vmemmap optimization >> reduces the actual number of vmemmap pages by reusing tail pages. = This >> causes the system to overcount vmemmap usage, leading to inaccurate >> page statistics in /proc/vmstat. >>=20 >> Fix this by introducing section_vmemmap_pages(), which returns the = exact >> vmemmap page count for a given pfn range based on whether = optimization >> is in effect. >>=20 >> Fixes: 15995a352474 ("mm: report per-page metadata information") >> Signed-off-by: Muchun Song >> Acked-by: Mike Rapoport (Microsoft) >> Acked-by: Oscar Salvador >> --- >> mm/sparse-vmemmap.c | 31 +++++++++++++++++++++++++++---- >> 1 file changed, 27 insertions(+), 4 deletions(-) >>=20 >> diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c >> index 3340f6d30b01..979d71158c9b 100644 >> --- a/mm/sparse-vmemmap.c >> +++ b/mm/sparse-vmemmap.c >> @@ -652,6 +652,28 @@ void offline_mem_sections(unsigned long = start_pfn, unsigned long end_pfn) >> } >> } >>=20 >> +static int __meminit section_nr_vmemmap_pages(unsigned long pfn, = unsigned long nr_pages, >> + struct vmem_altmap *altmap, struct dev_pagemap *pgmap) >> +{ >> + const unsigned int order =3D pgmap ? pgmap->vmemmap_shift : 0; >> + const unsigned long pages_per_compound =3D 1UL << order; >> + >> + VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, = pages_per_compound)); >> + VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, PAGES_PER_SECTION)); >=20 > Thinking about the PAGES_PER_SECTION, can't we get called for = sub-sections? Oh, I see. My apologies=E2=80=94I just remembered why I took the minimum = of pages_per_compound and PAGES_PER_SECTION in the previous version v4: it was specifically to support subsections. In the last version, when I was addressing your suggestions/questions, I forgot about this underlying logic and simplified it to two lines. Of course, that=E2=80=99s on me, not you. Ah, looks like I need to update the patch to fix this. Muchun, Thanks. >=20 > --=20 > Cheers, >=20 > David