From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (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 63A282BDC23 for ; Sat, 25 Apr 2026 06:21:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777098089; cv=none; b=RSrxx40H/U6+tMXyn5cle+xUIuu/refkecZcCd0gmkv8ErcJ1uJHYzjxPyTzVrlifZ7LLE+InBD7uLA5ZyzosGTyu2Ba/1o1yiNn/kGJt/k/GxOB4w9Cqy22xEjdFjDSJ7I6pBkKzgQzUEm6Wv3Fq5CxywUHqp3qpbFY+jmcdow= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777098089; c=relaxed/simple; bh=4ZN3457nASgHm4tfC11PRBzk9FsN/Ns8nfhU1IFzn84=; h=Content-Type:From:Mime-Version:Subject:Date:Message-Id:References: Cc:In-Reply-To:To; b=foFYD+rvYjOvCe49NQ5RLNT2EcBMkZdMz7gui65KQA1wR5ZqCIeogA7EXP8NeZmGCp0HS9bviElG2uICWSIV4K/sFEefRoJjtiCC1lXHoqQcAOGKrNlz/hfc9twrPE3KuzcZqIgL+3t6/XNx0u4XKyVgRF9sUrqp15zi2OY/jVI= 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=ZCQSa0xM; arc=none smtp.client-ip=91.218.175.181 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="ZCQSa0xM" Content-Type: text/plain; charset=utf-8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1777098076; 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=DHZLJC5B5fmgRAOtQknXGM+s5bBWV7trEmZX8TH0Pyk=; b=ZCQSa0xMAWeLz4zqajISETfXw0jpqKglaKesdUOywfIFOqHdjirtt+ma6LodskeBqPJfos 2sHx8WiBaja3NZLDcHxvFAt1HvSgu28BujosBA5ALe9pIqvU8pMspNe8EEj4HliRx0V/0y I+S/2Px5CbIdsYh0eu/l0FH2uqJGXlQ= Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (1.0) Subject: Re: [PATCH v6 4/7] mm/sparse-vmemmap: Fix DAX vmemmap accounting with optimization Date: Sat, 25 Apr 2026 14:20:39 +0800 Message-Id: <17902B08-7487-4FC8-8EBC-268CE5F3E1B9@linux.dev> References: <02e35414-8c30-4753-9403-432d90263f39@kernel.org> 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, stable@vger.kernel.org In-Reply-To: <02e35414-8c30-4753-9403-432d90263f39@kernel.org> To: David Hildenbrand X-Migadu-Flow: FLOW_OUT > On Apr 25, 2026, at 13:48, David Hildenbrand (Arm) wrot= e: >=20 > =EF=BB=BF >>=20 >>=20 >> Hi David, >>=20 >> Sorry, I missed the 1GB hugepage scenario earlier. Given that sparse_add_= section() >> operates on a scale between PAGES_PER_SUBSECTION and PAGES_PER_SECTION, t= he pfn and >> nr_pages parameters wouldn't be aligned with the hugepage size (pages_per= _compound), >> but rather with the PAGES_PER_SECTION boundary. Do you think this explana= tion makes >> it clearer? In the interest of code clarity, do you think the modificatio= n below >> makes it easier to follow? >>=20 >> diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c >> index 2e642c5ff3f2..ce675c5fb94d 100644 >> --- a/mm/sparse-vmemmap.c >> +++ b/mm/sparse-vmemmap.c >> @@ -658,15 +658,18 @@ static int __meminit section_nr_vmemmap_pages(unsig= ned long pfn, unsigned long n >> const unsigned int order =3D pgmap ? pgmap->vmemmap_shift : 0; >> const unsigned long pages_per_compound =3D 1UL << order; >>=20 >> - VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, >> - min(pages_per_compound, PAGES_PER_SEC= TION))); >> + VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, PAGES_PER_SUBSECTION)= ); >=20 > That here makes sense. We can only add/remove in multiples of PAGES_PER_SE= CTION. > I think what we are saying is that we want that check in addition to the > existing min() check. Right. >=20 >> VM_WARN_ON_ONCE(pfn_to_section_nr(pfn) !=3D pfn_to_section_nr(pfn += nr_pages - 1)); >>=20 >> if (!vmemmap_can_optimize(altmap, pgmap)) >> return DIV_ROUND_UP(nr_pages * sizeof(struct page), PAGE_S= IZE); >>=20 >> - if (order < PFN_SECTION_SHIFT) >> + if (order < PFN_SECTION_SHIFT) { >> + VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, pages_per_com= pound)); >> return VMEMMAP_RESERVE_NR * nr_pages / pages_per_compound;= >=20 > That makes sense as well, within a section, we expect that we always add/r= emove > entire "compound"-managed chunks. >=20 >> + } >> + >> + VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, PAGES_PER_SECTION)); >=20 > And this is then for the case where a 1G page spans multiple sections, whe= re we > expect to add/remove an entire section. >=20 > So here, indeed the "min" makes sense. I guess we also assume: >=20 > VM_WARN_ON_ONCE(nr_pages > PAGES_PER_SECTION); Yes. But this one we do not need to explicit it to assert it since at the front of this function we have VM_WARN_ON_ONCE(pfn_to_section_nr(pfn) !=3D pfn_to_section_nr(pfn + nr_pages= - 1)); to make sure the passing range belongs to one section. Thanks. >=20 > Looks better to me! >=20 > -- > Cheers, >=20 > David