Suspend/resume culling based on recently released file/block counts

Newer kernels include the counts of objects and blocks unpinned since last
the status was read over the control device fd.  The unpinning is usually
through relinquishment by the netfs.

If these fields are present, extract them and use them to work out whether
there can be anything to cull.  The fields are reset when read and POLLIN
is signalled when the file counter is increased from 0.

If there is nothing new to cull, scanning to build a cull table is
suspended until more stuff is available.  If the new fields are present,
work on that basis - otherwise we sleep for 30s and try again.

The thresholds at which culling should be resumed can be set by adding:

	resume_thresholds <block> <file>

to the config file.  The cull scan is retried when sufficient cumulative
unpinning has happened that either threshold is exceeded.  The block
threshold watches the cumulative i_blocks for unpinned cache inodes and the
file threshold watches the number of cache inodes unpinned.  If either is
"-" then that threshold is disabled.  The default is 5 files and no block


 (*) Some of the variable names are changed to be more obvious as to what
     they do.

 (*) If time-based culling is used, then SIGALRM must be blocked between
     the did-it-happen check and the call to poll.  SIGINT, SIGTERM and
     SIGIO are already so blocked.

 (*) All the decision making logic is moved into the cachefilesd() function
     rather than being spread out.

Signed-off-by: David Howells <>
Reviewed-by: Steve Dickson <>
Reviewed-by: John Snow <>
3 files changed