Skip to content

Commit a45f555

Browse files
josephlrianlancetaylor
authored andcommitted
unix: defer Getpagesize() to runtime
In general, page size is not a function of the archetecture. This was addressed in the Go standard library here: https://go-review.googlesource.com/25051 This change simply defers to the standard library "syscall" package, which in turn defers to the runtime. This helps in addressing golang/go#10180 and also fixes a bug on ppc64. Currently, we return 65536 as the page size on ppc64, but the kernel supports 4k and 64k sizes, see here: http://elixir.free-electrons.com/linux/v4.13/source/arch/powerpc/include/asm/page.h#L24 Now that various page size calculations are not needed, various components are now dead code and can also be removed. This CL reverts: https://go-review.googlesource.com/14483 and part of: https://go-review.googlesource.com/30755 Change-Id: I9d7a2d96359054e0dca9c985b026c8072b2eeaf3 Reviewed-on: https://go-review.googlesource.com/62111 Reviewed-by: Austin Clements <[email protected]> Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 31e1faf commit a45f555

40 files changed

+16
-145
lines changed

unix/gccgo_linux_sparc64.go

Lines changed: 0 additions & 20 deletions
This file was deleted.

unix/linux/types.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,6 @@ const RNDGETENTCNT = C.RNDGETENTCNT
535535

536536
const PERF_IOC_FLAG_GROUP = C.PERF_IOC_FLAG_GROUP
537537

538-
// sysconf information
539-
540-
const _SC_PAGESIZE = C._SC_PAGESIZE
541-
542538
// Terminal handling
543539

544540
type Termios C.termios_t

unix/pagesize_unix.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
6+
7+
// For Unix, get the pagesize from the runtime.
8+
9+
package unix
10+
11+
import "syscall"
12+
13+
func Getpagesize() int {
14+
return syscall.Getpagesize()
15+
}

unix/syscall_darwin_386.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"unsafe"
1212
)
1313

14-
func Getpagesize() int { return 4096 }
15-
1614
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1715

1816
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_darwin_amd64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"unsafe"
1212
)
1313

14-
func Getpagesize() int { return 4096 }
15-
1614
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1715

1816
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_darwin_arm.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"unsafe"
1010
)
1111

12-
func Getpagesize() int { return 4096 }
13-
1412
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1513

1614
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_darwin_arm64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"unsafe"
1212
)
1313

14-
func Getpagesize() int { return 16384 }
15-
1614
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1715

1816
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_dragonfly_amd64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"unsafe"
1212
)
1313

14-
func Getpagesize() int { return 4096 }
15-
1614
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1715

1816
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_freebsd_386.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"unsafe"
1212
)
1313

14-
func Getpagesize() int { return 4096 }
15-
1614
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1715

1816
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_freebsd_amd64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"unsafe"
1212
)
1313

14-
func Getpagesize() int { return 4096 }
15-
1614
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1715

1816
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_freebsd_arm.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"unsafe"
1212
)
1313

14-
func Getpagesize() int { return 4096 }
15-
1614
func TimespecToNsec(ts Timespec) int64 { return ts.Sec*1e9 + int64(ts.Nsec) }
1715

1816
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_linux_386.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"unsafe"
1515
)
1616

17-
func Getpagesize() int { return 4096 }
18-
1917
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
2018

2119
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_linux_amd64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ func Gettimeofday(tv *Timeval) (err error) {
6969
return nil
7070
}
7171

72-
func Getpagesize() int { return 4096 }
73-
7472
func Time(t *Time_t) (tt Time_t, err error) {
7573
var tv Timeval
7674
errno := gettimeofday(&tv)

unix/syscall_linux_arm.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"unsafe"
1212
)
1313

14-
func Getpagesize() int { return 4096 }
15-
1614
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1715

1816
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_linux_arm64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ func Lstat(path string, stat *Stat_t) (err error) {
6666
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
6767
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
6868

69-
func Getpagesize() int { return 65536 }
70-
7169
//sysnb Gettimeofday(tv *Timeval) (err error)
7270

7371
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

unix/syscall_linux_mips64x.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ package unix
5555
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
5656
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
5757

58-
func Getpagesize() int { return 65536 }
59-
6058
//sysnb Gettimeofday(tv *Timeval) (err error)
6159

6260
func Time(t *Time_t) (tt Time_t, err error) {

unix/syscall_linux_mipsx.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,3 @@ func Poll(fds []PollFd, timeout int) (n int, err error) {
235235
}
236236
return poll(&fds[0], len(fds), timeout)
237237
}
238-
239-
func Getpagesize() int { return 4096 }

unix/syscall_linux_ppc64x.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ package unix
6161
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
6262
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
6363

64-
func Getpagesize() int { return 65536 }
65-
6664
//sysnb Gettimeofday(tv *Timeval) (err error)
6765
//sysnb Time(t *Time_t) (tt Time_t, err error)
6866

unix/syscall_linux_s390x.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ import (
4646
//sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
4747
//sysnb setgroups(n int, list *_Gid_t) (err error)
4848

49-
func Getpagesize() int { return 4096 }
50-
5149
//sysnb Gettimeofday(tv *Timeval) (err error)
5250

5351
func Time(t *Time_t) (tt Time_t, err error) {

unix/syscall_linux_sparc64.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
package unix
88

9-
import (
10-
"sync/atomic"
11-
"syscall"
12-
)
13-
149
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
1510
//sys Dup2(oldfd int, newfd int) (err error)
1611
//sys Fchown(fd int, uid int, gid int) (err error)
@@ -63,21 +58,6 @@ import (
6358
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
6459
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
6560

66-
func sysconf(name int) (n int64, err syscall.Errno)
67-
68-
// pageSize caches the value of Getpagesize, since it can't change
69-
// once the system is booted.
70-
var pageSize int64 // accessed atomically
71-
72-
func Getpagesize() int {
73-
n := atomic.LoadInt64(&pageSize)
74-
if n == 0 {
75-
n, _ = sysconf(_SC_PAGESIZE)
76-
atomic.StoreInt64(&pageSize, n)
77-
}
78-
return int(n)
79-
}
80-
8161
func Ioperm(from int, num int, on int) (err error) {
8262
return ENOSYS
8363
}

unix/syscall_netbsd_386.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
package unix
88

9-
func Getpagesize() int { return 4096 }
10-
119
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1210

1311
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_netbsd_amd64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
package unix
88

9-
func Getpagesize() int { return 4096 }
10-
119
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1210

1311
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_netbsd_arm.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
package unix
88

9-
func Getpagesize() int { return 4096 }
10-
119
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1210

1311
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_openbsd_386.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
package unix
88

9-
func Getpagesize() int { return 4096 }
10-
119
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1210

1311
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_openbsd_amd64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
package unix
88

9-
func Getpagesize() int { return 4096 }
10-
119
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1210

1311
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_openbsd_arm.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
package unix
88

9-
import "syscall"
10-
11-
func Getpagesize() int { return syscall.Getpagesize() }
12-
139
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1410

1511
func NsecToTimespec(nsec int64) (ts Timespec) {

unix/syscall_solaris.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
package unix
1414

1515
import (
16-
"sync/atomic"
1716
"syscall"
1817
"unsafe"
1918
)
@@ -699,18 +698,3 @@ func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, e
699698
func Munmap(b []byte) (err error) {
700699
return mapper.Munmap(b)
701700
}
702-
703-
//sys sysconf(name int) (n int64, err error)
704-
705-
// pageSize caches the value of Getpagesize, since it can't change
706-
// once the system is booted.
707-
var pageSize int64 // accessed atomically
708-
709-
func Getpagesize() int {
710-
n := atomic.LoadInt64(&pageSize)
711-
if n == 0 {
712-
n, _ = sysconf(_SC_PAGESIZE)
713-
atomic.StoreInt64(&pageSize, n)
714-
}
715-
return int(n)
716-
}

unix/types_solaris.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,6 @@ type BpfTimeval C.struct_bpf_timeval
256256

257257
type BpfHdr C.struct_bpf_hdr
258258

259-
// sysconf information
260-
261-
const _SC_PAGESIZE = C._SC_PAGESIZE
262-
263259
// Terminal handling
264260

265261
type Termios C.struct_termios

unix/zsyscall_solaris_amd64.go

Lines changed: 1 addition & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_linux_386.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_linux_amd64.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_linux_arm.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_linux_arm64.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)