Commit c115cda2 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

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
parent cdc93d24
......@@ -44,7 +44,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void
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*
......
......@@ -48,7 +48,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void
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*
......
......@@ -48,7 +48,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void
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*
......
......@@ -95,7 +95,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void
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*
......
......@@ -56,7 +56,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void
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*
......
......@@ -48,7 +48,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void
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*
......
......@@ -48,7 +48,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void
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*
......
......@@ -49,7 +49,7 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void
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*
......
......@@ -66,11 +66,8 @@ runtime·SysFree(void *v, uintptr n, uint64 *stat)
void
runtime·SysFault(void *v, uintptr n)
{
uintptr r, old;
r = (uintptr)runtime·stdcall(runtime·VirtualProtect, 4, v, n, (uintptr)PAGE_NOACCESS, &old);
if(r == 0)
runtime·throw("runtime: failed to protect pages");
// SysUnused makes the memory inaccessible and prevents its reuse
runtime·SysUnused(v, n);
}
void*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment