From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 2144E35504B for ; Fri, 9 Jan 2026 08:56:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767949005; cv=none; b=ARS+/Yr/UlnL57sWG9mal262oQsb7uh97n6rYSRg0wMG5+Kpk0HSGFlbjQzlBcBSal6cA4zzGkS/0Q3Gn/XYlnWMV4Owkh3+alpZETLoIpel2WOmYKxGO391wFyVxuRa7vsWyuUkvmr19wByiB4314tOu4p31/RBQGBM5ZivQWI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767949005; c=relaxed/simple; bh=Ei3iOPS+myBqtT5xuA9JKyEL9TietkXXYAr7sL9XrQ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TXA8x0b18/JLgAijYt7+0GcqBM9hcaHDgfIjNmie8Jd9ulzkGulXmqUldgxun0qtoTMWPo5d5mEJFxZldyJCAliMesnul9wwr5uLUewktoaa0iXqHurGzMzAY947yG0eVNm49z/KECQbzMDG0e6Mn3HuCaRmMS9Y6c19KXOqJgE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=TyavRToq; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TyavRToq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1767948997; x=1799484997; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ei3iOPS+myBqtT5xuA9JKyEL9TietkXXYAr7sL9XrQ0=; b=TyavRToqZ2/3awYiSmxP0/FvlH+l3nCxo5I0A+fHrCxoolgB9BYm7Arj GWPwVmbxUFUksjzT+x7E7RF87/ryEAIOZnUZ+T1Alh3D5q5ETqXEKhBXf Fw22ReZbsW+62YvXvqcIS5gz+STMOItarrvv9zF7Rim4A/0HIqGjXMIO8 fUftY9AH9FjT4uMCrf9J+ChlhBTCEq3tmMtwWigefJliS7qAOt0TOGaG4 V2/W9b0lNTE+jK95dSnbXP9S6/grZxzaIe2G3IGW4gULtY0gPU8eOYb7J 1RjdA919/lvw3pC2+rFvLMrEYryfFJZnOXFB7T6OQBm/RwiXRvXQ54k3f w==; X-CSE-ConnectionGUID: /EF8x0JHSkaHjkVIQxsmOQ== X-CSE-MsgGUID: ivGbl0RxTBeSxgSz08k3tg== X-IronPort-AV: E=McAfee;i="6800,10657,11665"; a="79625968" X-IronPort-AV: E=Sophos;i="6.21,212,1763452800"; d="scan'208";a="79625968" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jan 2026 00:56:34 -0800 X-CSE-ConnectionGUID: LgJ4gWLiSTGmrZf/2pruUQ== X-CSE-MsgGUID: CFcs2tEXQX2urP2N69BAeg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,212,1763452800"; d="scan'208";a="202538591" Received: from pgcooper-mobl3.ger.corp.intel.com (HELO fdugast-desk.intel.com) ([10.245.244.83]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Jan 2026 00:56:30 -0800 From: Francois Dugast To: intel-xe@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org, Matthew Brost , Balbir Singh , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alistair Popple , Francois Dugast Subject: [PATCH v3 1/7] mm: Add folio_split_unref helper Date: Fri, 9 Jan 2026 09:54:21 +0100 Message-ID: <20260109085605.443316-2-francois.dugast@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260109085605.443316-1-francois.dugast@intel.com> References: <20260109085605.443316-1-francois.dugast@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Matthew Brost Add folio_split_unref helper which splits an unreferenced folio (refcount == 0) into individual pages. Intended to be called on special pages (e.g., device-private, DAX, etc.) when returning the folio to the free page pool. Cc: Balbir Singh Cc: Andrew Morton Cc: David Hildenbrand Cc: Lorenzo Stoakes Cc: Zi Yan Cc: Baolin Wang Cc: "Liam R. Howlett" Cc: Nico Pache Cc: Ryan Roberts Cc: Dev Jain Cc: Barry Song Cc: Lance Yang Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Suggested-by: Alistair Popple Signed-off-by: Matthew Brost Signed-off-by: Francois Dugast --- include/linux/huge_mm.h | 1 + mm/huge_memory.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index a4d9f964dfde..18cb9728d8f1 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -369,6 +369,7 @@ enum split_type { SPLIT_TYPE_NON_UNIFORM, }; +void folio_split_unref(struct folio *folio); int __split_huge_page_to_list_to_order(struct page *page, struct list_head *list, unsigned int new_order); int folio_split_unmapped(struct folio *folio, unsigned int new_order); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 40cf59301c21..0eb9e6ad8639 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3580,6 +3580,45 @@ static void __split_folio_to_order(struct folio *folio, int old_order, ClearPageCompound(&folio->page); } +/** + * folio_split_unref() - split an unreferenced folio (refcount == 0) + * @folio: the to-be-split folio + * + * Split an unreferenced folio (refcount == 0) into individual pages. + * Intended to be called on special pages (e.g., device-private, DAX, etc.) + * when returning the folio to the free page pool. + */ +void folio_split_unref(struct folio *folio) +{ + struct dev_pagemap *pgmap = page_pgmap(&folio->page); + int order, i; + + folio->mapping = NULL; + order = folio_order(folio); + if (!order) + return; + + folio_reset_order(folio); + + for (i = 0; i < (1UL << order); i++) { + struct page *page = folio_page(folio, i); + struct folio *new_folio = (struct folio *)page; + + ClearPageHead(page); + clear_compound_head(page); + + new_folio->mapping = NULL; + /* + * Reset pgmap which was over-written by + * prep_compound_page(). + */ + new_folio->pgmap = pgmap; + new_folio->share = 0; /* fsdax only, unused for device private */ + VM_WARN_ON_FOLIO(folio_ref_count(new_folio), new_folio); + } +} +EXPORT_SYMBOL_GPL(folio_split_unref); + /** * __split_unmapped_folio() - splits an unmapped @folio to lower order folios in * two ways: uniform split or non-uniform split. -- 2.43.0