]> Zhao Yanbai Git Server - minix.git/commitdiff
memory driver: use mmap to pre-allocate ramdisks to avoid overcommit.
authorBen Gras <ben@minix3.org>
Mon, 28 Jun 2010 18:12:32 +0000 (18:12 +0000)
committerBen Gras <ben@minix3.org>
Mon, 28 Jun 2010 18:12:32 +0000 (18:12 +0000)
drivers/memory/memory.c

index 3e7a9469cc69773a6cda52f007e8fcc524750cd2..0d2f1ed90eb36545f73043e5be3369e801d4f6bc 100644 (file)
@@ -445,7 +445,7 @@ message *m_ptr;                             /* pointer to control message */
                        panic("huge old ramdisk");
                }
                size = ex64lo(dv->dv_size);
-               free((void *) m_vaddrs[dev]);
+               munmap((void *) m_vaddrs[dev], size);
                m_vaddrs[dev] = (vir_bytes) NULL;
        }
 
@@ -454,11 +454,11 @@ message *m_ptr;                           /* pointer to control message */
 #endif
 
        /* Try to allocate a piece of memory for the RAM disk. */
-       if(!(mem = malloc(ramdev_size))) {
+       if((mem = mmap(NULL, ramdev_size, PROT_READ|PROT_WRITE,
+         MAP_PREALLOC|MAP_ANON, -1, 0)) == MAP_FAILED) {
            printf("MEM: failed to get memory for ramdisk\n");
             return(ENOMEM);
-        } 
-       memset(mem, 0, ramdev_size);
+        }
 
        m_vaddrs[dev] = (vir_bytes) mem;