Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern align allocations >=pagesize at a page boundary, to...



details:   https://anonhg.NetBSD.org/src/rev/c3ffa816454a
branches:  trunk
changeset: 773565:c3ffa816454a
user:      drochner <drochner%NetBSD.org@localhost>
date:      Mon Feb 06 12:13:44 2012 +0000

description:
align allocations >=pagesize at a page boundary, to preserve traditional
malloc(9) semantics
fixes dri mappings shared per mmap (at least on i945)
approved by releng

diffstat:

 sys/kern/kern_malloc.c |  24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diffs (62 lines):

diff -r d104816bfb78 -r c3ffa816454a sys/kern/kern_malloc.c
--- a/sys/kern/kern_malloc.c    Mon Feb 06 10:55:32 2012 +0000
+++ b/sys/kern/kern_malloc.c    Mon Feb 06 12:13:44 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_malloc.c,v 1.137 2012/01/30 05:42:54 mrg Exp $    */
+/*     $NetBSD: kern_malloc.c,v 1.138 2012/02/06 12:13:44 drochner Exp $       */
 
 /*
  * Copyright (c) 1987, 1991, 1993
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.137 2012/01/30 05:42:54 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_malloc.c,v 1.138 2012/02/06 12:13:44 drochner Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -108,10 +108,18 @@
 #endif /* MALLOCLOG */
 {
        const int kmflags = (flags & M_NOWAIT) ? KM_NOSLEEP : KM_SLEEP;
-       const size_t allocsize = sizeof(struct malloc_header) + size;
+       size_t allocsize, hdroffset;
        struct malloc_header *mh;
        void *p;
 
+       if (size >= PAGE_SIZE) {
+               allocsize = PAGE_SIZE + size; /* for page alignment */
+               hdroffset = PAGE_SIZE - sizeof(struct malloc_header);
+       } else {
+               allocsize = sizeof(struct malloc_header) + size;
+               hdroffset = 0;
+       }
+
        p = kmem_intr_alloc(allocsize, kmflags);
        if (p == NULL)
                return NULL;
@@ -119,8 +127,8 @@
        if ((flags & M_ZERO) != 0) {
                memset(p, 0, allocsize);
        }
-       mh = (void *)p;
-       mh->mh_size = allocsize;
+       mh = (void *)((char *)p + hdroffset);
+       mh->mh_size = allocsize - hdroffset;
 
        return mh + 1;
 }
@@ -141,7 +149,11 @@
        mh = addr;
        mh--;
 
-       kmem_intr_free(mh, mh->mh_size);
+       if (mh->mh_size >= PAGE_SIZE + sizeof(struct malloc_header))
+               kmem_intr_free((char *)addr - PAGE_SIZE,
+                   mh->mh_size + PAGE_SIZE - sizeof(struct malloc_header));
+       else
+               kmem_intr_free(mh, mh->mh_size);
 }
 
 /*



Home | Main Index | Thread Index | Old Index