From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 A573839A054 for ; Thu, 21 May 2026 10:18:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779358688; cv=none; b=hdk833jUDpKbf28a9DsikmIGcgC/uuHqv7r3ecNzh/VZPkDwHSaBRWZht2v0cQiDhTlLvO8YG/vr+D6EKHuWL8K+BWB8zOfF9fP75obHf3eQhJ8TINHQ23cakGyI5oKKaKhwY7ohT6GD6g0oW8dgMDAFoUpoe1WdZdZx4RMsAs8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779358688; c=relaxed/simple; bh=9Pe8+ZjrYRQJiOIU8K7FPoyUGDQ+DlBlLp/jlo74mZE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QspsTagbHzNzstw+8BwDk6kho1BttHgbPrgub6wAxof7IDAGiIwz0uAfCapdyKF+PnmSqrkkLRBNSzAWGj0luHKJhQc7vmJG0CxxJUydMMSI0bDkdG/I35IDqCRLsXgj7o+0h48EkpTCRZvOenn19FjOBfZzyQcBPqP8k9SnFjQ= 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=cn5AIKGC; arc=none smtp.client-ip=209.85.215.179 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="cn5AIKGC" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-c802196bd32so515706a12.1 for ; Thu, 21 May 2026 03:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779358685; x=1779963485; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bN7pEF/YCMte4OiPfGkGfT7emXc7eO02yqJ1xiQvVVg=; b=cn5AIKGCnmgM0s8SyGdeicPRNc+09cNXplKa5TsNPAK2LhDa6F22nJKaFGcAHCsbNR ncuVlPtAD7F2V4B++I5vxKBtHv6iqNkYATqPdGwnPfFVVETs3JBM/U+VPkIJCjR5hWIZ LrkDCYlkT1idv7EJ6ErmOPizALx9S2IPOLJ3iTVSZNC26YZ7FN/LvWaRYC+XRfkHgHe+ 2LwP2J5ksMo+DpOB2VULDuq4bp+lyXShUsC1J0cGWsYV1H4yzCW5vryJWjTRFhW9e0QL gSixvLkUMB0yvZHjP4JsrjFYshOiVk7k4xtUdHwgCMoYVAylqibWW7U7520U3avv7RWx uq+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779358685; x=1779963485; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=bN7pEF/YCMte4OiPfGkGfT7emXc7eO02yqJ1xiQvVVg=; b=Ngl3VlmhgqRFBRvMXlgf4joF3GaL8oK7d/EDYD0G43b3QH7FQgdqD3CCtK/k7LRoDU KjVZaOQFfgzfXYpOkxDOhTWhV8QNJ+Jr9dItolxJo7niDKL79pK1nWG/ApM5AN2d59LG LEnj+SIBfXC6+u+xH2RtsCl/gDqenXwxlLMxDfI/H2Oh/SJAXFniqefsydYew4MBOlN1 ewE8U8OVW0f8prnnitGZEMxB6hRTegD4RFq/zO7+p4lxuBFOi9BiueRnjIn0p1uWirvL TV/vjT+/iWrZNqH8jTtxce27gewcxc+MT9O2lTRDVDWEixmGAcEQjo2UAi6LrR7Jj0re Z3MA== X-Forwarded-Encrypted: i=1; AFNElJ9YB0weubHJw0T6W52HXTS6WpZ9y67uxyFrYNAK3QH83fa5G7JclK474zCt0DGXWk1zr9NJLp460HLCqAI=@vger.kernel.org X-Gm-Message-State: AOJu0YwHwuRs4gO3QMnfl4xCrLoY5UL0R6kOo3pv1DKgyBOmo+SOJ5vv CpO1Z1KhkCXDrX+qLme31cyJmPTetHV4X3/ZCJr99KHbbj1DO+3K1Ydf X-Gm-Gg: Acq92OHWhTzNpiNnK4h4e8iSnRe2SFbkHAsHdal9kJbOacGeKFprrcp7ZfSduRvdovZ SLPKce9J2xj5kAbWiyxMBSIJ9ess5/hbzqKMQIGhs9oXIZ3t1fb8QcJMN6A3/fcpFAUZoueVYVB pXVFsXsH64f+tPGlukVezom1fIN36mjvIRfrso16ftAx1McribwEBolochdViS+1zXT3T0f8oUI 6FyT5PVwqh9jqBsfj1TQqPsdgwDBZv22cPLjTBcHgvFiExk40/vGXJueliSBjlsLZlNsdkXztkE GfnZw1pXVZNvxVHlLIjN+14ivn+MiXk/4hFKzJCpdpjYXDhJXIxwCRBoGfPIzta0vlkXnku/a89 T9L9lqVcFvfDjvTxYKQPIh/DT511Oz7TleckYX4R1g6L8JBlzXypP7cuTUMMoHmibQgVXDq5LVS L2gGN2KS+g7kc+yqdOOAfuEZ/Hw+M= X-Received: by 2002:a05:6a00:997:b0:82f:6a82:4231 with SMTP id d2e1a72fcca58-8414ac846bfmr1346412b3a.1.1779358685366; Thu, 21 May 2026 03:18:05 -0700 (PDT) Received: from ser8.. ([221.156.231.192]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84154e1fc86sm1197799b3a.44.2026.05.21.03.18.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2026 03:18:04 -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 v2 2/3] ntfs: avoid heap allocation for free-cluster readahead state Date: Thu, 21 May 2026 19:17:50 +0900 Message-ID: <20260521101751.591345-3-charsyam@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260521101751.591345-1-charsyam@gmail.com> References: <20260520170151.4115308-1-charsyam@gmail.com> <20260521101751.591345-1-charsyam@gmail.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 get_nr_free_clusters() is run from the precalc_free_clusters() worker queued at the end of ntfs_fill_super(). It is also the only place that publishes the result by atomic64_set(&vol->free_clusters, ...), sets NVolSetFreeClusterKnown(), and wakes vol->free_waitq. The function currently allocates a temporary file_ra_state with kzalloc() before that publication happens. If the allocation fails, get_nr_free_clusters() returns 0 without setting NVolFreeClusterKnown() or waking vol->free_waitq, so callers that wait for the free count can block forever. The readahead state is only used synchronously while scanning the bitmap and struct file_ra_state is small. Keep it on the stack and pass it to the readahead helper by address, eliminating the early allocation failure path. Zero-initialize the on-stack state because file_ra_state_init() only sets ra_pages and prev_pos. Signed-off-by: DaeMyung Kang --- fs/ntfs/super.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c index 7e3561265b47..14fd244f29fe 100644 --- a/fs/ntfs/super.c +++ b/fs/ntfs/super.c @@ -1954,7 +1954,7 @@ s64 get_nr_free_clusters(struct ntfs_volume *vol) struct address_space *mapping = vol->lcnbmp_ino->i_mapping; struct folio *folio; pgoff_t index, max_index; - struct file_ra_state *ra; + struct file_ra_state ra = {}; ntfs_debug("Entering."); /* Serialize accesses to the cluster bitmap. */ @@ -1962,11 +1962,7 @@ s64 get_nr_free_clusters(struct ntfs_volume *vol) if (NVolFreeClusterKnown(vol)) return atomic64_read(&vol->free_clusters); - ra = kzalloc(sizeof(*ra), GFP_NOFS); - if (!ra) - return 0; - - file_ra_state_init(ra, mapping); + file_ra_state_init(&ra, mapping); /* * Convert the number of bits into bytes rounded up, then convert into @@ -1985,7 +1981,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 = ntfs_get_locked_folio(mapping, index, max_index, ra); + folio = ntfs_get_locked_folio(mapping, index, max_index, &ra); /* Ignore pages which errored synchronously. */ if (IS_ERR(folio)) { @@ -2024,7 +2020,6 @@ s64 get_nr_free_clusters(struct ntfs_volume *vol) else atomic64_set(&vol->free_clusters, nr_free); - kfree(ra); NVolSetFreeClusterKnown(vol); wake_up_all(&vol->free_waitq); ntfs_debug("Exiting."); -- 2.43.0