uma_core.c (109548) | uma_core.c (109623) |
---|---|
1/* 2 * Copyright (c) 2002, Jeffrey Roberson <jeff@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * | 1/* 2 * Copyright (c) 2002, Jeffrey Roberson <jeff@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/vm/uma_core.c 109548 2003-01-20 01:32:56Z jeff $ | 26 * $FreeBSD: head/sys/vm/uma_core.c 109623 2003-01-21 08:56:16Z alfred $ |
27 * 28 */ 29 30/* 31 * uma_core.c Implementation of the Universal Memory allocator 32 * 33 * This allocator is intended to replace the multitude of similar object caches 34 * in the standard FreeBSD kernel. The intent is to be flexible as well as --- 314 unchanged lines hidden (view full) --- 349 hash->uh_hashsize = oldsize * 2; 350 alloc = sizeof(hash->uh_slab_hash[0]) * hash->uh_hashsize; 351 /* XXX Shouldn't be abusing DEVBUF here */ 352 hash->uh_slab_hash = (struct slabhead *)malloc(alloc, 353 M_DEVBUF, M_NOWAIT); 354 } else { 355 alloc = sizeof(hash->uh_slab_hash[0]) * UMA_HASH_SIZE_INIT; 356 hash->uh_slab_hash = uma_zalloc_internal(hashzone, NULL, | 27 * 28 */ 29 30/* 31 * uma_core.c Implementation of the Universal Memory allocator 32 * 33 * This allocator is intended to replace the multitude of similar object caches 34 * in the standard FreeBSD kernel. The intent is to be flexible as well as --- 314 unchanged lines hidden (view full) --- 349 hash->uh_hashsize = oldsize * 2; 350 alloc = sizeof(hash->uh_slab_hash[0]) * hash->uh_hashsize; 351 /* XXX Shouldn't be abusing DEVBUF here */ 352 hash->uh_slab_hash = (struct slabhead *)malloc(alloc, 353 M_DEVBUF, M_NOWAIT); 354 } else { 355 alloc = sizeof(hash->uh_slab_hash[0]) * UMA_HASH_SIZE_INIT; 356 hash->uh_slab_hash = uma_zalloc_internal(hashzone, NULL, |
357 M_WAITOK); | 357 0); |
358 hash->uh_hashsize = UMA_HASH_SIZE_INIT; 359 } 360 if (hash->uh_slab_hash) { 361 bzero(hash->uh_slab_hash, alloc); 362 hash->uh_hashmask = hash->uh_hashsize - 1; 363 return (1); 364 } 365 --- 929 unchanged lines hidden (view full) --- 1295 args.size = size; 1296 args.ctor = ctor; 1297 args.dtor = dtor; 1298 args.uminit = uminit; 1299 args.fini = fini; 1300 args.align = align; 1301 args.flags = flags; 1302 | 358 hash->uh_hashsize = UMA_HASH_SIZE_INIT; 359 } 360 if (hash->uh_slab_hash) { 361 bzero(hash->uh_slab_hash, alloc); 362 hash->uh_hashmask = hash->uh_hashsize - 1; 363 return (1); 364 } 365 --- 929 unchanged lines hidden (view full) --- 1295 args.size = size; 1296 args.ctor = ctor; 1297 args.dtor = dtor; 1298 args.uminit = uminit; 1299 args.fini = fini; 1300 args.align = align; 1301 args.flags = flags; 1302 |
1303 return (uma_zalloc_internal(zones, &args, M_WAITOK)); | 1303 return (uma_zalloc_internal(zones, &args, 0)); |
1304} 1305 1306/* See uma.h */ 1307void 1308uma_zdestroy(uma_zone_t zone) 1309{ 1310 uma_zfree_internal(zones, zone, NULL, 0); 1311} --- 9 unchanged lines hidden (view full) --- 1321 1322 /* This is the fast path allocation */ 1323#ifdef UMA_DEBUG_ALLOC_1 1324 printf("Allocating one item from %s(%p)\n", zone->uz_name, zone); 1325#endif 1326 1327 if (!(flags & M_NOWAIT)) { 1328 KASSERT(curthread->td_intr_nesting_level == 0, | 1304} 1305 1306/* See uma.h */ 1307void 1308uma_zdestroy(uma_zone_t zone) 1309{ 1310 uma_zfree_internal(zones, zone, NULL, 0); 1311} --- 9 unchanged lines hidden (view full) --- 1321 1322 /* This is the fast path allocation */ 1323#ifdef UMA_DEBUG_ALLOC_1 1324 printf("Allocating one item from %s(%p)\n", zone->uz_name, zone); 1325#endif 1326 1327 if (!(flags & M_NOWAIT)) { 1328 KASSERT(curthread->td_intr_nesting_level == 0, |
1329 ("malloc(M_WAITOK) in interrupt context")); | 1329 ("malloc without M_NOWAIT in interrupt context")); |
1330 WITNESS_SLEEP(1, NULL); 1331 } 1332 1333zalloc_restart: 1334 cpu = PCPU_GET(cpuid); 1335 CPU_LOCK(zone, cpu); 1336 cache = &zone->uz_cpu[cpu]; 1337 --- 266 unchanged lines hidden (view full) --- 1604 return (0); 1605} 1606/* 1607 * Allocates an item for an internal zone 1608 * 1609 * Arguments 1610 * zone The zone to alloc for. 1611 * udata The data to be passed to the constructor. | 1330 WITNESS_SLEEP(1, NULL); 1331 } 1332 1333zalloc_restart: 1334 cpu = PCPU_GET(cpuid); 1335 CPU_LOCK(zone, cpu); 1336 cache = &zone->uz_cpu[cpu]; 1337 --- 266 unchanged lines hidden (view full) --- 1604 return (0); 1605} 1606/* 1607 * Allocates an item for an internal zone 1608 * 1609 * Arguments 1610 * zone The zone to alloc for. 1611 * udata The data to be passed to the constructor. |
1612 * flags M_WAITOK, M_NOWAIT, M_ZERO. | 1612 * flags M_NOWAIT, M_ZERO. |
1613 * 1614 * Returns 1615 * NULL if there is no memory and M_NOWAIT is set 1616 * An item if successful 1617 */ 1618 1619static void * 1620uma_zalloc_internal(uma_zone_t zone, void *udata, int flags) --- 338 unchanged lines hidden (view full) --- 1959 uma_slab_t slab; 1960 1961 ZONE_LOCK(zone); 1962 slabs = items / zone->uz_ipers; 1963 if (slabs * zone->uz_ipers < items) 1964 slabs++; 1965 1966 while (slabs > 0) { | 1613 * 1614 * Returns 1615 * NULL if there is no memory and M_NOWAIT is set 1616 * An item if successful 1617 */ 1618 1619static void * 1620uma_zalloc_internal(uma_zone_t zone, void *udata, int flags) --- 338 unchanged lines hidden (view full) --- 1959 uma_slab_t slab; 1960 1961 ZONE_LOCK(zone); 1962 slabs = items / zone->uz_ipers; 1963 if (slabs * zone->uz_ipers < items) 1964 slabs++; 1965 1966 while (slabs > 0) { |
1967 slab = slab_zalloc(zone, M_WAITOK); | 1967 slab = slab_zalloc(zone, 0); |
1968 LIST_INSERT_HEAD(&zone->uz_free_slab, slab, us_link); 1969 slabs--; 1970 } 1971 ZONE_UNLOCK(zone); 1972} 1973 1974/* See uma.h */ 1975void --- 93 unchanged lines hidden (view full) --- 2069 char *p; 2070 2071 cnt = 0; 2072 mtx_lock(&uma_mtx); 2073 LIST_FOREACH(z, &uma_zones, uz_link) 2074 cnt++; 2075 mtx_unlock(&uma_mtx); 2076 MALLOC(tmpbuf, char *, (cnt == 0 ? 1 : cnt) * linesize, | 1968 LIST_INSERT_HEAD(&zone->uz_free_slab, slab, us_link); 1969 slabs--; 1970 } 1971 ZONE_UNLOCK(zone); 1972} 1973 1974/* See uma.h */ 1975void --- 93 unchanged lines hidden (view full) --- 2069 char *p; 2070 2071 cnt = 0; 2072 mtx_lock(&uma_mtx); 2073 LIST_FOREACH(z, &uma_zones, uz_link) 2074 cnt++; 2075 mtx_unlock(&uma_mtx); 2076 MALLOC(tmpbuf, char *, (cnt == 0 ? 1 : cnt) * linesize, |
2077 M_TEMP, M_WAITOK); | 2077 M_TEMP, 0); |
2078 len = snprintf(tmpbuf, linesize, 2079 "\nITEM SIZE LIMIT USED FREE REQUESTS\n\n"); 2080 if (cnt == 0) 2081 tmpbuf[len - 1] = '\0'; 2082 error = SYSCTL_OUT(req, tmpbuf, cnt == 0 ? len-1 : len); 2083 if (error || cnt == 0) 2084 goto out; 2085 offset = tmpbuf; --- 27 unchanged lines hidden --- | 2078 len = snprintf(tmpbuf, linesize, 2079 "\nITEM SIZE LIMIT USED FREE REQUESTS\n\n"); 2080 if (cnt == 0) 2081 tmpbuf[len - 1] = '\0'; 2082 error = SYSCTL_OUT(req, tmpbuf, cnt == 0 ? len-1 : len); 2083 if (error || cnt == 0) 2084 goto out; 2085 offset = tmpbuf; --- 27 unchanged lines hidden --- |