From nobody Tue Jun 9 01:01:39 2026 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) (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 6D4AC38E5DA for ; Mon, 25 May 2026 07:18:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779693542; cv=none; b=b93LTP/sLPOpcB8OXPg5kN1sVUv7UqRsjCoD2/HcAHRPGZRNMbD4RFQMm4+fToAx6yrylo4O+G0Oql5DwM6WE06GOfhSRFyXywCu9mp6d3eylW5C8fLJdQtFHaalZCYi6aH0mccs3AgnIMeCsktoWJ5zx3HraRa9H2y53GMzCU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779693542; c=relaxed/simple; bh=8ya30OXgYG+HnFwWHHtj5AxEYwVs06eYBXe/t50+wQs=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=F4HVOcvgEkFKDLA0bcAjRZuGtA976XHXfbYDbWZ6S0cssq6JSX+dfTnmx5p4ydU8BBdPN8wXVbOMupG/G2nl4W5t2vOxE15YCGMBvsKmfVzbWIxIBNaomC2P+yEqIMITwCHABA2P9P73eaGSqupkLh84uTmjpKJujXuqmVXoivM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; dkim=pass (2048-bit key) header.d=unisoc.com header.i=@unisoc.com header.b=OsZdPPey; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=unisoc.com header.i=@unisoc.com header.b="OsZdPPey" Received: from SHSQR01.spreadtrum.com (localhost [127.0.0.2] (may be forged)) by SHSQR01.spreadtrum.com with ESMTP id 64P7BEQ0091984 for ; Mon, 25 May 2026 15:11:14 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 64P7Ah7Y086797; Mon, 25 May 2026 15:10:43 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from SHDLP.spreadtrum.com (BJMBX01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4gP6Pq1vHKz2LknxW; Mon, 25 May 2026 15:06:55 +0800 (CST) Received: from bj03382pcu03.spreadtrum.com (10.0.73.40) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Mon, 25 May 2026 15:10:41 +0800 From: "zhaoyang.huang" To: Andrew Morton , Vlastimil Babka , Johannes Weiner , Michal Hocko , Suren Baghdasaryan , Brendan Jackman , Zi Yan , , , Zhaoyang Huang , Subject: [PATCH] mm: free HIGHATOMIC and CMA frozen pages via buddy Date: Mon, 25 May 2026 15:10:33 +0800 Message-ID: <20260525071033.1104929-1-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 64P7Ah7Y086797 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unisoc.com; s=default; t=1779693065; bh=WGgiuT8upSNZaz92rgjPyBJ4LtqfGYd9MIM5EPOpwOM=; h=From:To:Subject:Date; b=OsZdPPeyEJDrQjPsTNy96LVO4gRLZ6kk67Y2fvbUiqoVAZe53IS6VPpWC90BG1yNc jDVOz0jWcjS89UPotFkGUH+rd8GMb8M6O99HTdNUkaIxqdPbPBRxKN2NZl62lfWoXO BMHTl6zdM1XfBVcVUoP0B6sWmT1s/8DONVLfFzCGDVWHrgpQEkCwOhn0Os/2yeSzkl C8iku1bn6Zc2cvQZTtM62YoRFN1QicyCrqcLiDNECZmgMUFULhHWKILwfajCz+/84C RMFhTWmlq30PfzBTmnSPkCVFlhNw6/3bg2s8JSoANms6kdN1UzhiHQlLIHFsxD/JcH BjVoWIk3YnY1A== Content-Type: text/plain; charset="utf-8" From: Zhaoyang Huang Pages in pageblocks above MIGRATE_PCPTYPES were remapped to MIGRATE_MOVABLE on the per-CPU lists, so order-9 GFP_ATOMIC allocations could consume CMA physical blocks which may lead to cma_alloc failed. This commit would like to free them through free_one_page() simply. Signed-off-by: Zhaoyang Huang --- mm/page_alloc.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 65e205111553..94b79db8da2f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2945,19 +2945,15 @@ static void __free_frozen_pages(struct page *page, = unsigned int order, =20 /* * We only track unmovable, reclaimable and movable on pcp lists. - * Place ISOLATE pages on the isolated list because they are being - * offlined but treat HIGHATOMIC and CMA as movable pages so we can - * get those areas back if necessary. Otherwise, we may have to free - * excessively into the page allocator + * ISOLATE, HIGHATOMIC and CMA pageblocks are freed directly to the + * buddy allocator so their migratetype is not misrouted on PCP lists + * (e.g. order-9 pages must not share the MIGRATE_MOVABLE THP list). */ zone =3D page_zone(page); migratetype =3D get_pfnblock_migratetype(page, pfn); if (unlikely(migratetype >=3D MIGRATE_PCPTYPES)) { - if (unlikely(is_migrate_isolate(migratetype))) { - free_one_page(zone, page, pfn, order, fpi_flags); - return; - } - migratetype =3D MIGRATE_MOVABLE; + free_one_page(zone, page, pfn, order, fpi_flags); + return; } =20 if (unlikely((fpi_flags & FPI_TRYLOCK) && IS_ENABLED(CONFIG_PREEMPT_RT) @@ -3029,6 +3025,17 @@ void free_unref_folios(struct folio_batch *folios) folio->private =3D NULL; migratetype =3D get_pfnblock_migratetype(&folio->page, pfn); =20 + if (unlikely(!is_migrate_isolate(migratetype) && + migratetype >=3D MIGRATE_PCPTYPES)) { + if (pcp) { + pcp_spin_unlock(pcp); + locked_zone =3D NULL; + pcp =3D NULL; + } + free_one_page(zone, &folio->page, pfn, order, FPI_NONE); + continue; + } + /* Different zone requires a different pcp lock */ if (zone !=3D locked_zone || is_migrate_isolate(migratetype)) { @@ -3061,13 +3068,6 @@ void free_unref_folios(struct folio_batch *folios) locked_zone =3D zone; } =20 - /* - * Non-isolated types over MIGRATE_PCPTYPES get added - * to the MIGRATE_MOVABLE pcp list. - */ - if (unlikely(migratetype >=3D MIGRATE_PCPTYPES)) - migratetype =3D MIGRATE_MOVABLE; - trace_mm_page_free_batched(&folio->page); if (!free_frozen_page_commit(zone, pcp, &folio->page, migratetype, order, FPI_NONE)) { --=20 2.25.1