From: Ben Gras Date: Mon, 28 Jun 2010 18:12:32 +0000 (+0000) Subject: memory driver: use mmap to pre-allocate ramdisks to avoid overcommit. X-Git-Tag: v3.1.8~319 X-Git-Url: http://zhaoyanbai.com/repos/migration-4to9?a=commitdiff_plain;h=635a8f772cfe973c942eecc45a5fca9fab4bf1df;p=minix.git memory driver: use mmap to pre-allocate ramdisks to avoid overcommit. --- diff --git a/drivers/memory/memory.c b/drivers/memory/memory.c index 3e7a9469c..0d2f1ed90 100644 --- a/drivers/memory/memory.c +++ b/drivers/memory/memory.c @@ -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;