Changeset View
Changeset View
Standalone View
Standalone View
sys/vm/uma_core.c
Show First 20 Lines • Show All 3,010 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
zone_dtor(void *arg, int size, void *udata) | zone_dtor(void *arg, int size, void *udata) | ||||
{ | { | ||||
uma_zone_t zone; | uma_zone_t zone; | ||||
uma_keg_t keg; | uma_keg_t keg; | ||||
int i; | int i; | ||||
zone = (uma_zone_t)arg; | zone = (uma_zone_t)arg; | ||||
keg = NULL; | |||||
sysctl_remove_oid(zone->uz_oid, 1, 1); | sysctl_remove_oid(zone->uz_oid, 1, 1); | ||||
if (!(zone->uz_flags & UMA_ZFLAG_INTERNAL)) | if (!(zone->uz_flags & UMA_ZFLAG_INTERNAL)) | ||||
cache_drain(zone); | cache_drain(zone); | ||||
rw_wlock(&uma_rwlock); | rw_wlock(&uma_rwlock); | ||||
LIST_REMOVE(zone, uz_link); | LIST_REMOVE(zone, uz_link); | ||||
rw_wunlock(&uma_rwlock); | rw_wunlock(&uma_rwlock); | ||||
if ((zone->uz_flags & (UMA_ZONE_SECONDARY | UMA_ZFLAG_CACHE)) == 0) { | if ((zone->uz_flags & (UMA_ZONE_SECONDARY | UMA_ZFLAG_CACHE)) == 0) { | ||||
keg = zone->uz_keg; | keg = zone->uz_keg; | ||||
keg->uk_reserve = 0; | keg->uk_reserve = 0; | ||||
} | } | ||||
if (keg != NULL && (zone->uz_flags & (UMA_ZONE_NOFREE | | |||||
UMA_ZONE_ALLFINI)) == (UMA_ZONE_NOFREE | UMA_ZONE_ALLFINI)) | |||||
keg->uk_flags &= ~UMA_ZONE_NOFREE; | |||||
zone_reclaim(zone, UMA_ANYDOMAIN, M_WAITOK, true); | zone_reclaim(zone, UMA_ANYDOMAIN, M_WAITOK, true); | ||||
/* | /* | ||||
* We only destroy kegs from non secondary/non cache zones. | * We only destroy kegs from non secondary/non cache zones. | ||||
*/ | */ | ||||
if ((zone->uz_flags & (UMA_ZONE_SECONDARY | UMA_ZFLAG_CACHE)) == 0) { | if ((zone->uz_flags & (UMA_ZONE_SECONDARY | UMA_ZFLAG_CACHE)) == 0) { | ||||
keg = zone->uz_keg; | keg = zone->uz_keg; | ||||
rw_wlock(&uma_rwlock); | rw_wlock(&uma_rwlock); | ||||
▲ Show 20 Lines • Show All 2,807 Lines • ▼ Show 20 Lines | db_printf("%18s %8ju %8jd %8ld %12ju %8u\n", | ||||
z->uz_name, (uintmax_t)z->uz_size, | z->uz_name, (uintmax_t)z->uz_size, | ||||
(intmax_t)(allocs - frees), cachefree, | (intmax_t)(allocs - frees), cachefree, | ||||
(uintmax_t)allocs, z->uz_bucket_size); | (uintmax_t)allocs, z->uz_bucket_size); | ||||
if (db_pager_quit) | if (db_pager_quit) | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
#endif /* DDB */ | #endif /* DDB */ | ||||
static int | |||||
zz_init(void *mem, int size, int flags) | |||||
{ | |||||
printf("zz_init: %p %d %#x\n", mem, size, flags); | |||||
return (0); | |||||
} | |||||
static void | |||||
zz_fini(void *mem, int size) | |||||
{ | |||||
printf("zz_fini: %p %d\n", mem, size); | |||||
} | |||||
static void | |||||
test_allfini(void) | |||||
{ | |||||
uma_zone_t zz; | |||||
uint64_t *a[8]; | |||||
printf("creating ZZ\n"); | |||||
zz = uma_zcreate("ZZ", sizeof(uint64_t), NULL, NULL, | |||||
zz_init, zz_fini, sizeof(uint64_t) - 1, | |||||
UMA_ZONE_NOFREE | UMA_ZONE_ALLFINI); | |||||
printf("allocating\n"); | |||||
for (int i = 0; i < nitems(a); i++) { | |||||
a[i] = uma_zalloc(zz, M_WAITOK); | |||||
MPASS(a[i] != NULL); | |||||
} | |||||
printf("freeing\n"); | |||||
for (int i = 0; i < nitems(a); i++) | |||||
uma_zfree(zz, a[i]); | |||||
printf("allocating\n"); | |||||
for (int i = 0; i < nitems(a); i++) | |||||
a[i] = uma_zalloc(zz, M_WAITOK); | |||||
#if 0 | |||||
printf("allocating\n"); | |||||
for (int i = 0; i < nitems(a); i++) | |||||
a[i] = uma_zalloc(zz, M_WAITOK); | |||||
#endif | |||||
for (int i = 0; i < nitems(a); i++) | |||||
uma_zfree(zz, a[i]); | |||||
printf("destroying ZZ\n"); | |||||
uma_zdestroy(zz); | |||||
} | |||||
static int | |||||
sysctl_test_allfini(SYSCTL_HANDLER_ARGS) | |||||
{ | |||||
int error, val; | |||||
val = 0; | |||||
error = sysctl_handle_int(oidp, &val, 0, req); | |||||
if (error != 0 || req->newptr == NULL) | |||||
return (error); | |||||
if (val != 0) { | |||||
test_allfini(); | |||||
} | |||||
return (0); | |||||
} | |||||
SYSCTL_PROC(_debug, OID_AUTO, test_allfini, CTLTYPE_INT | CTLFLAG_RW | | |||||
CTLFLAG_MPSAFE, NULL, 0, | |||||
sysctl_test_allfini, "I", | |||||
""); |