From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DC85343208 for ; Wed, 14 Jan 2026 21:33:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768426401; cv=none; b=o34HvcsYkFr9FR4yt7QcfjzHTONXVZxO76z6c6ANIni2eMb+KKO3gvUkfFB5srmDT2K2b5jEqmTWGQOrsREhKq2CFaoU7V1HWXlzhUYMPKXY+DVy1DepLceE/RNaOr00mP+PH8indVDkflNcdcZ7VWOWaIiLRCjdiMlIHYdNHX4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768426401; c=relaxed/simple; bh=Z7q2dDcOGE5HHI9QjGkZF0YF9uZw21LuZRZPZpdyNIM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MKmfLnyLuRL6MIGFakabQIEEdoLVULxsE2sgOnyhqLMfLttzFfzyr9oUqGS3r3wrNisq0Mg5js5sIzOUxyUCmz399YtLaxiXV9BDy1ZAtyJPYT4iO4DXsq2LD+AhtZciwD05zXQGebXq/ZI5DtUj2wVXx99fg9dTDFTBMsbiS8I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=Groves.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JzOa/227; arc=none smtp.client-ip=209.85.210.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=Groves.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JzOa/227" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-7c7533dbd87so195610a34.2 for ; Wed, 14 Jan 2026 13:33:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768426398; x=1769031198; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=WSGuW77Tqa7tA2WLBhJJdwtXNnuVhxLeXVZSIZi6p4U=; b=JzOa/227Efe9oKpPOLLaSbebVvzfyc42E/v99KGVF+H1gXiLXkud0T8kigaTfa5uL5 lhZwrQCXzDxKXbq0DtwO1HWwJPVRiVqmO1rF3np3bwcUBF8pLXEjBsZUTu8SO97D0c// nRhT+LJexsBR+IwpkV/GLsvkEx3G1EttdpDLjmSz2AHQ4pyUuS0D2JbTfDVBeJi6qB8V xo0QXlvy49aoVkqYFUOrO2eJLVq2Fh210DDhm59bglaf7vyb7L9bB4s5/tY9CvOjzjN/ uzYDpUzIPPkqXazqzUXhJt5YN0klwjm+vxxghHp4w2yFB3vR0IXG09R7wE2WVU33sr0y w2yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768426398; x=1769031198; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WSGuW77Tqa7tA2WLBhJJdwtXNnuVhxLeXVZSIZi6p4U=; b=pHY+wHBDasQgqNQaE0TxoGKdPpQ5cdQO0p0WIMGoRL3YhglheKgSa2VLo5Ipf05ZGC oLqx0gkZenFVLePFw7pluluH77yBpV7q+XOQPV6SVA1Sq/FpQYUOUpJ40bOkS80+AKvI FJN4RMyEFDZZvA+V8lnQf8d5ZtVmKfPFY8zEdgS1St6pTAk17IX5oiBYrYhX1R5WvvXx YzvRhB8JCqxcu9WExuBouqhCLWqnd3aDhrRE4As9PCUraRcZcOtoewUTLauDqIfqNePi rIPrAWvIvk0nA7vQ4grgT+YWKCENhYOl2A6mMfnoHbs9PGsKpMcUj1mHNup0gDK1+xtZ Zq+g== X-Forwarded-Encrypted: i=1; AJvYcCVHtJZZfmwUImeCk7bF59meJQVu3h2teFTUpPqXhcvRNwtfPQVi+Twn/BSWjsf0tkN6Bt22ff9AhMI=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2q7FDBtjP87ihgolYaCS0LOq8ewPSj+DxvB0wje2JhDtjgZ4a rLnWz1uV8ZN5J9zhCSoSHon3bA+NY5gK6uDW6Nsaoxfpr6WOs6Hecwte X-Gm-Gg: AY/fxX50ATV+A9iG/hhVsbGwxChxvQoaqYGbaKz+QXbEygBcyYk5nWsZVJfBAhPM7Ed DdkTLSV/O5P5ehSiFAhirRHF+8u7isOkTTRNYKgfbBI9+zryFpN3f3TQcEFqhchF26zf4oc5Z7T VXcz5qAWSEbC/TJdLg7RaeQ+oPBFRkQyWtgYKpt5xc1V6URB7xJnUNlT8If4hAtTUR2dxEwje1B TVzeD3UN869NLegJAziPNuQo5FfD72TwxmgXPAuSNfmvbI4YadZjrRvpekIin6LonLhFr98HAVs KQW/JWmAQEiHKgYLaIpNYVkBmxxNN3Hmt0mI3D7FVgHIvaCzUM5g3keXukpWT7UglmvHwGURNCL uZqYdHXmlT1rWVvS/1oSFkflIbwb+dDC+Vl1Lc8Rypt2APPrvom0zx4MBjfcrB+xLgq5Usxu4P9 PlKOB+rY4C/p+w+uq0XI3+ae0czDFJjLNsrBUU7S9AOLFo X-Received: by 2002:a05:6830:44a4:b0:7c7:4bb:dc06 with SMTP id 46e09a7af769-7cfc8965df3mr3143110a34.0.1768426397962; Wed, 14 Jan 2026 13:33:17 -0800 (PST) Received: from localhost.localdomain ([2603:8080:1500:3d89:4c85:2962:e438:72c4]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7cfd68b13fesm76200a34.3.2026.01.14.13.33.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 14 Jan 2026 13:33:17 -0800 (PST) Sender: John Groves From: John Groves X-Google-Original-From: John Groves To: John Groves , Miklos Szeredi , Dan Williams , Bernd Schubert , Alison Schofield Cc: John Groves , Jonathan Corbet , Vishal Verma , Dave Jiang , Matthew Wilcox , Jan Kara , Alexander Viro , David Hildenbrand , Christian Brauner , "Darrick J . Wong" , Randy Dunlap , Jeff Layton , Amir Goldstein , Jonathan Cameron , Stefan Hajnoczi , Joanne Koong , Josef Bacik , Bagas Sanjaya , James Morse , Fuad Tabba , Sean Christopherson , Shivank Garg , Ackerley Tng , Gregory Price , Aravind Ramesh , Ajay Joshi , venkataravis@micron.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH V4 02/19] dax: Factor out dax_folio_reset_order() helper Date: Wed, 14 Jan 2026 15:31:49 -0600 Message-ID: <20260114213209.29453-3-john@groves.net> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260114213209.29453-1-john@groves.net> References: <20260114153133.29420.compound@groves.net> <20260114213209.29453-1-john@groves.net> Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: John Groves Both fs/dax.c:dax_folio_put() and drivers/dax/fsdev.c: fsdev_clear_folio_state() (the latter coming in the next commit after this one) contain nearly identical code to reset a compound DAX folio back to order-0 pages. Factor this out into a shared helper function. The new dax_folio_reset_order() function: - Clears the folio's mapping and share count - Resets compound folio state via folio_reset_order() - Clears PageHead and compound_head for each sub-page - Restores the pgmap pointer for each resulting order-0 folio - Returns the original folio order (for callers that need to advance by that many pages) This simplifies fsdev_clear_folio_state() from ~50 lines to ~15 lines while maintaining the same functionality in both call sites. Suggested-by: Jonathan Cameron Signed-off-by: John Groves --- fs/dax.c | 60 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 289e6254aa30..7d7bbfb32c41 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -378,6 +378,45 @@ static void dax_folio_make_shared(struct folio *folio) folio->share = 1; } +/** + * dax_folio_reset_order - Reset a compound DAX folio to order-0 pages + * @folio: The folio to reset + * + * Splits a compound folio back into individual order-0 pages, + * clearing compound state and restoring pgmap pointers. + * + * Returns: the original folio order (0 if already order-0) + */ +int dax_folio_reset_order(struct folio *folio) +{ + struct dev_pagemap *pgmap = page_pgmap(&folio->page); + int order = folio_order(folio); + int i; + + folio->mapping = NULL; + folio->share = 0; + + if (!order) { + folio->pgmap = pgmap; + return 0; + } + + folio_reset_order(folio); + + for (i = 0; i < (1UL << order); i++) { + struct page *page = folio_page(folio, i); + struct folio *f = (struct folio *)page; + + ClearPageHead(page); + clear_compound_head(page); + f->mapping = NULL; + f->share = 0; + f->pgmap = pgmap; + } + + return order; +} + static inline unsigned long dax_folio_put(struct folio *folio) { unsigned long ref; @@ -391,28 +430,13 @@ static inline unsigned long dax_folio_put(struct folio *folio) if (ref) return ref; - folio->mapping = NULL; - order = folio_order(folio); - if (!order) - return 0; - folio_reset_order(folio); + order = dax_folio_reset_order(folio); + /* Debug check: verify refcounts are zero for all sub-folios */ for (i = 0; i < (1UL << order); i++) { - struct dev_pagemap *pgmap = page_pgmap(&folio->page); 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; - WARN_ON_ONCE(folio_ref_count(new_folio)); + WARN_ON_ONCE(folio_ref_count((struct folio *)page)); } return ref; -- 2.52.0