<feed xmlns='http://www.w3.org/2005/Atom'>
<title>go/src/runtime/mpagealloc_test.go, branch makepkg</title>
<subtitle>Fork of Go programming language with my patches.</subtitle>
<id>http://git.kilabit.info/go/atom?h=makepkg</id>
<link rel='self' href='http://git.kilabit.info/go/atom?h=makepkg'/>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/'/>
<updated>2025-10-17T20:10:27Z</updated>
<entry>
<title>all: remove unnecessary loop variable copies in tests</title>
<updated>2025-10-17T20:10:27Z</updated>
<author>
<name>Tobias Klauser</name>
<email>tklauser@distanz.ch</email>
</author>
<published>2025-10-14T09:40:26Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=b5aefe07e5afe2fd5d49c6a4219cc826b3e4e34e'/>
<id>urn:sha1:b5aefe07e5afe2fd5d49c6a4219cc826b3e4e34e</id>
<content type='text'>
Copying the loop variable is no longer necessary since Go 1.22.

Change-Id: Iebb21dac44a20ec200567f1d786f105a4ee4999d
Reviewed-on: https://go-review.googlesource.com/c/go/+/711640
Reviewed-by: Florian Lehner &lt;lehner.florian86@gmail.com&gt;
Auto-Submit: Damien Neil &lt;dneil@google.com&gt;
Reviewed-by: Dmitri Shuralyov &lt;dmitshur@google.com&gt;
Reviewed-by: Damien Neil &lt;dneil@google.com&gt;
Auto-Submit: Tobias Klauser &lt;tobias.klauser@gmail.com&gt;
LUCI-TryBot-Result: Go LUCI &lt;golang-scoped@luci-project-accounts.iam.gserviceaccount.com&gt;
</content>
</entry>
<entry>
<title>runtime: use a smaller arena size on Wasm</title>
<updated>2025-09-27T00:13:31Z</updated>
<author>
<name>Cherry Mui</name>
<email>cherryyz@google.com</email>
</author>
<published>2025-06-22T19:40:02Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=53009b26dd2e8b75fba8b44849e1d323ddb2a31f'/>
<id>urn:sha1:53009b26dd2e8b75fba8b44849e1d323ddb2a31f</id>
<content type='text'>
On Wasm, some programs have very small heap. Currently,
we use 4 MB arena size (like all other 32-bit platforms).
For a very small program, it needs to allocate one heap
arena, 4 MB size at a 4 MB aligned address. So we'll
need 8 MB of linear memory, whereas only a smaller
portion is actually used by the program. On Wasm, samll
programs are not uncommon (e.g. WASI plugins), and
users are concerned about the memory usage.

This CL switches to a smaller arena size, as well as a
smaller page allocator chunk size (both are now 512 KB).
So the heap will be grown in 512 KB granularity. For a
helloworld program, it now uses less than 3 MB of
linear memory, instead of 8 MB.

Change-Id: Ibd66c1fa6e794a12c00906cbacc8f2e410f196c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/683296
Reviewed-by: David Chase &lt;drchase@google.com&gt;
Reviewed-by: Michael Knyszek &lt;mknyszek@google.com&gt;
LUCI-TryBot-Result: Go LUCI &lt;golang-scoped@luci-project-accounts.iam.gserviceaccount.com&gt;
</content>
</entry>
<entry>
<title>runtime: set iOS addr space to 40 bits with incremental pagealloc</title>
<updated>2021-12-06T19:16:48Z</updated>
<author>
<name>Michael Anthony Knyszek</name>
<email>mknyszek@google.com</email>
</author>
<published>2021-08-23T17:27:40Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=c27a3592aec5f46ae18f7fd3d9ba18e69e2f1dcb'/>
<id>urn:sha1:c27a3592aec5f46ae18f7fd3d9ba18e69e2f1dcb</id>
<content type='text'>
In iOS &lt;14, the address space is strictly limited to 8 GiB, or 33 bits.
As a result, the page allocator also assumes all heap memory lives in
this region. This is especially necessary because the page allocator has
a PROT_NONE mapping proportional to the size of the usable address
space, so this keeps that mapping very small.

However starting with iOS 14, this restriction is relaxed, and mmap may
start returning addresses outside of the &lt;14 range. Today this means
that in iOS 14 and later, users experience an error in the page
allocator when a heap arena is mapped outside of the old range.

This change increases the ios/arm64 heapAddrBits to 40 while
simultaneously making ios/arm64 use the 64-bit pagealloc implementation
(with reservations and incremental mapping) to accommodate both iOS
versions &lt;14 and 14+.

Once iOS &lt;14 is deprecated, we can remove these exceptions and treat
ios/arm64 like any other arm64 platform.

This change also makes the BaseChunkIdx expression a little bit easier
to read, while we're here.

Fixes #46860.

Change-Id: I13865f799777739109585f14f1cc49d6d57e096b
Reviewed-on: https://go-review.googlesource.com/c/go/+/344401
Trust: Michael Knyszek &lt;mknyszek@google.com&gt;
Run-TryBot: Michael Knyszek &lt;mknyszek@google.com&gt;
TryBot-Result: Gopher Robot &lt;gobot@golang.org&gt;
Reviewed-by: Cherry Mui &lt;cherryyz@google.com&gt;
Reviewed-by: Austin Clements &lt;austin@google.com&gt;
</content>
</entry>
<entry>
<title>runtime: define the AddrRange used for testing in terms of addrRange</title>
<updated>2020-10-22T15:25:33Z</updated>
<author>
<name>Michael Anthony Knyszek</name>
<email>mknyszek@google.com</email>
</author>
<published>2020-07-14T20:27:27Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=b4a06b20897fe7ea3be715cb51040a2ccc52c15b'/>
<id>urn:sha1:b4a06b20897fe7ea3be715cb51040a2ccc52c15b</id>
<content type='text'>
Currently the AddrRange used for testing is defined separately from
addrRange in the runtime, making it difficult to test it as well as
addrRanges. Redefine AddrRange in terms of addrRange instead.

For #40191.

Change-Id: I3aa5b8df3e4c9a3c494b46ab802dd574b2488141
Reviewed-on: https://go-review.googlesource.com/c/go/+/242677
Trust: Michael Knyszek &lt;mknyszek@google.com&gt;
Run-TryBot: Michael Knyszek &lt;mknyszek@google.com&gt;
TryBot-Result: Go Bot &lt;gobot@golang.org&gt;
Reviewed-by: Michael Pratt &lt;mpratt@google.com&gt;
Reviewed-by: Austin Clements &lt;austin@google.com&gt;
</content>
</entry>
<entry>
<title>runtime: validate candidate searchAddr in pageAlloc.find</title>
<updated>2020-07-31T14:35:39Z</updated>
<author>
<name>Michael Anthony Knyszek</name>
<email>mknyszek@google.com</email>
</author>
<published>2020-07-13T19:51:50Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=b56791cdea5caa87ffcd585d29c294bd3d08a06a'/>
<id>urn:sha1:b56791cdea5caa87ffcd585d29c294bd3d08a06a</id>
<content type='text'>
Currently pageAlloc.find attempts to find a better estimate for the
first free page in the heap, even if the space its looking for isn't
necessarily going to be the first free page in the heap (e.g. if npages
&gt;= 2). However, in doing so it has the potential to return a searchAddr
candidate that doesn't actually correspond to mapped memory, but this
candidate might still be adopted. As a result, pageAlloc.alloc's fast
path may look at unmapped summary memory and segfault. This case is rare
on most operating systems since the heap is kept fairly contiguous, so
the chance that the candidate searchAddr discovered is unmapped is
fairly low. Even so, this is totally possible and outside the user's
control when it happens (in fact, it's likely to happen consistently for
a given user on a given system).

Fix this problem by ensuring that our candidate always points to mapped
memory. We do this by looking at mheap's arenas structure first. If it
turns out our candidate doesn't correspond to mapped memory, then we
look at inUse to round up the searchAddr to the next mapped address.

While we're here, clean up some documentation related to searchAddr.

Fixes #40191.

Change-Id: I759efec78987e4a8fde466ae45aabbaa3d9d4214
Reviewed-on: https://go-review.googlesource.com/c/go/+/242680
Run-TryBot: Michael Knyszek &lt;mknyszek@google.com&gt;
Reviewed-by: Austin Clements &lt;austin@google.com&gt;
Reviewed-by: Michael Pratt &lt;mpratt@google.com&gt;
TryBot-Result: Gobot Gobot &lt;gobot@golang.org&gt;
</content>
</entry>
<entry>
<title>runtime: ensure that searchAddr always refers to inUse memory</title>
<updated>2020-01-28T22:08:43Z</updated>
<author>
<name>Michael Anthony Knyszek</name>
<email>mknyszek@google.com</email>
</author>
<published>2020-01-28T19:59:19Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=e7f9e17b7927cad7a93c5785e864799e8d9b4381'/>
<id>urn:sha1:e7f9e17b7927cad7a93c5785e864799e8d9b4381</id>
<content type='text'>
This change formalizes an assumption made by the page allocator, which
is that (*pageAlloc).searchAddr should never refer to memory that is not
represented by (*pageAlloc).inUse. The portion of address space covered
by (*pageAlloc).inUse reflects the parts of the summary arrays which are
guaranteed to mapped, and so looking at any summary which is not
reflected there may cause a segfault.

In fact, this can happen today. This change thus also removes a
micro-optimization which is the only case which may cause
(*pageAlloc).searchAddr to point outside of any region covered by
(*pageAlloc).inUse, and adds a test verifying that the current segfault
can no longer occur.

Change-Id: I98b534f0ffba8656d3bd6d782f6fc22549ddf1c2
Reviewed-on: https://go-review.googlesource.com/c/go/+/216697
Run-TryBot: Michael Knyszek &lt;mknyszek@google.com&gt;
TryBot-Result: Gobot Gobot &lt;gobot@golang.org&gt;
Reviewed-by: Cherry Zhang &lt;cherryyz@google.com&gt;
</content>
</entry>
<entry>
<title>runtime: disable pageAlloc tests on OpenBSD in short mode</title>
<updated>2019-12-26T21:16:03Z</updated>
<author>
<name>Michael Anthony Knyszek</name>
<email>mknyszek@google.com</email>
</author>
<published>2019-12-19T17:44:58Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=cd1b9c1d5a7bb8ea6ebec223ce11e91897584ef4'/>
<id>urn:sha1:cd1b9c1d5a7bb8ea6ebec223ce11e91897584ef4</id>
<content type='text'>
This change disables pageAlloc tests on OpenBSD in short mode because
pageAlloc holds relatively large virtual memory reservations and we make
two during the pageAlloc tests. The runtime may also be carrying one
such reservation making the virtual memory requirement for testing the
Go runtime three times as much as just running a Go binary.

This causes problems for folks who just want to build and test Go
(all.bash) on OpenBSD but either don't have machines with at least 4ish
GiB of RAM (per-process virtual memory limits are capped at some
constant factor times the amount of physical memory) or their
per-process virtual memory limits are low for other reasons.

Fixes #36210.

Change-Id: I8d89cfde448d4cd2fefff4ad6ffed90de63dd527
Reviewed-on: https://go-review.googlesource.com/c/go/+/212177
Run-TryBot: Michael Knyszek &lt;mknyszek@google.com&gt;
TryBot-Result: Gobot Gobot &lt;gobot@golang.org&gt;
Reviewed-by: Bryan C. Mills &lt;bcmills@google.com&gt;
</content>
</entry>
<entry>
<title>runtime: fix off-by-1 error on address ranges</title>
<updated>2019-12-13T17:18:15Z</updated>
<author>
<name>Cherry Zhang</name>
<email>cherryyz@google.com</email>
</author>
<published>2019-12-12T21:41:24Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=1475b9709013db2c1bb25583729529db1e549312'/>
<id>urn:sha1:1475b9709013db2c1bb25583729529db1e549312</id>
<content type='text'>
When growing the address ranges, the new length is the old length + 1.

Fixes #36113.

Change-Id: I1b425f78e473cfa3cbdfe6113e166663f41fc9f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/211157
Run-TryBot: Cherry Zhang &lt;cherryyz@google.com&gt;
TryBot-Result: Gobot Gobot &lt;gobot@golang.org&gt;
Reviewed-by: Michael Knyszek &lt;mknyszek@google.com&gt;
</content>
</entry>
<entry>
<title>runtime: use inUse ranges to map in summary memory only as needed</title>
<updated>2019-12-11T19:51:34Z</updated>
<author>
<name>Michael Anthony Knyszek</name>
<email>mknyszek@google.com</email>
</author>
<published>2019-11-18T19:23:39Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=1b1fbb3192984624871ab92518499d4bd6e6e65c'/>
<id>urn:sha1:1b1fbb3192984624871ab92518499d4bd6e6e65c</id>
<content type='text'>
Prior to this change, if the heap was very discontiguous (such as in
TestArenaCollision) it's possible we could map a large amount of memory
as R/W and commit it. We would use only the start and end to track what
should be mapped, and we would extend that mapping as needed to
accomodate a potentially fragmented address space.

After this change, we only map exactly the part of the summary arrays
that we need by using the inUse ranges from the previous change. This
reduces the GCSys footprint of TestArenaCollision from 300 MiB to 18
MiB.

Because summaries are no longer mapped contiguously, this means the
scavenger can no longer iterate directly. This change also updates the
scavenger to borrow ranges out of inUse and iterate over only the
parts of the heap which are actually currently in use. This is both an
optimization and necessary for correctness.

Fixes #35514.

Change-Id: I96bf0c73ed0d2d89a00202ece7b9d089a53bac90
Reviewed-on: https://go-review.googlesource.com/c/go/+/207758
Run-TryBot: Michael Knyszek &lt;mknyszek@google.com&gt;
TryBot-Result: Gobot Gobot &lt;gobot@golang.org&gt;
Reviewed-by: Austin Clements &lt;austin@google.com&gt;
</content>
</entry>
<entry>
<title>runtime: track ranges of address space which are owned by the heap</title>
<updated>2019-12-11T19:37:19Z</updated>
<author>
<name>Michael Anthony Knyszek</name>
<email>mknyszek@google.com</email>
</author>
<published>2019-11-15T23:30:30Z</published>
<link rel='alternate' type='text/html' href='http://git.kilabit.info/go/commit/?id=9d78e75a0a55fd5ff3d68b4cba2f0395c4b5dc88'/>
<id>urn:sha1:9d78e75a0a55fd5ff3d68b4cba2f0395c4b5dc88</id>
<content type='text'>
This change adds a new inUse field to the allocator which tracks ranges
of addresses that are owned by the heap. It is updated on each heap
growth.

These ranges are tracked in an array which is kept sorted. In practice
this array shouldn't exceed its initial allocation except in rare cases
and thus should be small (ideally exactly 1 element in size).

In a hypothetical worst-case scenario wherein we have a 1 TiB heap and 4
MiB arenas (note that the address ranges will never be at a smaller
granularity than an arena, since arenas are always allocated
contiguously), inUse would use at most 4 MiB of memory if the heap
mappings were completely discontiguous (highly unlikely) with an
additional 2 MiB leaked from previous allocations. Furthermore, the
copies that are done to keep the inUse array sorted will copy at most 4
MiB of memory in such a scenario, which, assuming a conservative copying
rate of 5 GiB/s, amounts to about 800µs.

However, note that in practice:
1) Most 64-bit platforms have 64 MiB arenas.
2) The copies should incur little-to-no page faults, meaning a copy rate
   closer to 25-50 GiB/s is expected.
3) Go heaps are almost always mostly contiguous.

Updates #35514.

Change-Id: I3ad07f1c2b5b9340acf59ecc3b9ae09e884814fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/207757
Run-TryBot: Michael Knyszek &lt;mknyszek@google.com&gt;
TryBot-Result: Gobot Gobot &lt;gobot@golang.org&gt;
Reviewed-by: Cherry Zhang &lt;cherryyz@google.com&gt;
Reviewed-by: Austin Clements &lt;austin@google.com&gt;
</content>
</entry>
</feed>
