From 5a6523ecf45c88704cea61b3de127d5fc0e2bb9b Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Wed, 25 Mar 2026 13:53:29 -0700 Subject: [PATCH] Ramping up data preallocation Ramps up data preallocation based on the number of online blocks. This results in a simple 2< --- kmod/src/data.c | 10 +++++++++- tests/golden/data-prealloc | 12 ++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/kmod/src/data.c b/kmod/src/data.c index 0abb48c0..b6ca5eb1 100644 --- a/kmod/src/data.c +++ b/kmod/src/data.c @@ -422,6 +422,8 @@ static int alloc_block(struct super_block *sb, struct inode *inode, mutex_lock(&datinf->mutex); + scoutfs_inode_get_onoff(inode, &online, &offline); + /* default to single allocation at the written block */ start = iblock; count = 1; @@ -444,7 +446,6 @@ static int alloc_block(struct super_block *sb, struct inode *inode, * the preallocation size to the number of online * blocks. */ - scoutfs_inode_get_onoff(inode, &online, &offline); if (iblock > 1 && iblock == online) { ret = scoutfs_ext_next(sb, &data_ext_ops, &args, iblock, 1, &found); @@ -486,6 +487,13 @@ static int alloc_block(struct super_block *sb, struct inode *inode, /* trim count by next extent after iblock */ if (found.len && found.start > start && found.start < start + count) count = (found.start - start); + + /* + * Ramp the aligned region size up proportionally with + * the file's online block count rather than jumping to + * the full prealloc size. + */ + count = max_t(u64, 1, min(count, online)); } /* overall prealloc limit */ diff --git a/tests/golden/data-prealloc b/tests/golden/data-prealloc index 19efd20a..69fb3a23 100644 --- a/tests/golden/data-prealloc +++ b/tests/golden/data-prealloc @@ -8,10 +8,10 @@ /mnt/test/test/data-prealloc/file-1: extents: 32 /mnt/test/test/data-prealloc/file-2: extents: 32 == any writes to region prealloc get full extents -/mnt/test/test/data-prealloc/file-1: extents: 4 -/mnt/test/test/data-prealloc/file-2: extents: 4 -/mnt/test/test/data-prealloc/file-1: extents: 4 -/mnt/test/test/data-prealloc/file-2: extents: 4 +/mnt/test/test/data-prealloc/file-1: extents: 8 +/mnt/test/test/data-prealloc/file-2: extents: 8 +/mnt/test/test/data-prealloc/file-1: extents: 8 +/mnt/test/test/data-prealloc/file-2: extents: 8 == streaming offline writes get full extents either way /mnt/test/test/data-prealloc/file-1: extents: 4 /mnt/test/test/data-prealloc/file-2: extents: 4 @@ -20,8 +20,8 @@ == goofy preallocation amounts work /mnt/test/test/data-prealloc/file-1: extents: 6 /mnt/test/test/data-prealloc/file-2: extents: 6 -/mnt/test/test/data-prealloc/file-1: extents: 6 -/mnt/test/test/data-prealloc/file-2: extents: 6 +/mnt/test/test/data-prealloc/file-1: extents: 10 +/mnt/test/test/data-prealloc/file-2: extents: 10 /mnt/test/test/data-prealloc/file-1: extents: 3 /mnt/test/test/data-prealloc/file-2: extents: 3 == block writes into region allocs hole