From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 B823D409121 for ; Wed, 10 Jun 2026 13:55:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781099743; cv=none; b=nXoY8BjxaZ8vWVKwAFDlHbCWA91YLDWERCI6gHN85g7BBr+p7/CVR7SUwZ9EOHXO2XaGx1GViVLIzOTeTLuaquHhuHjcYR81/pidt7eRigqfBMdsA9xK9Qp1+9H9WotCPBWCZdJEM4qMTWnKZyB0CPPuKamMcY6zysi4xKnhm9M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781099743; c=relaxed/simple; bh=ZpmKwRFTaVDRpEG+RAi47QlgioLtD3fzRnZknrzZESo=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=GNB4cgwtq9fstimKVy2wNTAfLBbqNmuZnxEsr461+zqsbwYJ5cO93nqi4/j3wRJidE/+Hs3igTSigShgRruFmoHNdq2uY43NwsGS1fR5kNiQiyRXgKbBG8IM2bBUL20u6X09Zixnye97xMqCNMlSwe7nHl711bGOeYTex7S5yXc= 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=YeVOAe3F; arc=none smtp.client-ip=209.85.214.169 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="YeVOAe3F" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2c0c35980fdso67850825ad.2 for ; Wed, 10 Jun 2026 06:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781099739; x=1781704539; 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=mQb/iqJQzpo10orrqM+glo+MDt0vouj2eWi6LDZfVHY=; b=YeVOAe3FFx0Yv5n4d0WNkUjBx2HMPFXK/GcCBm1BTLAs6gIVZRZmgbQPHcgNxEoN8A xvs6Z6Sqhr+rojJkBKoPbIvw501BpD7rhTn+pdnOgrJjWVfbV0IGmKDvsJ3iyyPH7fyY vtNBcXYKDgpHZ3nfetpG4dlsQSf02/gPpvG1tt5GgNfeh/qwqTtVTbdtF53CKEzWHphQ MfH4sY4jybjn+DgcWmATwTEcCQOVOep/lcKrq9SztcVwM24awvvzWEZauASuiSK4gcRd MlsNHYV6BtEksNiXEEeve+NYLUs3XxVYwK6xBuCiYctBphLyZaMlQOx4zDD16ZpT+P87 DOwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781099739; x=1781704539; 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=mQb/iqJQzpo10orrqM+glo+MDt0vouj2eWi6LDZfVHY=; b=bzT60yinIHSjVNJ3l0EACkfbEt9HyDayAsWHDWDA+yL97vbPWD6/T5b/Mnt89Kxuwg bMLMgsrAE/XUCIN4muMo5WTU8NqEEhjq7ypnzacaPWghH950XXLEP05a+bweHTsxWfEb qsYf8gLYHpFxV5B+fHX7B2o+9z9bxYQ/03J2XBXAuY1kaMzuexMMHoP3oMOmvdv4yvXO d4b+98uqq5GMYKVJfUjBE2lDtn0JS56cRyKTxfEEFJRXY0yHThtV8mFrRakEFCyPY3V9 BEfWETVAaW9RfZw1h+TOj/kTrIAmQSX9skeABFL2vx/or0/3kW3MYmnyf+cHYjBZglCO pSdg== X-Forwarded-Encrypted: i=1; AFNElJ/A9otR46xa5X64zJeKFrHVLzt76lzCRBTWIiiCGR1B+aR86CkLA0QvzN5q2IptAMUbEaRnYtzHxWqDaic=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1HogdGqvxbxyWyFxJj8W5+pIUE2MKrS5Bd4EGstrHATyCpLca T68CvOeHJz2KJNkb2m56HTfhqS3zcvBQq0hUuTpq93bV2bmz9Ggsm4w1 X-Gm-Gg: Acq92OFQUioIXqlj3pTfzrJp87+6M8QYjRN8VjkwFwG7IDJu3LnF2kR2d50rdbMol3H 27V6sm/UuBhv9UmWHRXB0MjKVqxTuQSaj1APhFGsLoKN/EOyIJFgS75KpdszMtSnCX7xC4pz/P8 7sndLiINpzj1yLv3EhfLiKnxKxmA6M8/8l7+aeh/3prIl42g+HaPpZ4tRLvrHg18o6BTmgOvqWf Y7g3wxwdFtAiun9hf43F1dXupCz+wpLSABudrTvRNduPSiWCuPmo66Sn9NdCTh49llA6JZA/anM nD/uMNytmPs013qWnQD4yQxsAEo4mhHPdTuqJj7iqadtDSYmDSblBOqDJQW0XJAlUYwWyJWkDcy Olc1DIIoI3rgo6wRXFCl2Bq2dvVEO4Bon3wRV9gw5k0VEHkyEtyiNpFzT/WFD+mttLgNukfrohH /MNgLMeGL9Surilv/A2p8vt0E+fLuHAhFmNdP9dWiDKXxyeLo= X-Received: by 2002:a17:902:e883:b0:2c0:ca93:1303 with SMTP id d9443c01a7336-2c1e80e4313mr290888175ad.6.1781099739147; Wed, 10 Jun 2026 06:55:39 -0700 (PDT) Received: from localhost.localdomain ([47.100.192.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c166495203sm239619245ad.70.2026.06.10.06.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2026 06:55:38 -0700 (PDT) From: Yang Wen To: linkinjeon@kernel.org, sj1557.seo@samsung.com Cc: yuezhang.mo@sony.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Yang Wen Subject: [PATCH 2/2] preserve the next empty-entry hint after allocation Date: Wed, 10 Jun 2026 21:55:11 +0800 Message-Id: <20260610135511.203041-1-anmuxixixi@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Advance and preserve the empty-entry hint when only part of a contiguous empty range is consumed. This allows the next file creation to reuse the remaining range without scanning the directory again. Signed-off-by: Yang Wen --- fs/exfat/namei.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index fe26fbf6a0f2..10c58bb7f422 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -273,6 +273,34 @@ static int exfat_check_max_dentries(struct inode *inode) return 0; } +static int exfat_cache_next_empty_entry(struct super_block *sb, + struct exfat_inode_info *ei, struct exfat_hint_femp *hint_femp, + int dentry, int num_entries) +{ + int next, cur_clu, next_clu; + struct exfat_sb_info *sbi = EXFAT_SB(sb); + struct exfat_hint_femp next_hint; + + if (hint_femp->eidx == EXFAT_HINT_NONE || + hint_femp->eidx != dentry || + hint_femp->count <= num_entries) + return 0; + + next = dentry + num_entries; + next_hint = *hint_femp; + next_hint.eidx = next; + next_hint.count -= num_entries; + + cur_clu = dentry / sbi->dentries_per_clu; + next_clu = next / sbi->dentries_per_clu; + if (next_clu > cur_clu && + exfat_chain_advance(sb, &next_hint.cur, next_clu - cur_clu)) + return -EIO; + + ei->hint_femp = next_hint; + return 0; +} + /* * Find an empty directory entry set. * @@ -302,6 +330,7 @@ int exfat_find_empty_entry(struct inode *inode, struct exfat_sb_info *sbi = EXFAT_SB(sb); struct exfat_inode_info *ei = EXFAT_I(inode); struct exfat_hint_femp hint_femp; + struct exfat_hint_femp prev_hint_femp; hint_femp.eidx = EXFAT_HINT_NONE; @@ -314,8 +343,13 @@ int exfat_find_empty_entry(struct inode *inode, exfat_bytes_to_cluster(sbi, i_size_read(inode)), ei->flags); - while ((dentry = exfat_search_empty_slot(sb, &hint_femp, p_dir, - num_entries, es)) < 0) { + for (;;) { + prev_hint_femp = hint_femp; + dentry = exfat_search_empty_slot(sb, &hint_femp, p_dir, + num_entries, es); + if (dentry >= 0) + break; + if (dentry != -ENOSPC) return dentry; @@ -382,6 +416,13 @@ int exfat_find_empty_entry(struct inode *inode, inode->i_blocks += sbi->cluster_size >> 9; } + ret = exfat_cache_next_empty_entry(sb, ei, &prev_hint_femp, dentry, + num_entries); + if (ret) { + exfat_put_dentry_set(es, false); + return ret; + } + p_dir->dir = exfat_sector_to_cluster(sbi, es->bh[0]->b_blocknr); p_dir->size -= dentry / sbi->dentries_per_clu; -- 2.34.1