1
0
mirror of https://github.com/golang/go synced 2024-11-26 20:21:25 -07:00

runtime: improve efence

Mark free memory blocks as unused.
On amd64 it allows the process to eat all 128 GB of heap
without killing the machine.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/74070043
This commit is contained in:
Dmitriy Vyukov 2014-03-13 19:04:00 +04:00
parent cdc93d2416
commit c115cda22c
9 changed files with 10 additions and 13 deletions

View File

@ -44,7 +44,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void void
runtime·SysFault(void *v, uintptr n) runtime·SysFault(void *v, uintptr n)
{ {
runtime·mmap(v, n, PROT_NONE, 0, -1, 0); runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
} }
void* void*

View File

@ -48,7 +48,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void void
runtime·SysFault(void *v, uintptr n) runtime·SysFault(void *v, uintptr n)
{ {
runtime·mmap(v, n, PROT_NONE, 0, -1, 0); runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
} }
void* void*

View File

@ -48,7 +48,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void void
runtime·SysFault(void *v, uintptr n) runtime·SysFault(void *v, uintptr n)
{ {
runtime·mmap(v, n, PROT_NONE, 0, -1, 0); runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
} }
void* void*

View File

@ -95,7 +95,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void void
runtime·SysFault(void *v, uintptr n) runtime·SysFault(void *v, uintptr n)
{ {
runtime·mmap(v, n, PROT_NONE, 0, -1, 0); runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
} }
void* void*

View File

@ -56,7 +56,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void void
runtime·SysFault(void *v, uintptr n) runtime·SysFault(void *v, uintptr n)
{ {
runtime·mmap(v, n, PROT_NONE, 0, -1, 0); runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
} }
void* void*

View File

@ -48,7 +48,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void void
runtime·SysFault(void *v, uintptr n) runtime·SysFault(void *v, uintptr n)
{ {
runtime·mmap(v, n, PROT_NONE, 0, -1, 0); runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
} }
void* void*

View File

@ -48,7 +48,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void void
runtime·SysFault(void *v, uintptr n) runtime·SysFault(void *v, uintptr n)
{ {
runtime·mmap(v, n, PROT_NONE, 0, -1, 0); runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
} }
void* void*

View File

@ -49,7 +49,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void void
runtime·SysFault(void *v, uintptr n) runtime·SysFault(void *v, uintptr n)
{ {
runtime·mmap(v, n, PROT_NONE, 0, -1, 0); runtime·mmap(v, n, PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0);
} }
void* void*

View File

@ -66,11 +66,8 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void void
runtime·SysFault(void *v, uintptr n) runtime·SysFault(void *v, uintptr n)
{ {
uintptr r, old; // SysUnused makes the memory inaccessible and prevents its reuse
runtime·SysUnused(v, n);
r = (uintptr)runtime·stdcall(runtime·VirtualProtect, 4, v, n, (uintptr)PAGE_NOACCESS, &old);
if(r == 0)
runtime·throw("runtime: failed to protect pages");
} }
void* void*