]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: implement runtime.SysUnused on FreeBSD
authorJohn Graham-Cumming <jgc@jgc.org>
Sat, 24 Nov 2012 04:55:19 +0000 (15:55 +1100)
committerDave Cheney <dave@cheney.net>
Sat, 24 Nov 2012 04:55:19 +0000 (15:55 +1100)
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

src/pkg/runtime/defs_freebsd.go
src/pkg/runtime/defs_freebsd_386.h
src/pkg/runtime/defs_freebsd_amd64.h
src/pkg/runtime/defs_freebsd_arm.h
src/pkg/runtime/mem_freebsd.c
src/pkg/runtime/sys_freebsd_386.s
src/pkg/runtime/sys_freebsd_amd64.s
src/pkg/runtime/sys_freebsd_arm.s

index 306e32197e4309476b1a146b9ee1a47d349c35ff..0302527936719db8e6afa4a8df28df6646256259 100644 (file)
@@ -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
index 29fcb8b576516360f307877a09338a00c59926a7..eb8c7f629f8844beb815b62f19f60b1a7dc41639 100644 (file)
@@ -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,
index 8a222dca4fd67f83a218ce14a92944d6fe3aaf74..a933a9c0248dbddba19b0de5e2a2d9483730cc3d 100644 (file)
@@ -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,
index 351259eee91bd5b36eff7cc6c936eb47a9b18550..995129f291459d275ff4b0f52fd4ad03a9747409 100644 (file)
@@ -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,
index d1c22583dc8a390a703f70f5b5bab9f00c86c159..cc31711f8ede7b209a42ca421a7abc3c6d5af15f 100644 (file)
@@ -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
index c386268ff5d19f52ca35638877da64679271e91a..9049f1e75b522045baab312109611da8171d9cdc 100644 (file)
@@ -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
index 3d25db2ce7d4207e3580bfaedfda8a259f86a15e..d66aed107cc5aa1abaad46b475ea52fb68992b0a 100644 (file)
@@ -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
index 097fcd0457721b29c6a53621bd22f486397f7660..1edf8071bb42a56e1f4ccebeb091ccd0823a4254 100644 (file)
@@ -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