Commit 4eeb780
mm: only hugepage-align mappings of hugepage-aligned length
This is consistent with Linux after d4148aeab4124 "mm, mmap: limit THP
alignment of anonymous mappings to PMD-aligned sizes".
In #12804, when PyTorch / libcuda / the Nvidia userspace driver allocates CPU
memory, it relies specifically on Linux's mmap address selection behavior (and
the assumption that no other threads are doing mmap() / munmap()) in order to
get (in this case) a mapping aligned to one page before a hugepage boundary.
After this CL, this looks like:
```
I0401 23:24:16.756773 1 strace.go:576] [ 1: 1] python3 E mmap(0x0, 0x11fff000, 0x0, MAP_PRIVATE|MAP_ANONYMOUS, 0xffffffffffffffff (bad FD), 0x0)
I0401 23:24:16.756782 1 strace.go:614] [ 1: 1] python3 X mmap(0x0, 0x11fff000, 0x0, MAP_PRIVATE|MAP_ANONYMOUS, 0xffffffffffffffff (bad FD), 0x0) = 139925074735104 (0x7f42d85ff000) (3.624µs)
I0401 23:24:16.756790 1 strace.go:564] [ 1: 1] python3 E munmap(0x7f42d85ff000, 0x1a01000)
I0401 23:24:16.756796 1 strace.go:602] [ 1: 1] python3 X munmap(0x7f42d85ff000, 0x1a01000) = 0 (0x0) (1.436µs)
I0401 23:24:16.756801 1 strace.go:564] [ 1: 1] python3 E munmap(0x7f42ea000000, 0x5fe000)
I0401 23:24:16.756805 1 strace.go:602] [ 1: 1] python3 X munmap(0x7f42ea000000, 0x5fe000) = 0 (0x0) (598ns)
<driver ioctls>
I0401 23:24:16.758206 1 strace.go:576] [ 1: 1] python3 E mmap(0x0, 0x10001000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0xffffffffffffffff (bad FD), 0x0)
I0401 23:24:16.758213 1 strace.go:614] [ 1: 1] python3 X mmap(0x0, 0x10001000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0xffffffffffffffff (bad FD), 0x0) = 139924833562624 (0x7f42c9fff000) (1.983µs)
...
cpu.data_ptr() = 0x7f42c9fff040
7f42c9fff000-7f42da000000 rw-p 00000000 00:00 0
7f42da000000-7f42ea000000 ---p 00000000 00:00 0
```
This is consistent across executions in runc and (after this CL) gVisor. Before
this CL, this doesn't work in gVisor:
```
I0401 23:06:38.431128 1 strace.go:576] [ 1: 1] python3 E mmap(0x0, 0x10001000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0xffffffffffffffff (bad FD), 0x0)
I0401 23:06:38.431136 1 strace.go:614] [ 1: 1] python3 X mmap(0x0, 0x10001000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0xffffffffffffffff (bad FD), 0x0) = 140266751131648 (0x7f9265e00000) (2.221µs)
...
cpu.data_ptr() = 0x7f9265e00040
7f9265e00000-7f9275e01000 rw-p 00000000 00:00 0
```
Fixes #12804
PiperOrigin-RevId: 8932668001 parent 28a0852 commit 4eeb780
1 file changed
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | | - | |
199 | | - | |
| 198 | + | |
| 199 | + | |
200 | 200 | | |
201 | | - | |
| 201 | + | |
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| |||
0 commit comments