1/*
2 * Copyright (c) 2002, Jeffrey Roberson <jroberson@chesapeake.net>
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 92654 2002-03-19 09:11:49Z jeff $
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
--- 559 unchanged lines hidden (view full) ---
594 uma_slab_t slab; /* Starting slab */
595 u_int8_t *mem;
596 u_int8_t flags;
597 int i;
598
599#ifdef UMA_DEBUG
600 printf("slab_zalloc: Allocating a new slab for %s\n", zone->uz_name);
601#endif
602
603 if (booted || (zone->uz_flags & UMA_ZFLAG_PRIVALLOC)) {
604 ZONE_UNLOCK(zone);
605 mtx_lock(&Giant);
606 slab = (uma_slab_t )zone->uz_allocf(zone,
607 zone->uz_ppera * UMA_SLAB_SIZE, &flags, wait);
608 mtx_unlock(&Giant);
609 ZONE_LOCK(zone);
--- 119 unchanged lines hidden (view full) ---
729static void *
730obj_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
731{
732 vm_offset_t zkva;
733 vm_offset_t retkva;
734 vm_page_t p;
735 int pages;
736
737
738 if (zone->uz_pages + zone->uz_ppera > zone->uz_maxpages)
739 return (NULL);
740
741 retkva = NULL;
742 pages = zone->uz_pages;
743
744 /*
745 * This looks a little weird since we're getting one page at a time
746 */
747 while (bytes > 0) {
748 p = vm_page_alloc(zone->uz_obj, pages,
--- 488 unchanged lines hidden (view full) ---
1237
1238 if (item && isitem == 0)
1239 goto zalloc_start;
1240
1241 /*
1242 * If isitem is set then we should just return it. The cpu lock
1243 * was unlocked when we couldn't get a bucket.
1244 */
1245
1246#ifdef INVARIANTS
1247 if (wait == M_WAITOK)
1248 KASSERT(item != NULL,
1249 ("uma_zalloc: WAITOK set but we're returning NULL"));
1250#endif
1251 return item;
1252}
1253
1254/*
1255 * Allocates an item for an internal zone OR fills a bucket
1256 *
1257 * Arguments
1258 * zone The zone to alloc for.
--- 414 unchanged lines hidden (view full) ---
1673 ZONE_UNLOCK(zone);
1674
1675 if (!skip && zone->uz_dtor)
1676 zone->uz_dtor(item, zone->uz_size, udata);
1677}
1678
1679/* See uma.h */
1680void
1681uma_zone_set_freef(uma_zone_t zone, uma_free freef)
1682{
1683 ZONE_LOCK(zone);
1684
1685 zone->uz_freef = freef;
1686
1687 ZONE_UNLOCK(zone);
1688}
--- 212 unchanged lines hidden ---
2 * Copyright (c) 2002, Jeffrey Roberson <jroberson@chesapeake.net>
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 92654 2002-03-19 09:11:49Z jeff $
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
--- 559 unchanged lines hidden (view full) ---
594 uma_slab_t slab; /* Starting slab */
595 u_int8_t *mem;
596 u_int8_t flags;
597 int i;
598
599#ifdef UMA_DEBUG
600 printf("slab_zalloc: Allocating a new slab for %s\n", zone->uz_name);
601#endif
602
603 if (booted || (zone->uz_flags & UMA_ZFLAG_PRIVALLOC)) {
604 ZONE_UNLOCK(zone);
605 mtx_lock(&Giant);
606 slab = (uma_slab_t )zone->uz_allocf(zone,
607 zone->uz_ppera * UMA_SLAB_SIZE, &flags, wait);
608 mtx_unlock(&Giant);
609 ZONE_LOCK(zone);
--- 119 unchanged lines hidden (view full) ---
729static void *
730obj_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
731{
732 vm_offset_t zkva;
733 vm_offset_t retkva;
734 vm_page_t p;
735 int pages;
736
737
738 if (zone->uz_pages + zone->uz_ppera > zone->uz_maxpages)
739 return (NULL);
740
741 retkva = NULL;
742 pages = zone->uz_pages;
743
744 /*
745 * This looks a little weird since we're getting one page at a time
746 */
747 while (bytes > 0) {
748 p = vm_page_alloc(zone->uz_obj, pages,
--- 488 unchanged lines hidden (view full) ---
1237
1238 if (item && isitem == 0)
1239 goto zalloc_start;
1240
1241 /*
1242 * If isitem is set then we should just return it. The cpu lock
1243 * was unlocked when we couldn't get a bucket.
1244 */
1245
1246#ifdef INVARIANTS
1247 if (wait == M_WAITOK)
1248 KASSERT(item != NULL,
1249 ("uma_zalloc: WAITOK set but we're returning NULL"));
1250#endif
1251 return item;
1252}
1253
1254/*
1255 * Allocates an item for an internal zone OR fills a bucket
1256 *
1257 * Arguments
1258 * zone The zone to alloc for.
--- 414 unchanged lines hidden (view full) ---
1673 ZONE_UNLOCK(zone);
1674
1675 if (!skip && zone->uz_dtor)
1676 zone->uz_dtor(item, zone->uz_size, udata);
1677}
1678
1679/* See uma.h */
1680void
1681uma_zone_set_freef(uma_zone_t zone, uma_free freef)
1682{
1683 ZONE_LOCK(zone);
1684
1685 zone->uz_freef = freef;
1686
1687 ZONE_UNLOCK(zone);
1688}
--- 212 unchanged lines hidden ---