From 4608feb18b515ef7e01b906913b10bbca9d6b08a Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 28 Jan 2011 15:03:26 -0500 Subject: runtime: simpler heap map, memory allocation The old heap maps used a multilevel table, but that was overkill: there are only 1M entries on a 32-bit machine and we can arrange to use a dense address range on a 64-bit machine. The heap map is in bss. The assumption is that if we don't touch the pages they won't be mapped in. Also moved some duplicated memory allocation code out of the OS-specific files. R=r CC=golang-dev https://golang.org/cl/4118042 --- src/pkg/runtime/linux/mem.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/pkg/runtime/linux') diff --git a/src/pkg/runtime/linux/mem.c b/src/pkg/runtime/linux/mem.c index e750f97ea2..3a83e7394b 100644 --- a/src/pkg/runtime/linux/mem.c +++ b/src/pkg/runtime/linux/mem.c @@ -12,12 +12,11 @@ runtime·SysAlloc(uintptr n) p = runtime·mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0); if(p < (void*)4096) { if(p == (void*)EACCES) { - runtime·printf("mmap: access denied\n"); - runtime·printf("If you're running SELinux, enable execmem for this process.\n"); + runtime·printf("runtime: mmap: access denied\n"); + runtime·printf("if you're running SELinux, enable execmem for this process.\n"); runtime·exit(2); } - runtime·printf("mmap: errno=%p\n", p); - runtime·throw("mmap"); + return nil; } return p; } @@ -37,7 +36,19 @@ runtime·SysFree(void *v, uintptr n) runtime·munmap(v, n); } +void* +runtime·SysReserve(void *v, uintptr n) +{ + return runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0); +} + void -runtime·SysMemInit(void) +runtime·SysMap(void *v, uintptr n) { + void *p; + + mstats.sys += n; + p = runtime·mmap(v, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_FIXED|MAP_PRIVATE, -1, 0); + if(p != v) + runtime·throw("runtime: cannot map pages in arena address space"); } -- cgit v1.3-5-g9baa