Page MenuHomeFreeBSD

blist_alloc_count.patch

Authored By
dougm
Apr 29 2019, 9:24 PM
Size
1 KB
Referenced Files
None
Subscribers
None

blist_alloc_count.patch

diff --git a/sys/kern/subr_blist.c b/sys/kern/subr_blist.c
index 3f8f1771d66..6a1ca51ae12 100644
--- a/sys/kern/subr_blist.c
+++ b/sys/kern/subr_blist.c
@@ -266,60 +266,70 @@ blist_create(daddr_t blocks, int flags)
);
printf("BLIST raw radix tree contains %lld records\n",
(long long)nodes);
#endif
return (bl);
}
void
blist_destroy(blist_t bl)
{
free(bl, M_SWAP);
}
+#include <sys/sysctl.h>
+static SYSCTL_NODE(_debug, OID_AUTO, counters, CTLFLAG_RD, 0, "");
+
+static long alloc_success, alloc_failure;
+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, "");
+
/*
* blist_alloc() - reserve space in the block bitmap. Return the base
* of a contiguous region or SWAPBLK_NONE if space could
* not be allocated.
*/
daddr_t
blist_alloc(blist_t bl, daddr_t count)
{
daddr_t blk;
if (count > BLIST_MAX_ALLOC)
panic("allocation too large");
/*
* This loop iterates at most twice. An allocation failure in the
* first iteration leads to a second iteration only if the cursor was
* non-zero. When the cursor is zero, an allocation failure will
* stop further iterations.
*/
for (;;) {
blk = blst_meta_alloc(bl->bl_root, bl->bl_cursor, count,
bl->bl_radix);
if (blk != SWAPBLK_NONE) {
bl->bl_avail -= 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;
}
}
/*
* blist_avail() - return the number of free blocks.
*/
daddr_t
blist_avail(blist_t bl)
{
return (bl->bl_avail);
}
/*

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1866475
Default Alt Text
blist_alloc_count.patch (1 KB)

Event Timeline