svn commit: r270811 - stable/10/sys/kern
Xin LI
delphij at FreeBSD.org
Fri Aug 29 13:12:46 UTC 2014
Author: delphij
Date: Fri Aug 29 13:12:45 2014
New Revision: 270811
URL: http://svnweb.freebsd.org/changeset/base/270811
Log:
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.
Modified:
stable/10/sys/kern/kern_malloc.c
Directory Properties:
stable/10/ (props changed)
Modified: stable/10/sys/kern/kern_malloc.c
==============================================================================
--- stable/10/sys/kern/kern_malloc.c Fri Aug 29 13:06:30 2014 (r270810)
+++ stable/10/sys/kern/kern_malloc.c Fri Aug 29 13:12:45 2014 (r270811)
@@ -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
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);
More information about the svn-src-stable
mailing list