]> Cypherpunks repositories - gostls13.git/commit
runtime: optimize permission changes with mprotect
authorLance Yang <ioworker0@gmail.com>
Tue, 19 Mar 2024 14:19:43 +0000 (14:19 +0000)
committerMichael Knyszek <mknyszek@google.com>
Tue, 19 Mar 2024 14:54:29 +0000 (14:54 +0000)
commitcb12198de57db6f514d7ef11839d446189e38f4b
treebadaa98ce8212fb9d331bee245c0abba19e0d420
parentb750841906c84e894dfa3ee43e0f65d94f989b01
runtime: optimize permission changes with mprotect

On Linux, both mprotect() and mmap() acquire the mmap_lock (in writer mode),
posing scalability challenges.

The mmap_lock (formerly called mmap_sem) is a reader/writer lock that controls
access to a process's address space; before making changes there (mapping in a
new range, for example), the kernel must acquire that lock.

Page-fault handling must also acquire mmap_lock (in reader mode) to ensure that
the address space doesn't change in surprising ways while a fault is being resolved.

A process can have a large address space and many threads running (and incurring
page faults) concurrently, turning mmap_lock into a significant bottleneck.

While both mmap() and mprotect() are protected by the mmap_lock, the shorter
duration of mprotect system call, due to their simpler nature, results in a reduced
locking time for the mmap_lock.

Change-Id: I7f929544904e31eab34d0d8a9e368abe4de64637
GitHub-Last-Rev: 6f27a216b4fb789181d00316561b44358a118b19
GitHub-Pull-Request: golang/go#65038
Reviewed-on: https://go-review.googlesource.com/c/go/+/554935
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
12 files changed:
src/internal/runtime/syscall/defs_linux_386.go
src/internal/runtime/syscall/defs_linux_amd64.go
src/internal/runtime/syscall/defs_linux_arm.go
src/internal/runtime/syscall/defs_linux_arm64.go
src/internal/runtime/syscall/defs_linux_loong64.go
src/internal/runtime/syscall/defs_linux_mips64x.go
src/internal/runtime/syscall/defs_linux_mipsx.go
src/internal/runtime/syscall/defs_linux_ppc64x.go
src/internal/runtime/syscall/defs_linux_riscv64.go
src/internal/runtime/syscall/defs_linux_s390x.go
src/runtime/mem_linux.go
src/runtime/os_linux.go