2058 libumem should allow you to specify an allocator
authorRobert Mustacchi <rm@joyent.com>
Tue, 29 May 2012 18:11:49 -0700
changeset 13708 6d0517b1a52b
parent 13707 3f41b24ce657
child 13709 1f68af63b8d9
2058 libumem should allow you to specify an allocator Reviewed by: Jerry Jelinek <[email protected]> Reviewed by: Bryan Cantrill <[email protected]> Reviewed by: Richard Lowe <[email protected]> Reviewed by: Garrett D'Amore <[email protected]> Approved by: Eric Schrock <[email protected]>
usr/src/lib/libumem/common/envvar.c
usr/src/lib/libumem/common/vmem.c
usr/src/lib/libumem/common/vmem_base.c
usr/src/lib/libumem/common/vmem_base.h
usr/src/man/man3malloc/umem_alloc.3malloc
--- a/usr/src/lib/libumem/common/envvar.c	Tue May 29 13:58:04 2012 -0700
+++ b/usr/src/lib/libumem/common/envvar.c	Tue May 29 18:11:49 2012 -0700
@@ -22,10 +22,9 @@
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ * Copyright 2012 Joyent, Inc. All rights reserved.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
@@ -84,6 +83,7 @@
 
 #ifndef UMEM_STANDALONE
 static arg_process_t umem_backend_process;
+static arg_process_t umem_allocator_process;
 #endif
 
 static arg_process_t umem_log_process;
@@ -100,6 +100,11 @@
 		NULL, 0, NULL, NULL,
 		&umem_backend_process
 	},
+	{ "allocator",		"Evolving",	ITEM_SPECIAL,
+		"=best, =first, =next, or =instant",
+		NULL, 0, NULL, NULL,
+		&umem_allocator_process
+	},
 #endif
 
 	{ "concurrency",	"Private",	ITEM_UINT,
@@ -473,6 +478,35 @@
 	    CURRENT, name, name, name);
 	return (ARG_BAD);
 }
+
+
+static int
+umem_allocator_process(const umem_env_item_t *item, const char *item_arg)
+{
+	const char *name = item->item_name;
+
+	if (item_arg == NULL)
+		goto fail;
+
+	if (strcmp(item_arg, "best") == 0)
+		vmem_allocator = VM_BESTFIT;
+	else if (strcmp(item_arg, "next") == 0)
+		vmem_allocator = VM_NEXTFIT;
+	else if (strcmp(item_arg, "first") == 0)
+		vmem_allocator = VM_FIRSTFIT;
+	else if (strcmp(item_arg, "instant") == 0)
+		vmem_allocator = 0;
+	else
+		goto fail;
+
+	return (ARG_SUCCESS);
+
+fail:
+	log_message("%s: %s: must be %s=best, %s=next or %s=first\n",
+	    CURRENT, name, name, name, name);
+	return (ARG_BAD);
+
+}
 #endif
 
 static int
--- a/usr/src/lib/libumem/common/vmem.c	Tue May 29 13:58:04 2012 -0700
+++ b/usr/src/lib/libumem/common/vmem.c	Tue May 29 18:11:49 2012 -0700
@@ -22,6 +22,7 @@
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ * Copyright 2012 Joyent, Inc. All rights reserved.
  */
 
 /*
@@ -1069,6 +1070,7 @@
 	int hb;
 	int flist = 0;
 	uint32_t mtbf;
+	vmflag |= vmem_allocator;
 
 	if (size - 1 < vmp->vm_qcache_max) {
 		ASSERT(vmflag & VM_NOSLEEP);
--- a/usr/src/lib/libumem/common/vmem_base.c	Tue May 29 13:58:04 2012 -0700
+++ b/usr/src/lib/libumem/common/vmem_base.c	Tue May 29 18:11:49 2012 -0700
@@ -22,14 +22,14 @@
 /*
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ * Copyright 2012 Joyent, Inc. All rights reserved.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include "vmem_base.h"
 #include "umem_base.h"
 
 uint_t vmem_backend = 0;
+uint_t vmem_allocator = 0;
 
 vmem_t *
 vmem_heap_arena(vmem_alloc_t **allocp, vmem_free_t **freep)
--- a/usr/src/lib/libumem/common/vmem_base.h	Tue May 29 13:58:04 2012 -0700
+++ b/usr/src/lib/libumem/common/vmem_base.h	Tue May 29 18:11:49 2012 -0700
@@ -21,13 +21,12 @@
 /*
  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ * Copyright 2012 Joyent, Inc. All rights reserved.
  */
 
 #ifndef	_VMEM_BASE_H
 #define	_VMEM_BASE_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #include <sys/vmem.h>
 #include <umem.h>
 
@@ -66,6 +65,8 @@
 #define	VMEM_BACKEND_MMAP	0x0000002
 #define	VMEM_BACKEND_STAND	0x0000003
 
+extern uint_t vmem_allocator;
+
 extern vmem_t *vmem_heap;
 extern vmem_alloc_t *vmem_heap_alloc;
 extern vmem_free_t *vmem_heap_free;
--- a/usr/src/man/man3malloc/umem_alloc.3malloc	Tue May 29 13:58:04 2012 -0700
+++ b/usr/src/man/man3malloc/umem_alloc.3malloc	Tue May 29 18:11:49 2012 -0700
@@ -1,5 +1,6 @@
 '\" te
 .\" Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
+.\" Copyright (c) 2012 Joyent, Inc. All Rights Reserved.
 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
@@ -174,6 +175,31 @@
 will be used.
 .RE
 
+.ne 2
+.na
+\fB\fBallocator\fR=\fBbest\fR\fR
+.ad
+.br
+.na
+\fB\fBallocator\fR=\fBfirst\fR\fR
+.ad
+.br
+.na
+\fB\fBallocator\fR=\fBinstant\fR\fR
+.ad
+.br
+.na
+\fB\fBallocator\fR=\fBnext\fR\fR
+.ad
+.RS 16n
+Set the underlying allocation strategy. The \fBbest\fR fit strategy tells
+libumem to use the smallest free segment possible. The \fBinstant\fR fit
+strategy approximates the best fit strategy in constant cpu time. The
+\fBfirst\fR fit strategy takes the first free segment that can honor the
+allocation. The \fBnext\fR fit strategy uses the next free segment after the
+previously allocated one.
+.RE
+
 .RE
 
 .SH EXAMPLES