MCPcopy Create free account
hub / github.com/F-Stack/f-stack / bufspace_daemon

Function bufspace_daemon

freebsd/kern/vfs_bio.c:794–856  ·  view source on GitHub ↗

* bufspace_daemon: * * buffer space management daemon. Tries to maintain some marginal * amount of free buffer space so that requesting processes neither * block nor work to reclaim buffers. */

Source from the content-addressed store, hash-verified

792 * block nor work to reclaim buffers.
793 */
794static void
795bufspace_daemon(void *arg)
796{
797 struct bufdomain *bd;
798
799 EVENTHANDLER_REGISTER(shutdown_pre_sync, kthread_shutdown, curthread,
800 SHUTDOWN_PRI_LAST + 100);
801
802 bd = arg;
803 for (;;) {
804 kthread_suspend_check();
805
806 /*
807 * Free buffers from the clean queue until we meet our
808 * targets.
809 *
810 * Theory of operation: The buffer cache is most efficient
811 * when some free buffer headers and space are always
812 * available to getnewbuf(). This daemon attempts to prevent
813 * the excessive blocking and synchronization associated
814 * with shortfall. It goes through three phases according
815 * demand:
816 *
817 * 1) The daemon wakes up voluntarily once per-second
818 * during idle periods when the counters are below
819 * the wakeup thresholds (bufspacethresh, lofreebuffers).
820 *
821 * 2) The daemon wakes up as we cross the thresholds
822 * ahead of any potential blocking. This may bounce
823 * slightly according to the rate of consumption and
824 * release.
825 *
826 * 3) The daemon and consumers are starved for working
827 * clean buffers. This is the 'bufspace' sleep below
828 * which will inefficiently trade bufs with bqrelse
829 * until we return to condition 2.
830 */
831 while (bd->bd_bufspace > bd->bd_lobufspace ||
832 bd->bd_freebuffers < bd->bd_hifreebuffers) {
833 if (buf_recycle(bd, false) != 0) {
834 if (bd_flushall(bd))
835 continue;
836 /*
837 * Speedup dirty if we've run out of clean
838 * buffers. This is possible in particular
839 * because softdep may held many bufs locked
840 * pending writes to other bufs which are
841 * marked for delayed write, exhausting
842 * clean space until they are written.
843 */
844 bd_speedup();
845 BD_LOCK(bd);
846 if (bd->bd_wanted) {
847 msleep(&bd->bd_wanted, BD_LOCKPTR(bd),
848 PRIBIO|PDROP, "bufspace", hz/10);
849 } else
850 BD_UNLOCK(bd);
851 }

Callers

nothing calls this directly

Calls 6

kthread_suspend_checkFunction · 0.85
buf_recycleFunction · 0.85
bd_flushallFunction · 0.85
bd_speedupFunction · 0.85
maybe_yieldFunction · 0.85
bufspace_daemon_waitFunction · 0.85

Tested by

no test coverage detected