From nobody Sun May 24 19:33:42 2026 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 AA1F944E027 for ; Fri, 22 May 2026 14:20:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779459660; cv=none; b=nnZ3Emwqg4Gm9Q1qXmTUeh+jTnrUlioYWulk0rOfx/gPsyUmqeISKEiT/gVa/HDMMUoQGkjs/DfUztJ3UtLrsYBiPezdnc5JeEPUAsLjm5wj1dc5okrh7ckdGyt+uRBkL8rUbUWKdpINM9YopYAjbSdwYc9XtT6iGWWd6512e0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779459660; c=relaxed/simple; bh=e/XQ6di4Qf/V7YJFDfeInjZPqQMrEo1MHXIHSm37VgE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=EJ+sdRAJCHMJ8g53ml4MmZsyWvKVi9lK5MFlkoAJYm1LToLDKuIgu7zgQdWRs2Od9lmwxZJABL2rYJcBLvDRGp44LJnqxtodMF/bZHH06NnbIBm3bCK2VB6ka28DDMaUA4WWyf3QAm6Nu+fBe/rKJ1Y2heE2yTdgHdfjRJhHaKo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ctrBJ9ef; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com 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="ctrBJ9ef" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-365deee00c3so676331a91.1 for ; Fri, 22 May 2026 07:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779459653; x=1780064453; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=LUYTSun9nFl805qwarsJbDtTWjRMthsch5tO/uUnULI=; b=ctrBJ9efkJPXFQ8HFkUslk0XtGvCI4Exlt9xYbt/gxbn6L/cA8RVx5KeZIhtiLFO9K oayzhhqrzfBF9EYflSM7dZgJApNxTeXtbsUVPtuI2zxbqfsKdYojQHn3p5kbwUX81rfe cZdtI0wdXQtmZEPOttgTjfucG2PKCmKXrquhC3SVigoYUuNuDog7fAX7Y12Ji24O27kr 4cG/M8ukkYmwTjcVkQImH8e1BmUs1DgEkCwpFzPQ5kHV1OQv2Cq0Awt6addqgny/DWu0 lLEvA+QCrduKe6uCFGJtiYicHwnc50nqwheS7x9dN+e46RFs2RhK/GuUWbeSLPeE28FK l4Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779459653; x=1780064453; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LUYTSun9nFl805qwarsJbDtTWjRMthsch5tO/uUnULI=; b=Vr1EXVtDmo1uFAK1gnVCIRA6bOiJI1YH6UiwnHvzAyJiz3rewztyUAlQ4qm+Hb9s4J qWRGDeQponzBHXzeaVz2m0AnXgtfMhJsBfmUxPOvnZ031cXtU5dTZRmzL3R6pg4zZ5Jk uatm7PZFq1H/MOiVKJSoQ9hiQCnhUQXRdklcvm8g3zuj30zQN0m9bXT5tqA5CVjRwn0Y FJ0yEdleIP4ufHgDzZIwyok2q6QLaLWfq7qkyUfy7BO7P/Y150dRTQRzFXaRHBxIi/O5 b/CSM+zfci+jRCdDijvf7E+IUjNbaq37+IO2cTplmsjxjF6V3rj8K3CJxUun5mJ+iyrI pSjg== X-Forwarded-Encrypted: i=1; AFNElJ/JjusCrM0LzEPd1t24+ihbEk3/+kxmLUthFgCIwq5ZrxgWINRkP/j2uBpExU5C7qviCx3raODrAOhy97M=@vger.kernel.org X-Gm-Message-State: AOJu0YwirUWp3Re6XfcA43wPvFThLum4ipby2CMnTByFX30sCZhdCeE6 UBB7dJ620M0JmCK1RHgm1WgJn8/dORv12BEo56eRVvQ5CzSMN5y1tecy X-Gm-Gg: Acq92OGDVhzhOc7xfPhcmBTKynq1q8HtqCzLnPuFySfB0QSDhhgK+gWW1MERWnVuuxM mTkvNwdACZFOqMEUCY1Q0xHixsyLPN/v8G7cMJDaHIYa3tEzaWuiLOG8nLuTm6Zq3MpZ53goKDp KHVKtlhYMteLxuSQFCSEMgnkha39LhLwEltzR3zrJGn7LqApLkTrfO60faKbE9VsTJtghRyVX6H 0D85YRVNOeW+TxmHQtUI06YWR7HilZF4/rLJ2D+xOLteZzy4A7vwvqOl9Et1C1jsEAsdb/y9lYv Dm3j6986bjH3mzlHGHu0MHz/2rHjJ7za8S+eEoXt/iSvYiIttV4xcD3iY4r/OzyHyx9JfK3/+AS s9zmb5imr8PtuRpuuPUOHSGSRPAbdzrklCKWEPRzlj5e7rIjyKcfqiSh2LEVTjFivZCNLJ3yXQj QsXqmxsrNat3z3wHGHRK+lCR0H4uQ= X-Received: by 2002:a17:90b:3bc6:b0:364:b4e7:6706 with SMTP id 98e67ed59e1d1-36a6741a7ffmr2544742a91.1.1779459652845; Fri, 22 May 2026 07:20:52 -0700 (PDT) Received: from ser8.. ([221.156.231.192]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c852028ff19sm1735120a12.5.2026.05.22.07.20.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 07:20:52 -0700 (PDT) From: DaeMyung Kang To: Namjae Jeon , Hyunchul Lee Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, DaeMyung Kang Subject: [PATCH v4] ntfs: avoid heap allocation for free-cluster readahead state Date: Fri, 22 May 2026 23:20:48 +0900 Message-ID: <20260522142048.1666937-1-charsyam@gmail.com> X-Mailer: git-send-email 2.43.0 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 Content-Type: text/plain; charset="utf-8" get_nr_free_clusters() allocates a temporary file_ra_state before it publishes the precomputed free cluster count, sets NVolFreeClusterKnown(), and wakes vol->free_waitq. If that allocation fails, the worker returns without setting the flag or waking waiters, so callers waiting for the free count can block indefinitely. The readahead state is only used synchronously while scanning the bitmap. Keep it on the stack and pass it by address to the readahead helper. This eliminates the early allocation failure path instead of adding a special case that publishes a conservative count and wakes the waitqueue. Zero-initialize the on-stack state because file_ra_state_init() only sets ra_pages and prev_pos. Apply the same treatment to __get_nr_free_mft_records(), which scans the MFT bitmap with the same short-lived readahead state. Signed-off-by: DaeMyung Kang --- Changes in v4: - Rebase onto ntfs-next. - Convert __get_nr_free_mft_records() in the same way as get_nr_free_clusters(). fs/ntfs/super.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c index 9ebd13d1613b..2a5ad7d56bc2 100644 --- a/fs/ntfs/super.c +++ b/fs/ntfs/super.c @@ -1848,7 +1848,7 @@ s64 get_nr_free_clusters(struct ntfs_volume *vol) struct address_space *mapping =3D vol->lcnbmp_ino->i_mapping; struct folio *folio; pgoff_t index, max_index; - struct file_ra_state *ra; + struct file_ra_state ra =3D { 0 }; =20 ntfs_debug("Entering."); /* Serialize accesses to the cluster bitmap. */ @@ -1856,11 +1856,7 @@ s64 get_nr_free_clusters(struct ntfs_volume *vol) if (NVolFreeClusterKnown(vol)) return atomic64_read(&vol->free_clusters); =20 - ra =3D kzalloc(sizeof(*ra), GFP_NOFS); - if (!ra) - return 0; - - file_ra_state_init(ra, mapping); + file_ra_state_init(&ra, mapping); =20 /* * Convert the number of bits into bytes rounded up, then convert into @@ -1879,7 +1875,7 @@ s64 get_nr_free_clusters(struct ntfs_volume *vol) * Get folio from page cache, getting it from backing store * if necessary, and increment the use count. */ - folio =3D ntfs_get_locked_folio(mapping, index, max_index, ra); + folio =3D ntfs_get_locked_folio(mapping, index, max_index, &ra); =20 /* Ignore pages which errored synchronously. */ if (IS_ERR(folio)) { @@ -1918,7 +1914,6 @@ s64 get_nr_free_clusters(struct ntfs_volume *vol) else atomic64_set(&vol->free_clusters, nr_free); =20 - kfree(ra); NVolSetFreeClusterKnown(vol); wake_up_all(&vol->free_waitq); ntfs_debug("Exiting."); @@ -1973,15 +1968,11 @@ static unsigned long __get_nr_free_mft_records(stru= ct ntfs_volume *vol, struct address_space *mapping =3D vol->mftbmp_ino->i_mapping; struct folio *folio; pgoff_t index; - struct file_ra_state *ra; + struct file_ra_state ra =3D { 0 }; =20 ntfs_debug("Entering."); =20 - ra =3D kzalloc(sizeof(*ra), GFP_NOFS); - if (!ra) - return 0; - - file_ra_state_init(ra, mapping); + file_ra_state_init(&ra, mapping); =20 /* Use multiples of 4 bytes, thus max_size is PAGE_SIZE / 4. */ ntfs_debug("Reading $MFT/$BITMAP, max_index =3D 0x%lx, max_size =3D 0x%lx= .", @@ -1993,7 +1984,7 @@ static unsigned long __get_nr_free_mft_records(struct= ntfs_volume *vol, * Get folio from page cache, getting it from backing store * if necessary, and increment the use count. */ - folio =3D ntfs_get_locked_folio(mapping, index, max_index, ra); + folio =3D ntfs_get_locked_folio(mapping, index, max_index, &ra); =20 /* Ignore pages which errored synchronously. */ if (IS_ERR(folio)) { @@ -2025,7 +2016,6 @@ static unsigned long __get_nr_free_mft_records(struct= ntfs_volume *vol, else atomic64_set(&vol->free_mft_records, nr_free); =20 - kfree(ra); ntfs_debug("Exiting."); return nr_free; } base-commit: 5a717e8c387c2a3ccd372a1b34005c1dcedee297 --=20 2.43.0