diff --git a/sys/kern/subr_blist.c b/sys/kern/subr_blist.c index 3f8f1771d66..f7e431a0513 100644 --- a/sys/kern/subr_blist.c +++ b/sys/kern/subr_blist.c @@ -278,6 +278,14 @@ blist_destroy(blist_t bl) free(bl, M_SWAP); } +#include +static SYSCTL_NODE(_debug, OID_AUTO, counters, CTLFLAG_RD, 0, ""); + +static long alloc_success, alloc_failure, avg_count, count_err; +SYSCTL_ULONG(_debug_counters, OID_AUTO, alloc_success, CTLFLAG_RD, &alloc_success, 0, ""); +SYSCTL_ULONG(_debug_counters, OID_AUTO, alloc_failure, CTLFLAG_RD, &alloc_failure, 0, ""); +SYSCTL_ULONG(_debug_counters, OID_AUTO, avg_count, CTLFLAG_RD, &avg_count, 0, ""); + /* * blist_alloc() - reserve space in the block bitmap. Return the base * of a contiguous region or SWAPBLK_NONE if space could @@ -297,6 +305,9 @@ blist_alloc(blist_t bl, daddr_t count) * non-zero. When the cursor is zero, an allocation failure will * stop further iterations. */ + count_err += count - avg_count; + avg_count += count_err / (alloc_success + alloc_failure + 1); + count_err %= alloc_success + alloc_failure + 1; for (;;) { blk = blst_meta_alloc(bl->bl_root, bl->bl_cursor, count, bl->bl_radix); @@ -305,9 +316,12 @@ blist_alloc(blist_t bl, daddr_t count) bl->bl_cursor = blk + count; if (bl->bl_cursor == bl->bl_blocks) bl->bl_cursor = 0; + alloc_success++; return (blk); - } else if (bl->bl_cursor == 0) + } else if (bl->bl_cursor == 0) { + alloc_failure++; return (SWAPBLK_NONE); + } bl->bl_cursor = 0; } }