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 A3E74AD4B for ; Fri, 12 Dec 2025 06:47:18 +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=1765522042; cv=none; b=qFzhjWtTnBfKYIPZAMSPjkzCpDMR4TZjQ05Ggo3bZ2OF7jArFdRoDAR9ugDeTQ5cjYFyegJpmqYoOELySHrFM+9nfyW7jLbAJvUtVF5JZFtPDQxKdQsoXNfFw/3+9sIbZDk+9aYEf0hxDlhJnRK43q6egoImlIaY6wWXBSMHeGE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765522042; c=relaxed/simple; bh=gtGfmh9p3tGYgu4RUYPI8AbIGUPp1dzfAg3HA0XqSwI=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=DQpMSKF+skUrciHOqVaaBWR4D4wKUUZ7uYdQUy+FPldQmyoWndHBGTn8pifo+d1ArMNhUmMqJEP7LS8GP+upn0NURm7oKRcauyLfi83ZhG6xoVkdYemEXnuODA+uANoY8GFGfpC4s05JhRO3YniIrJ6ZA+FqbbThRqm038tWoDM= 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=B+XC21ml; 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="B+XC21ml" Content-Type: text/plain; charset=utf-8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1765522025; 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=qLUft9+c7O2zPq9tN76DdeBfT+fs7dXB/08o8SAMub4=; b=B+XC21mlZA3Ao1b7UuoXohJSHGGu1NifIskULhjfBIe7T5R8K3CnirKzhW/3VqpzHT3JnA CTqOeSY1aFOg/uhT6ThdQ80x/CvebeIykqf5+s0EVh2+N3foEhJkbXCRj/vZspPffHHESb kPvzz346KGVc7iCWWtWEuOssKKQgQ+E= 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.200.81.1.6\)) Subject: Re: [PATCH 00/11] mm/hugetlb: Eliminate fake head pages from vmemmap optimization X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <5twlonzi3rooao7gyp5g4tyaeevemcx6qhuf4xvdtsi2cykuo4@wrhxmxz63wvn> Date: Fri, 12 Dec 2025 14:45:42 +0800 Cc: Andrew Morton , David Hildenbrand , Oscar Salvador , Mike Rapoport , Vlastimil Babka , Lorenzo Stoakes , Matthew Wilcox , Zi Yan , Baoquan He , Michal Hocko , Johannes Weiner , Jonathan Corbet , Usama Arif , kernel-team@meta.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <4707A7AE-B8A9-4A56-B292-E590E91A9980@linux.dev> References: <20251205194351.1646318-1-kas@kernel.org> <4F9E5F2F-4B4D-4CE2-929D-1D12B1DB44F8@linux.dev> <6396CF70-E10F-4939-8E38-C58BE5BF6F91@linux.dev> <5twlonzi3rooao7gyp5g4tyaeevemcx6qhuf4xvdtsi2cykuo4@wrhxmxz63wvn> To: Kiryl Shutsemau X-Migadu-Flow: FLOW_OUT > On Dec 11, 2025, at 23:08, Kiryl Shutsemau wrote: >=20 > On Wed, Dec 10, 2025 at 11:39:24AM +0800, Muchun Song wrote: >>=20 >>=20 >>> On Dec 9, 2025, at 22:44, Kiryl Shutsemau wrote: >>>=20 >>> On Tue, Dec 09, 2025 at 02:22:28PM +0800, Muchun Song wrote: >>>> The prerequisite is that the starting address of vmemmap must be = aligned to >>>> 16MB boundaries (for 1GB huge pages). Right? We should add some = checks >>>> somewhere to guarantee this (not compile time but at runtime like = for KASLR). >>>=20 >>> I have hard time finding the right spot to put the check. >>>=20 >>> I considered something like the patch below, but it is probably too = late >>> if we boot preallocating huge pages. >>>=20 >>> I will dig more later, but if you have any suggestions, I would >>> appreciate. >>=20 >> If you opt to record the mask information, then even when HVO is >> disabled compound_head will still compute the head-page address >> by means of the mask. Consequently this constraint must hold for >> **every** compound page. =20 >>=20 >> Therefore adding your code in hugetlb_vmemmap.c is not appropriate: >> that file only turns HVO off, yet the calculation remains broken >> for all other large compound pages. >>=20 >> =46rom MAX_FOLIO_ORDER we know that folio_alloc_gigantic() can = allocate >> at most 16 GB of physically contiguous memory. We must therefore >> guarantee that the vmemmap area starts on an address aligned to at >> least 256 MB. >>=20 >> When KASLR is disabled the vmemmap base is normally fixed by a >> macro, so the check can be done at compile time; when KASLR is = enabled >> we have to ensure that the randomly chosen offset is a multiple >> of 256 MB. These two spots are, in my view, the places that need >> to be changed. >>=20 >> Moreover, this approach requires the virtual addresses of struct >> page (possibly spanning sections) to be contiguous, so the method is >> valid **only** under CONFIG_SPARSEMEM_VMEMMAP. >>=20 >> Also, when I skimmed through the overall patch yesterday, one detail >> caught my eye: the shared tail page is **not** "per hstate"; it is >> "per hstate, per zone, per node", because the zone and node >> information is encoded in the tail page=E2=80=99s flags field. We = should make >> sure both page_to_nid() and page_zone() work properly. >=20 > Right. Or we can slap compound_head() inside them.=20 At the same time, to keep users from accidentally passing = compound_head() a handcrafted-on-stack page struct (like snapshot_page()), Shall we add a VM_BUG_ON() in compound_head() to validate that the page address falls within the vmemmap range? Otherwise, compound_head() will return an = invalid head page struct (it is an address on the stack with arbitrary data). >=20 > I stepped onto VM_BUG_ON_PAGE() in get_pfnblock_bitmap_bitidx(). > Workarounded with compound_head() for now. I don=E2=80=99t see why you singled out = get_pfnblock_bitmap_bitidx=E2=80=94what=E2=80=99s special about that spot? >=20 > I am not sure if we want to allocate them per-zone. Seems excessive. Yes. If we could solve page_to_nid() and page_zonenum(), it does not need to be per-zone. > But per-node is reasonable. Agree. >=20 > --=20 > Kiryl Shutsemau / Kirill A. Shutemov