Commit 314fd624 authored by John Graham-Cumming's avatar John Graham-Cumming Committed by Dave Cheney

runtime: implement runtime.SysUnused on FreeBSD

madvise was missing so implement it in assembler. This change
needs to be extended to the other BSD variantes (Net and Open)

Without this change the scavenger will attempt to pass memory back
to the operating system when it has become idle, but the memory is
not returned and for long running Go processes the total memory used
can grow until OOM occurs.

I have only been able to test the code on FreeBSD AMD64. The ARM
platforms needs testing.

R=golang-dev, mikioh.mikioh, dave, jgc, minux.ma
CC=golang-dev
https://golang.org/cl/6850081
parent d4775a78
......@@ -7,8 +7,9 @@
/*
Input to cgo.
GOARCH=amd64 cgo -cdefs defs.go >amd64/defs.h
GOARCH=386 cgo -cdefs defs.go >386/defs.h
GOARCH=amd64 go tool cgo -cdefs defs_freebsd.go >defs_freebsd_amd64.h
GOARCH=386 go tool cgo -cdefs defs_freebsd.go >defs_freebsd_386.h
GOARCH=arm go tool cgo -cdefs defs_freebsd.go >defs_freebsd_arm.h
*/
package runtime
......@@ -38,6 +39,8 @@ const (
MAP_PRIVATE = C.MAP_PRIVATE
MAP_FIXED = C.MAP_FIXED
MADV_FREE = C.MADV_FREE
SA_SIGINFO = C.SA_SIGINFO
SA_RESTART = C.SA_RESTART
SA_ONSTACK = C.SA_ONSTACK
......
......@@ -11,6 +11,7 @@ enum {
MAP_ANON = 0x1000,
MAP_PRIVATE = 0x2,
MAP_FIXED = 0x10,
MADV_FREE = 0x5,
SA_SIGINFO = 0x40,
SA_RESTART = 0x2,
SA_ONSTACK = 0x1,
......
......@@ -11,6 +11,7 @@ enum {
MAP_ANON = 0x1000,
MAP_PRIVATE = 0x2,
MAP_FIXED = 0x10,
MADV_FREE = 0x5,
SA_SIGINFO = 0x40,
SA_RESTART = 0x2,
SA_ONSTACK = 0x1,
......
......@@ -11,6 +11,7 @@ enum {
MAP_ANON = 0x1000,
MAP_PRIVATE = 0x2,
MAP_FIXED = 0x10,
MADV_FREE = 0x5,
SA_SIGINFO = 0x40,
SA_RESTART = 0x2,
SA_ONSTACK = 0x1,
......
......@@ -23,9 +23,7 @@ runtime·SysAlloc(uintptr n)
void
runtime·SysUnused(void *v, uintptr n)
{
USED(v);
USED(n);
// TODO(rsc): call madvise MADV_DONTNEED
runtime·madvise(v, n, MADV_FREE);
}
void
......
......@@ -102,6 +102,13 @@ TEXT runtime·munmap(SB),7,$-4
MOVL $0xf1, 0xf1 // crash
RET
TEXT runtime·madvise(SB),7,$-4
MOVL $75, AX // madvise
INT $0x80
JAE 2(PC)
MOVL $0xf1, 0xf1 // crash
RET
TEXT runtime·setitimer(SB), 7, $-4
MOVL $83, AX
INT $0x80
......
......@@ -184,6 +184,17 @@ TEXT runtime·munmap(SB),7,$0
MOVL $0xf1, 0xf1 // crash
RET
TEXT runtime·madvise(SB),7,$0
MOVQ 8(SP), DI
MOVQ 16(SP), SI
MOVQ 24(SP), DX
MOVQ $75, AX // madvise
SYSCALL
CMPQ AX, $0xfffffffffffff001
JLS 2(PC)
MOVL $0xf1, 0xf1 // crash
RET
TEXT runtime·sigaltstack(SB),7,$-8
MOVQ new+8(SP), DI
MOVQ old+16(SP), SI
......
......@@ -187,6 +187,15 @@ TEXT runtime·munmap(SB),7,$0
MOVW.CS R9, (R9)
RET
TEXT runtime·madvise(SB),7,$0
MOVW 0(FP), R0 // arg 1 addr
MOVW 4(FP), R1 // arg 2 len
MOVW 8(FP), R2 // arg 3 flags
SWI $75
MOVW.CS $0, R9 // crash on syscall failure
MOVW.CS R9, (R9)
RET
TEXT runtime·sigaltstack(SB),7,$-8
MOVW new+0(FP), R0
MOVW old+4(FP), R1
......
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