From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (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 602BD1DF27F for ; Wed, 6 May 2026 02:24:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778034241; cv=none; b=u/7krAU1jJX9ZT3UjjbNS6Onk8k7yFD5T1CgKbg4AjreS164rN5VTq8Y4456oeZ8cp1ureOds+FHBKFvjYEfXP1Og/tFPvrp3QZLvUtIFz+WhljJgKscd+Poi0otOQMWZg5yrdqK8gqDRa4S/cn5j3zN/JPL+JhDT750JMdnFu0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778034241; c=relaxed/simple; bh=mdyC6qClgcC1QqgcrULQcHL/tQ1wz6peJDHAbtrf/ns=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=gqIXoyMNsWes6Xlp+I15w0w9H6NeQEeXmz3Kn3cnNeljGChu1v/jirw7co5FgxoLzQvnEXoZ8XchxCdAKw/yM8KuChfUmgFVsrNtGPGg1w053E7V34jaCItwWvvQH8MoPceOjpZlNC+eznfRAGVLlIsofA87DQgpJ4M0qlVlsoc= 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=DaofulPv; arc=none smtp.client-ip=91.218.175.189 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="DaofulPv" Message-ID: <0b9969e2-b208-46c2-a9a5-bf620239275a@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1778034238; 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=M5cG6WceuOLqnIw1nMZgIYwQQBDt8cOC1jRCz8a5xI8=; b=DaofulPv9KSwbTOT6OgFqTtQYPFDc+ubou6Pe+UMtIEL2SqNBXgdufAYrHYdAWk5xW+gfx TgLR/APVu3MHUxyzjFUIxEjygswj38jfmVFv4FSUuyH/5jY967AZ5+yZ7+Vg6U0yG/o9Se nEw4QD+ZQ5jeqVhRJ+VY6RqehhcMAU8= Date: Wed, 6 May 2026 10:23:09 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v4] mm/alloc_tag: replace fixed-size early PFN array with dynamic linked list To: Andrew Morton , Suren Baghdasaryan Cc: Kent Overstreet , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20260430020226.34116-1-hao.ge@linux.dev> <20260430075239.efcceac3d83ede2a2d22158c@linux-foundation.org> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Hao Ge In-Reply-To: <20260430075239.efcceac3d83ede2a2d22158c@linux-foundation.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Hi Andrew and Suren Sorry for the late reply, I was on holiday. On 2026/4/30 22:52, Andrew Morton wrote: > On Thu, 30 Apr 2026 10:02:26 +0800 Hao Ge wrote: > >> Pages allocated before page_ext is available have their codetag left >> uninitialized. Track these early PFNs and clear their codetag in >> clear_early_alloc_pfn_tag_refs() to avoid "alloc_tag was not set" >> warnings when they are freed later. >> >> Currently a fixed-size array of 8192 entries is used, with a warning if >> the limit is exceeded. However, the number of early allocations depends >> on the number of CPUs and can be larger than 8192. >> >> Replace the fixed-size array with a dynamically allocated linked list >> of pfn_pool structs. Each node is allocated via alloc_page() and mapped >> to a pfn_pool containing a next pointer, an atomic slot counter, and a >> PFN array that fills the remainder of the page. >> >> The tracking pages themselves are allocated via alloc_page(), which >> would trigger __pgalloc_tag_add() -> alloc_tag_add_early_pfn() and >> recurse indefinitely. Introduce __GFP_NO_CODETAG (reuses the >> %__GFP_NO_OBJ_EXT bit) and pass gfp_flags through pgalloc_tag_add() >> so that the early path can skip recording allocations that carry this >> flag. > Thanks. AI review asked a couple of questions: > > https://sashiko.dev/#/patchset/20260430020226.34116-1-hao.ge@linux.dev Yes, Sashiko is an excellent tool. Let me carefully go through the questions raised by its review. About question 1 (About question 1 (__GFP_NO_CODETAG aliasing to __GFP_NO_OBJ_EXT may cause SLUB page allocations to be erroneously skipped): No. When SLUB allocates a new slab page via new_slab(), it filters the flags with (GFP_RECLAIM_MASK | GFP_CONSTRAINT_MASK), https://elixir.bootlin.com/linux/v7.0.1/source/mm/slub.c#L3539  which does not include __GFP_NO_OBJ_EXT. So __GFP_NO_OBJ_EXT is never passed through to the page allocator for slab page allocations. About question 2 (retaining caller's zone/placement flags may cause NULL pointer dereference or violate mobility constraints): Sashiko's analysis is correct.  As Suren also suggested, it will be fixed in v5 by masking out GFP_ZONEMASK when allocating tracking pages, so the internal allocation is no longer constrained by the original caller's zone requirements. > Please check to see if there's anything legitimate there? > > It also asked some different questions of the v3 patch: > https://sashiko.dev/#/patchset/20260423083756.157902-1-hao.ge@linux.dev For the v3 patch: About question 3 (race in the cmpxchg failure path: page_ext becomes available between alloc_page() and __free_page(), triggering "alloc_tag was not set"): Good catch. This race was identified during the v3 review and the fix (calling clear_page_tag_ref() before __free_page()) was added in v4. Apologies for not documenting it in the v4 changelogs. CPU A (__alloc_tag_add_early_pfn)                CPU B (clear_early_alloc_pfn_tag_refs) alloc_page() -> codetag uninitialized                         page_ext becomes available cmpxchg() fails __free_page -> WARN Setting the codetag to CODETAG_EMPTY via clear_page_tag_ref() prevents this warning. About question 4 (accounting leak: tracking page gets fully accounted, then clear_page_tag_ref() overwrites to CODETAG_EMPTY, __free_page() skips subtraction): Yes, this can happen. However, the tracking pages are allocated with __GFP_NO_CODETAG and are only used during early boot. The leaked accounting is at most one page per tracking node, which is negligible for this debug-only code path. Thanks Best Regards Hao