Skip to content

Commit 48b7151

Browse files
committed
sbin/cleanerd: cap segments per clean by available free segments
If the file system is low on free segments, the number of segments requested for cleaning ('nsegs_per_step') may exceed the number of actual free segments ('ncleansegs'). Cap 'nsegs_per_step' to 'ncleansegs' in nilfs_cleanerd_select_segments(). This serves as an entry-level guard to prevent invalid requests and helps prevent filesystem operations from getting stuck when free space is running out. Signed-off-by: Ryusuke Konishi <[email protected]>
1 parent 4a733f7 commit 48b7151

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

sbin/cleanerd.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,20 @@ nilfs_cleanerd_select_segments(struct nilfs_cleanerd *cleanerd,
686686
int i;
687687

688688
nsegs_per_step = nilfs_cleanerd_nsegs_per_step(cleanerd);
689+
690+
if (nsegs_per_step > sustat->ss_ncleansegs) {
691+
syslog(LOG_DEBUG,
692+
"reducing segments per cleaning step from %u to %u "
693+
"(ncleansegs)",
694+
nsegs_per_step, (unsigned int)sustat->ss_ncleansegs);
695+
nsegs_per_step = (unsigned int)sustat->ss_ncleansegs;
696+
/*
697+
* Even if nsegs_per_step becomes 0, fall through to update
698+
* timestamps. This ensures nilfs_cleanerd_recalc_interval()
699+
* sets a short retry interval.
700+
*/
701+
}
702+
689703
nilfs = cleanerd->nilfs;
690704

691705
smv = nilfs_vector_create(sizeof(struct nilfs_segimp));

0 commit comments

Comments
 (0)