uma_core.c (95432) | uma_core.c (95758) |
---|---|
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 * | 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 95432 2002-04-25 06:24:40Z arr $ | 26 * $FreeBSD: head/sys/vm/uma_core.c 95758 2002-04-29 23:45:41Z 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 --- 919 unchanged lines hidden (view full) --- 954 * 955 */ 956 957static void 958zone_ctor(void *mem, int size, void *udata) 959{ 960 struct uma_zctor_args *arg = udata; 961 uma_zone_t zone = mem; | 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 --- 919 unchanged lines hidden (view full) --- 954 * 955 */ 956 957static void 958zone_ctor(void *mem, int size, void *udata) 959{ 960 struct uma_zctor_args *arg = udata; 961 uma_zone_t zone = mem; |
962 int privlc; |
|
962 int cplen; 963 int cpu; 964 965 bzero(zone, size); 966 zone->uz_name = arg->name; 967 zone->uz_size = arg->size; 968 zone->uz_ctor = arg->ctor; 969 zone->uz_dtor = arg->dtor; --- 17 unchanged lines hidden (view full) --- 987 if (arg->flags & UMA_ZONE_NOFREE) 988 zone->uz_flags |= UMA_ZFLAG_NOFREE; 989 990 if (zone->uz_size > UMA_SLAB_SIZE) 991 zone_large_init(zone); 992 else 993 zone_small_init(zone); 994 | 963 int cplen; 964 int cpu; 965 966 bzero(zone, size); 967 zone->uz_name = arg->name; 968 zone->uz_size = arg->size; 969 zone->uz_ctor = arg->ctor; 970 zone->uz_dtor = arg->dtor; --- 17 unchanged lines hidden (view full) --- 988 if (arg->flags & UMA_ZONE_NOFREE) 989 zone->uz_flags |= UMA_ZFLAG_NOFREE; 990 991 if (zone->uz_size > UMA_SLAB_SIZE) 992 zone_large_init(zone); 993 else 994 zone_small_init(zone); 995 |
996 if (arg->flags & UMA_ZONE_MTXCLASS) 997 privlc = 1; 998 else 999 privlc = 0; 1000 |
|
995 /* We do this so that the per cpu lock name is unique for each zone */ 996 memcpy(zone->uz_lname, "PCPU ", 5); 997 cplen = min(strlen(zone->uz_name) + 1, LOCKNAME_LEN - 6); 998 memcpy(zone->uz_lname+5, zone->uz_name, cplen); 999 zone->uz_lname[LOCKNAME_LEN - 1] = '\0'; 1000 1001 /* 1002 * If we're putting the slab header in the actual page we need to --- 45 unchanged lines hidden (view full) --- 1048 } 1049 1050#ifdef UMA_DEBUG 1051 printf("%s(%p) size = %d ipers = %d ppera = %d pgoff = %d\n", 1052 zone->uz_name, zone, 1053 zone->uz_size, zone->uz_ipers, 1054 zone->uz_ppera, zone->uz_pgoff); 1055#endif | 1001 /* We do this so that the per cpu lock name is unique for each zone */ 1002 memcpy(zone->uz_lname, "PCPU ", 5); 1003 cplen = min(strlen(zone->uz_name) + 1, LOCKNAME_LEN - 6); 1004 memcpy(zone->uz_lname+5, zone->uz_name, cplen); 1005 zone->uz_lname[LOCKNAME_LEN - 1] = '\0'; 1006 1007 /* 1008 * If we're putting the slab header in the actual page we need to --- 45 unchanged lines hidden (view full) --- 1054 } 1055 1056#ifdef UMA_DEBUG 1057 printf("%s(%p) size = %d ipers = %d ppera = %d pgoff = %d\n", 1058 zone->uz_name, zone, 1059 zone->uz_size, zone->uz_ipers, 1060 zone->uz_ppera, zone->uz_pgoff); 1061#endif |
1056 ZONE_LOCK_INIT(zone); | 1062 ZONE_LOCK_INIT(zone, privlc); |
1057 1058 mtx_lock(&uma_mtx); 1059 LIST_INSERT_HEAD(&uma_zones, zone, uz_link); 1060 mtx_unlock(&uma_mtx); 1061 1062 /* 1063 * Some internal zones don't have room allocated for the per cpu 1064 * caches. If we're internal, bail out here. 1065 */ 1066 1067 if (zone->uz_flags & UMA_ZFLAG_INTERNAL) 1068 return; 1069 1070 if (zone->uz_ipers < UMA_BUCKET_SIZE) 1071 zone->uz_count = zone->uz_ipers - 1; 1072 else 1073 zone->uz_count = UMA_BUCKET_SIZE - 1; 1074 1075 for (cpu = 0; cpu < maxcpu; cpu++) | 1063 1064 mtx_lock(&uma_mtx); 1065 LIST_INSERT_HEAD(&uma_zones, zone, uz_link); 1066 mtx_unlock(&uma_mtx); 1067 1068 /* 1069 * Some internal zones don't have room allocated for the per cpu 1070 * caches. If we're internal, bail out here. 1071 */ 1072 1073 if (zone->uz_flags & UMA_ZFLAG_INTERNAL) 1074 return; 1075 1076 if (zone->uz_ipers < UMA_BUCKET_SIZE) 1077 zone->uz_count = zone->uz_ipers - 1; 1078 else 1079 zone->uz_count = UMA_BUCKET_SIZE - 1; 1080 1081 for (cpu = 0; cpu < maxcpu; cpu++) |
1076 CPU_LOCK_INIT(zone, cpu); | 1082 CPU_LOCK_INIT(zone, cpu, privlc); |
1077} 1078 1079/* 1080 * Zone header dtor. This frees all data, destroys locks, frees the hash table 1081 * and removes the zone from the global list. 1082 * 1083 * Arguments/Returns follow uma_dtor specifications 1084 * udata unused --- 709 unchanged lines hidden (view full) --- 1794 1795/* See uma.h */ 1796void 1797uma_zone_set_max(uma_zone_t zone, int nitems) 1798{ 1799 ZONE_LOCK(zone); 1800 if (zone->uz_ppera > 1) 1801 zone->uz_maxpages = nitems * zone->uz_ppera; | 1083} 1084 1085/* 1086 * Zone header dtor. This frees all data, destroys locks, frees the hash table 1087 * and removes the zone from the global list. 1088 * 1089 * Arguments/Returns follow uma_dtor specifications 1090 * udata unused --- 709 unchanged lines hidden (view full) --- 1800 1801/* See uma.h */ 1802void 1803uma_zone_set_max(uma_zone_t zone, int nitems) 1804{ 1805 ZONE_LOCK(zone); 1806 if (zone->uz_ppera > 1) 1807 zone->uz_maxpages = nitems * zone->uz_ppera; |
1802 else | 1808 else |
1803 zone->uz_maxpages = nitems / zone->uz_ipers; | 1809 zone->uz_maxpages = nitems / zone->uz_ipers; |
1810 |
|
1804 if (zone->uz_maxpages * zone->uz_ipers < nitems) 1805 zone->uz_maxpages++; | 1811 if (zone->uz_maxpages * zone->uz_ipers < nitems) 1812 zone->uz_maxpages++; |
1813 |
|
1806 ZONE_UNLOCK(zone); 1807} 1808 1809/* See uma.h */ 1810void 1811uma_zone_set_freef(uma_zone_t zone, uma_free freef) 1812{ 1813 ZONE_LOCK(zone); --- 220 unchanged lines hidden --- | 1814 ZONE_UNLOCK(zone); 1815} 1816 1817/* See uma.h */ 1818void 1819uma_zone_set_freef(uma_zone_t zone, uma_free freef) 1820{ 1821 ZONE_LOCK(zone); --- 220 unchanged lines hidden --- |