summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2014-08-29 13:12:45 +0000
committerdelphij <delphij@FreeBSD.org>2014-08-29 13:12:45 +0000
commit3074ca39fd4dbe79a2014157d1707c850f5a3460 (patch)
tree20e0de4d396de0bf40d2ca895fa0cb6d8c5e05e0 /sys/kern
parent2a1fdab727ae3c39437949887e76e37667b3f012 (diff)
downloadFreeBSD-src-3074ca39fd4dbe79a2014157d1707c850f5a3460.zip
FreeBSD-src-3074ca39fd4dbe79a2014157d1707c850f5a3460.tar.gz
MFC r269963+269964:
Re-instate UMA cached backend for 4K - 64K allocations. New consumers like geli(4) uses malloc(9) to allocate temporary buffers that gets free'ed shortly, causing frequent TLB shootdown as observed in hwpmc supported flame graph. Add a new loader tunable, vm.kmem_zmax which allows a system administrator to limit the maximum allocation size that malloc(9) would consider using the UMA cache allocator as backend.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_malloc.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index a5d25ea..5c46a55 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -121,7 +121,7 @@ static int kmemcount;
#define KMEM_ZBASE 16
#define KMEM_ZMASK (KMEM_ZBASE - 1)
-#define KMEM_ZMAX PAGE_SIZE
+#define KMEM_ZMAX 65536
#define KMEM_ZSIZE (KMEM_ZMAX >> KMEM_ZSHIFT)
static uint8_t kmemsize[KMEM_ZSIZE + 1];
@@ -152,21 +152,10 @@ struct {
{1024, "1024", },
{2048, "2048", },
{4096, "4096", },
-#if PAGE_SIZE > 4096
{8192, "8192", },
-#if PAGE_SIZE > 8192
{16384, "16384", },
-#if PAGE_SIZE > 16384
{32768, "32768", },
-#if PAGE_SIZE > 32768
{65536, "65536", },
-#if PAGE_SIZE > 65536
-#error "Unsupported PAGE_SIZE"
-#endif /* 65536 */
-#endif /* 32768 */
-#endif /* 16384 */
-#endif /* 8192 */
-#endif /* 4096 */
{0, NULL},
};
@@ -184,6 +173,10 @@ u_long vm_kmem_size;
SYSCTL_ULONG(_vm, OID_AUTO, kmem_size, CTLFLAG_RDTUN, &vm_kmem_size, 0,
"Size of kernel memory");
+static u_long kmem_zmax = KMEM_ZMAX;
+SYSCTL_ULONG(_vm, OID_AUTO, kmem_zmax, CTLFLAG_RDTUN, &kmem_zmax, 0,
+ "Maximum allocation size that malloc(9) would use UMA as backend");
+
static u_long vm_kmem_size_min;
SYSCTL_ULONG(_vm, OID_AUTO, kmem_size_min, CTLFLAG_RDTUN, &vm_kmem_size_min, 0,
"Minimum size of kernel memory");
@@ -498,7 +491,7 @@ malloc(unsigned long size, struct malloc_type *mtp, int flags)
size = redzone_size_ntor(size);
#endif
- if (size <= KMEM_ZMAX) {
+ if (size <= kmem_zmax) {
mtip = mtp->ks_handle;
if (size & KMEM_ZMASK)
size = (size & ~KMEM_ZMASK) + KMEM_ZBASE;
@@ -783,6 +776,9 @@ mallocinit(void *dummy)
uma_startup2();
+ if (kmem_zmax < PAGE_SIZE || kmem_zmax > KMEM_ZMAX)
+ kmem_zmax = KMEM_ZMAX;
+
mt_zone = uma_zcreate("mt_zone", sizeof(struct malloc_type_internal),
#ifdef INVARIANTS
mtrash_ctor, mtrash_dtor, mtrash_init, mtrash_fini,
@@ -807,7 +803,7 @@ mallocinit(void *dummy)
}
for (;i <= size; i+= KMEM_ZBASE)
kmemsize[i >> KMEM_ZSHIFT] = indx;
-
+
}
}
SYSINIT(kmem, SI_SUB_KMEM, SI_ORDER_FIRST, mallocinit, NULL);
OpenPOWER on IntegriCloud