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 528A43DB33B for ; Thu, 21 May 2026 13:00:36 +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=1779368437; cv=none; b=VLND4oTl89+dgzEFx9+d9ZW9v9y+0nI2TlXXBDzdJKL3TWmn2jTjLA11/MRWRQFZLcWr3cJYK4H/KUaLGrE9L+ARmq0Cm3NDhGyMEvr0lX/eisoSzqD/YZA/VktXrSblPTuZu1wDTRr5XMybWRet1QlFZn92O0NFZivN72ue49g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779368437; c=relaxed/simple; bh=x/2x0r0BsLDAdOTno6N4SEpYiLbcdWoIiiKinLXvW9M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bw0GhzrESatYUIUzy7vhxClcmcsTYy3hd1U850UKWvi8Pu56sltmn5EeARqnyvFsUtDw4ZcqqNdbWelSI/0dlAUBKSEYXQSSt4JaeRnPwLJZgO5JSGrb6jY7AK0mq+O6TS5AtOKci0yYasKTfIe/dytcYcT4t+aguzxN9qe8b8o= 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=dy00ls3+; 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="dy00ls3+" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-c8026ca8365so303622a12.3 for ; Thu, 21 May 2026 06:00:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779368435; x=1779973235; 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=bcTSmoZSiShVO6fj/a8g1RvNK8Nfba3FyLnR3wmldOM=; b=dy00ls3+HYQVcaB+rZ2HpNDC6ZezfqZ/lc1mjHjXhjT9mIqwSiAu7STCLU+FEbjrKz L52zPqsCMQEhMT68qy57rg3JqbExSM+KqaFTkLTEIgPljfy8xcoRRldQ4gG+zObemjHZ aBMBvSQWodTN5fBFAYbmom2UGoDgRd9Hr8gfGTdgu4Gr3Hayv+RXIT60gGPVD6RchTZ/ sZhhzwOvvyoEBNHMcsa47XJew3rCYBSuW6i9zbdfCkzQGoCm+AuirB1Qd8tx4I4xRgj5 F4n5/Yf2a0LmbKtd3APJp1OzoJff0urfcuRQ36cCuoyRqBndc/fLSd6ADvB7FS4cMdyR EJ4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779368435; x=1779973235; 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=bcTSmoZSiShVO6fj/a8g1RvNK8Nfba3FyLnR3wmldOM=; b=J6kKtHTPC3s4RqYdLcVb6eve6muCmL94NHIMdhReffEhydTo74huyKvj+xcw7mkapR AS5knTpoulXKZxjFnilhCjxN3ZSiCDfRljkEzK5jwm2e2XqUhmUpycJtdc9rdKMYGw3I E2fNo3inrr0r4j9jp4427TivuqWK7QHz7D7a1oxrD2+m9E+aPP5ug4DoQ9zhKEAbX/+R lXAiktwUiqhHilz2R//Qo708IiEbfucoLz15dZaq9zD4zKcHYE+8FJywaUrkUrE4ijir uvTXagrvel9FZQWZY/iXPn6NSF7qHqjvJSc9f+m+TyZKNcIBp7GbRqM5D4E0+7/jBizy SRZw== X-Forwarded-Encrypted: i=1; AFNElJ9SJLs/85G+Fzrgb9SynE48ElgkzzWR/vvM1WK0WSu3QX3gjF5v5Zj96zcs2diS8Kp8vyejZVK7JTkf+YE=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5BPAfrilW8nWFokmCDrKqGJQEKFCdslWyieotK1ztA7CUh4Ap /YpECFwT0eVqpEBjN+RY6dNStoM5ODwXopJ7Xa9WAigaTSL94/V1SjkZ X-Gm-Gg: Acq92OHnM3RJG7O03LIaxywWPfhrmo19CMqQJsZEuOiISjE+O6DNGyL3UM3Da4XgEDC mCpli1N6jBKjq93vHoQTHvrfcOcK+Q6AUc63RaYwa7xT7XXTj/S7/fpX6cqu8HUQlx4sfYwQlJX GpWpeS2zq4Iqbce/Dr2ofBMWEexUi/RE4p3zCZhDkViqSV8NZm13Ec4gz5wMgh1mmsHEdbgamK4 PwEU9gy7Ct/bykikowW45CHS0ZCxtFnmXFBTvS2R0LMSmXfhVc94+ye1prS3Q5AeV9Ckc0DkO69 pJsbAHVBmfMsMQlJ/9IO5DmKdQ/iCersbxIj3o8bEhkQKUDcy4Wkz5HV+LPRHBwz/eZY7P2pSCa 8bJoMZM9X/6nxEKo9tMc0tTb+nZU2ZePCLLZVxb0Df3fLK+QbpvO77NCRKQoRKvrcxsEKBwwrxj gFZUWXBkxHoJdYSf+q X-Received: by 2002:a05:6a20:c98d:b0:3b3:203b:3068 with SMTP id adf61e73a8af0-3b3203b386fmr246779637.7.1779368435382; Thu, 21 May 2026 06:00:35 -0700 (PDT) Received: from ser8.. ([221.156.231.192]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c851993d8a7sm284340a12.27.2026.05.21.06.00.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2026 06:00:35 -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 v3 2/3] ntfs: avoid heap allocation for free-cluster readahead state Date: Thu, 21 May 2026 22:00:16 +0900 Message-ID: <20260521130017.713848-3-charsyam@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260521130017.713848-1-charsyam@gmail.com> References: <20260520170151.4115308-1-charsyam@gmail.com> <20260521130017.713848-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..d2c4fb6ea0d4 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 = { 0 }; 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