summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>2002-02-12 17:19:42 +0000
committerNiels Provos <provos@cvs.openbsd.org>2002-02-12 17:19:42 +0000
commitfb7c991390bd4887cc4985a05f6444fd2a116df4 (patch)
treeba53a8508b9295fadc5399ad2969a3074610fa0f /sys
parenta8c5987c33627c09fd4abefd3ce4dd467b66f1b5 (diff)
malloc_roundup to calculate allocation size malloc will use; from netbsd;
okay art@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_malloc.c14
-rw-r--r--sys/sys/malloc.h4
2 files changed, 16 insertions, 2 deletions
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index 01d3750929f..b2b58ea22e5 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_malloc.c,v 1.46 2002/01/16 20:50:17 miod Exp $ */
+/* $OpenBSD: kern_malloc.c,v 1.47 2002/02/12 17:19:41 provos Exp $ */
/* $NetBSD: kern_malloc.c,v 1.15.4.2 1996/06/13 17:10:56 cgd Exp $ */
/*
@@ -598,3 +598,15 @@ sysctl_malloc(name, namelen, oldp, oldlenp, newp, newlen, p)
}
/* NOTREACHED */
}
+
+/*
+ * Round up a size to how much malloc would actually allocate.
+ */
+size_t
+malloc_roundup(size_t sz)
+{
+ if (sz > MAXALLOCSAVE)
+ return round_page(sz);
+
+ return (1 << BUCKETINDX(sz));
+}
diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h
index 573f872c3ea..05e70a81a44 100644
--- a/sys/sys/malloc.h
+++ b/sys/sys/malloc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: malloc.h,v 1.53 2002/01/28 11:54:30 art Exp $ */
+/* $OpenBSD: malloc.h,v 1.54 2002/02/12 17:19:41 provos Exp $ */
/* $NetBSD: malloc.h,v 1.39 1998/07/12 19:52:01 augustss Exp $ */
/*
@@ -410,6 +410,8 @@ extern void free __P((void *addr, int type));
extern int sysctl_malloc __P((int *, u_int, void *, size_t *, void *, size_t,
struct proc *));
+size_t malloc_roundup(size_t);
+
#ifdef MALLOC_DEBUG
int debug_malloc(unsigned long, int, int, void **);
int debug_free(void *, int);