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 C42F13F9A10 for ; Thu, 18 Jun 2026 13:05:16 +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=1781787918; cv=none; b=oyHr0roAiYJv0Hh2qrDPUr8amujyLuSXQAPgk3iO6b/1vRO64D4G2Ha9dMgnadjIuwzXYZ4P9i70pAdpz8Qfq1h2gFKbLAVAjNPB9ht0OnkVDexM71Tfe2vNGaMNsk7bZ52njwORUlBF+2gdEjexXza4vL0bG2xiOlT5esIaMqk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781787918; c=relaxed/simple; bh=NMuqtT+r3eWCwGaEs6YOhAUtbbXk+HApJZLn8JolWZw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GCuEtvSv6QFj6N/gtTrwSfnCUunFGAKoxMvJZNA69CMpUs3MxI9JlKfM6XKh70nASiaF9Nd5SpXdXj2ZuS2NXcmLUjc+MWqVSSEGvjBKPVaHeUHrBbPjOjgqZwi/EA0YAGyYFiZhvZQyEJIjsP/hedsTKznJsVnV/bibTfpoVoM= 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=Wk5cJwep; 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="Wk5cJwep" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1781787914; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZVVVTITUcrw54iAGavqU8F/yKQPskyiHrFhdNlaRoRA=; b=Wk5cJwepVaWclDc134tmdLNIIt95s41cWvJrYH6zIy4ys2oeHlyZ7+w0NB9b0cAJ8AcELU eUnaOoxjpQTxU1qv/GWWlREw+idktXOppM9MTvbCEogXjBhuP2S80k+/hF2h+PTpaQjRjg gaB7eoLWfGLzW9e19m5+4svhARRIjms= From: Kaitao Cheng To: Andrew Morton , Uladzislau Rezki , Dennis Zhou , Tejun Heo , Christoph Lameter , Vlastimil Babka , Pedro Falcato , Michal Hocko Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kaitao Cheng Subject: [PATCH v4 3/4] mm/percpu: Make cached pages lookup explicit Date: Thu, 18 Jun 2026 21:04:13 +0800 Message-ID: <20260618130414.96383-4-kaitao.cheng@linux.dev> In-Reply-To: <20260618130414.96383-1-kaitao.cheng@linux.dev> References: <20260618130414.96383-1-kaitao.cheng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT From: Kaitao Cheng pcpu_depopulate_chunk() only needs the temporary pages array that was already allocated by an earlier successful population attempt. Passing GFP_KERNEL to pcpu_get_pages() in this path is misleading because the depopulation path is not expected to allocate the array. Teach pcpu_get_pages() to treat a zero gfp mask as a cached-only lookup and add pcpu_get_pages_cached() for that use case. This keeps allocation on the populate path tied to the caller supplied GFP mask while making the depopulate path's dependency on the cached array explicit. Suggested-by: Dennis Zhou Signed-off-by: Kaitao Cheng --- mm/percpu-vm.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c index ccd03cc152d4..7ed216192fc0 100644 --- a/mm/percpu-vm.c +++ b/mm/percpu-vm.c @@ -21,7 +21,8 @@ static struct page *pcpu_chunk_page(struct pcpu_chunk *chunk, /** * pcpu_get_pages - get temp pages array - * @gfp: allocation flags passed to the underlying allocator + * @gfp: allocation flags passed to the underlying allocator, 0 to only + * return the cached array * * Returns pointer to array of pointers to struct page which can be indexed * with pcpu_page_idx(). Note that there is only one array and accesses @@ -37,11 +38,16 @@ static struct page **pcpu_get_pages(gfp_t gfp) lockdep_assert_held(&pcpu_alloc_mutex); - if (!pages) + if (!pages && gfp) pages = pcpu_mem_zalloc(pages_size, gfp); return pages; } +static struct page **pcpu_get_pages_cached(void) +{ + return pcpu_get_pages(0); +} + /** * pcpu_free_pages - free pages which were allocated for @chunk * @chunk: chunk pages were allocated for @@ -333,7 +339,7 @@ static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, * successful population attempt so the temp pages array must * be available now. */ - pages = pcpu_get_pages(GFP_KERNEL); + pages = pcpu_get_pages_cached(); BUG_ON(!pages); /* unmap and free */ -- 2.50.1 (Apple Git-155)