aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/thread_linux.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2012-02-24 15:28:51 -0500
committerRuss Cox <rsc@golang.org>2012-02-24 15:28:51 -0500
commit102274a30e5d2df4d13d5fad50c484f78904236a (patch)
tree20384f9d94d1d7c9e934014c7d219c5be07c4aed /src/pkg/runtime/thread_linux.c
parentd8ccebfffa40b016d9e90713ce0430c37d98175c (diff)
downloadgo-102274a30e5d2df4d13d5fad50c484f78904236a.tar.xz
runtime: size arena to fit in virtual address space limit
For Brad. Now FreeBSD/386 binaries run on nearlyfreespeech.net. Fixes #2302. R=golang-dev, r CC=golang-dev https://golang.org/cl/5700060
Diffstat (limited to 'src/pkg/runtime/thread_linux.c')
-rw-r--r--src/pkg/runtime/thread_linux.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/pkg/runtime/thread_linux.c b/src/pkg/runtime/thread_linux.c
index 005fb1df6a..d406a71240 100644
--- a/src/pkg/runtime/thread_linux.c
+++ b/src/pkg/runtime/thread_linux.c
@@ -221,3 +221,31 @@ runtime·sigpanic(void)
}
runtime·panicstring(runtime·sigtab[g->sig].name);
}
+
+uintptr
+runtime·memlimit(void)
+{
+ Rlimit rl;
+ extern byte text[], end[];
+ uintptr used;
+
+ if(runtime·getrlimit(RLIMIT_AS, &rl) != 0)
+ return 0;
+ if(rl.rlim_cur >= 0x7fffffff)
+ return 0;
+
+ // Estimate our VM footprint excluding the heap.
+ // Not an exact science: use size of binary plus
+ // some room for thread stacks.
+ used = end - text + (64<<20);
+ if(used >= rl.rlim_cur)
+ return 0;
+
+ // If there's not at least 16 MB left, we're probably
+ // not going to be able to do much. Treat as no limit.
+ rl.rlim_cur -= used;
+ if(rl.rlim_cur < (16<<20))
+ return 0;
+
+ return rl.rlim_cur - used;
+}