As old prophecy says, some day UMA_DEBUG printfs shall be made CTRs.

This commit is contained in:
Gleb Smirnoff 2017-06-01 18:36:52 +00:00
parent ac0a6fd015
commit 1431a74845

View File

@ -50,13 +50,6 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/* I should really use ktr.. */
/*
#define UMA_DEBUG 1
#define UMA_DEBUG_ALLOC 1
#define UMA_DEBUG_ALLOC_1 1
*/
#include "opt_ddb.h"
#include "opt_param.h"
#include "opt_vm.h"
@ -822,6 +815,9 @@ keg_free_slab(uma_keg_t keg, uma_slab_t slab, int start)
int i;
uint8_t flags;
CTR4(KTR_UMA, "keg_free_slab keg %s(%p) slab %p, returning %d bytes",
keg->uk_name, keg, slab, PAGE_SIZE * keg->uk_ppera);
mem = slab->us_data;
flags = slab->us_flags;
i = start;
@ -832,10 +828,6 @@ keg_free_slab(uma_keg_t keg, uma_slab_t slab, int start)
}
if (keg->uk_flags & UMA_ZONE_OFFPAGE)
zone_free_item(keg->uk_slabzone, slab, NULL, SKIP_NONE);
#ifdef UMA_DEBUG
printf("%s: Returning %d bytes.\n", keg->uk_name,
PAGE_SIZE * keg->uk_ppera);
#endif
keg->uk_freef(mem, PAGE_SIZE * keg->uk_ppera, flags);
}
@ -858,9 +850,8 @@ keg_drain(uma_keg_t keg)
if (keg->uk_flags & UMA_ZONE_NOFREE || keg->uk_freef == NULL)
return;
#ifdef UMA_DEBUG
printf("%s free items: %u\n", keg->uk_name, keg->uk_free);
#endif
CTR3(KTR_UMA, "keg_drain %s(%p) free items: %u",
keg->uk_name, keg, keg->uk_free);
KEG_LOCK(keg);
if (keg->uk_free == 0)
goto finished;
@ -950,9 +941,6 @@ keg_alloc_slab(uma_keg_t keg, uma_zone_t zone, int wait)
slab = NULL;
mem = NULL;
#ifdef UMA_DEBUG
printf("alloc_slab: Allocating a new slab for %s\n", keg->uk_name);
#endif
allocf = keg->uk_allocf;
KEG_UNLOCK(keg);
@ -1017,6 +1005,9 @@ keg_alloc_slab(uma_keg_t keg, uma_zone_t zone, int wait)
out:
KEG_LOCK(keg);
CTR3(KTR_UMA, "keg_alloc_slab: allocated slab %p for %s(%p)",
slab, keg->uk_name, keg);
if (slab != NULL) {
if (keg->uk_flags & UMA_ZONE_HASH)
UMA_HASH_INSERT(&keg->uk_hash, slab, mem);
@ -1274,15 +1265,13 @@ keg_small_init(uma_keg_t keg)
keg->uk_ipers = slabsize / keg->uk_rsize;
KASSERT(keg->uk_ipers > 0 && keg->uk_ipers <= SLAB_SETSIZE,
("%s: keg->uk_ipers %u", __func__, keg->uk_ipers));
#ifdef UMA_DEBUG
printf("UMA decided we need offpage slab headers for "
"keg: %s, calculated wastedspace = %d, "
CTR6(KTR_UMA, "UMA decided we need offpage slab headers for "
"keg: %s(%p), calculated wastedspace = %d, "
"maximum wasted space allowed = %d, "
"calculated ipers = %d, "
"new wasted space = %d\n", keg->uk_name, wastedspace,
"new wasted space = %d\n", keg->uk_name, keg, wastedspace,
slabsize / UMA_MAX_WASTE, keg->uk_ipers,
slabsize - keg->uk_ipers * keg->uk_rsize);
#endif
keg->uk_flags |= UMA_ZONE_OFFPAGE;
}
@ -1492,13 +1481,10 @@ keg_ctor(void *mem, int size, void *udata, int flags)
if (keg->uk_flags & UMA_ZONE_HASH)
hash_alloc(&keg->uk_hash);
#ifdef UMA_DEBUG
printf("UMA: %s(%p) size %d(%d) flags %#x ipers %d ppera %d out %d free %d\n",
zone->uz_name, zone, keg->uk_size, keg->uk_rsize, keg->uk_flags,
keg->uk_ipers, keg->uk_ppera,
CTR5(KTR_UMA, "keg_ctor %p zone %s(%p) out %d free %d\n",
keg, zone->uz_name, zone,
(keg->uk_pages / keg->uk_ppera) * keg->uk_ipers - keg->uk_free,
keg->uk_free);
#endif
LIST_INSERT_HEAD(&keg->uk_zones, zone, uz_link);
@ -1743,9 +1729,6 @@ uma_startup(void *mem, int npages)
{
struct uma_zctor_args args;
#ifdef UMA_DEBUG
printf("Creating uma keg headers zone and keg.\n");
#endif
rw_init(&uma_rwlock, "UMA lock");
/* "manually" create the initial zone */
@ -1766,9 +1749,6 @@ uma_startup(void *mem, int npages)
bootmem = mem;
boot_pages = npages;
#ifdef UMA_DEBUG
printf("Creating uma zone headers zone and keg.\n");
#endif
args.name = "UMA Zones";
args.size = sizeof(struct uma_zone) +
(sizeof(struct uma_cache) * (mp_maxid + 1));
@ -1782,10 +1762,6 @@ uma_startup(void *mem, int npages)
/* The initial zone has no Per cpu queues so it's smaller */
zone_ctor(zones, sizeof(struct uma_zone), &args, M_WAITOK);
#ifdef UMA_DEBUG
printf("Creating slab and hash zones.\n");
#endif
/* Now make a zone for slab headers */
slabzone = uma_zcreate("UMA Slabs",
sizeof(struct uma_slab),
@ -1800,10 +1776,6 @@ uma_startup(void *mem, int npages)
bucket_init();
booted = UMA_STARTUP;
#ifdef UMA_DEBUG
printf("UMA startup complete.\n");
#endif
}
/* see uma.h */
@ -1813,9 +1785,6 @@ uma_startup2(void)
booted = UMA_STARTUP2;
bucket_enable();
sx_init(&uma_drain_lock, "umadrain");
#ifdef UMA_DEBUG
printf("UMA startup2 complete.\n");
#endif
}
/*
@ -1826,14 +1795,9 @@ uma_startup2(void)
static void
uma_startup3(void)
{
#ifdef UMA_DEBUG
printf("Starting callout.\n");
#endif
callout_init(&uma_callout, 1);
callout_reset(&uma_callout, UMA_TIMEOUT * hz, uma_timeout, NULL);
#ifdef UMA_DEBUG
printf("UMA startup3 complete.\n");
#endif
}
static uma_keg_t
@ -2073,11 +2037,8 @@ uma_zalloc_arg(uma_zone_t zone, void *udata, int flags)
random_harvest_fast_uma(&zone, sizeof(zone), 1, RANDOM_UMA);
/* This is the fast path allocation */
#ifdef UMA_DEBUG_ALLOC_1
printf("Allocating one item from %s(%p)\n", zone->uz_name, zone);
#endif
CTR3(KTR_UMA, "uma_zalloc_arg thread %x zone %s flags %d", curthread,
zone->uz_name, flags);
CTR4(KTR_UMA, "uma_zalloc_arg thread %x zone %s(%p) flags %d",
curthread, zone->uz_name, zone, flags);
if (flags & M_WAITOK) {
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
@ -2150,9 +2111,9 @@ uma_zalloc_arg(uma_zone_t zone, void *udata, int flags)
*/
bucket = cache->uc_freebucket;
if (bucket != NULL && bucket->ub_cnt > 0) {
#ifdef UMA_DEBUG_ALLOC
printf("uma_zalloc: Swapping empty with alloc.\n");
#endif
CTR2(KTR_UMA,
"uma_zalloc: zone %s(%p) swapping empty with alloc",
zone->uz_name, zone);
cache->uc_freebucket = cache->uc_allocbucket;
cache->uc_allocbucket = bucket;
goto zalloc_start;
@ -2233,6 +2194,8 @@ uma_zalloc_arg(uma_zone_t zone, void *udata, int flags)
* will use the just filled bucket.
*/
bucket = zone_alloc_bucket(zone, udata, flags);
CTR3(KTR_UMA, "uma_zalloc: zone %s(%p) bucket zone returned %p",
zone->uz_name, zone, bucket);
if (bucket != NULL) {
ZONE_LOCK(zone);
critical_enter();
@ -2254,10 +2217,6 @@ uma_zalloc_arg(uma_zone_t zone, void *udata, int flags)
/*
* We may not be able to get a bucket so return an actual item.
*/
#ifdef UMA_DEBUG
printf("uma_zalloc_arg: Bucketzone returned NULL\n");
#endif
zalloc_item:
item = zone_alloc_item(zone, udata, flags);
@ -2563,9 +2522,6 @@ zone_alloc_item(uma_zone_t zone, void *udata, int flags)
item = NULL;
#ifdef UMA_DEBUG_ALLOC
printf("INTERNAL: Allocating one item from %s(%p)\n", zone->uz_name, zone);
#endif
if (zone->uz_import(zone->uz_arg, &item, 1, flags) != 1)
goto fail;
atomic_add_long(&zone->uz_allocs, 1);
@ -2594,9 +2550,14 @@ zone_alloc_item(uma_zone_t zone, void *udata, int flags)
if (flags & M_ZERO)
uma_zero_item(item, zone);
CTR3(KTR_UMA, "zone_alloc_item item %p from %s(%p)", item,
zone->uz_name, zone);
return (item);
fail:
CTR2(KTR_UMA, "zone_alloc_item failed from %s(%p)",
zone->uz_name, zone);
atomic_add_long(&zone->uz_fails, 1);
return (NULL);
}
@ -2613,9 +2574,6 @@ uma_zfree_arg(uma_zone_t zone, void *item, void *udata)
/* Enable entropy collection for RANDOM_ENABLE_UMA kernel option */
random_harvest_fast_uma(&zone, sizeof(zone), 1, RANDOM_UMA);
#ifdef UMA_DEBUG_ALLOC_1
printf("Freeing item %p to %s(%p)\n", item, zone->uz_name, zone);
#endif
CTR2(KTR_UMA, "uma_zfree_arg thread %x zone %s", curthread,
zone->uz_name);
@ -2727,9 +2685,9 @@ uma_zfree_arg(uma_zone_t zone, void *item, void *udata)
/* Can we throw this on the zone full list? */
if (bucket != NULL) {
#ifdef UMA_DEBUG_ALLOC
printf("uma_zfree: Putting old bucket on the free list.\n");
#endif
CTR3(KTR_UMA,
"uma_zfree: zone %s(%p) putting bucket %p on free list",
zone->uz_name, zone, bucket);
/* ub_cnt is pointing to the last free item */
KASSERT(bucket->ub_cnt != 0,
("uma_zfree: Attempting to insert an empty bucket onto the full list.\n"));
@ -2744,10 +2702,9 @@ uma_zfree_arg(uma_zone_t zone, void *item, void *udata)
zone->uz_count++;
ZONE_UNLOCK(zone);
#ifdef UMA_DEBUG_ALLOC
printf("uma_zfree: Allocating new free bucket.\n");
#endif
bucket = bucket_alloc(zone, udata, M_NOWAIT);
CTR3(KTR_UMA, "uma_zfree: zone %s(%p) allocated bucket %p",
zone->uz_name, zone, bucket);
if (bucket) {
critical_enter();
cpu = curcpu;
@ -3138,9 +3095,7 @@ static void
uma_reclaim_locked(bool kmem_danger)
{
#ifdef UMA_DEBUG
printf("UMA: vm asked us to release pages!\n");
#endif
CTR0(KTR_UMA, "UMA: vm asked us to release pages!");
sx_assert(&uma_drain_lock, SA_XLOCKED);
bucket_enable();
zone_foreach(zone_drain);