<p dir="auto">As noted in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="99777054" data-permission-text="Title is private" data-url="https://github.com/golang/go/issues/12076" data-hovercard-type="issue" data-hovercard-url="/golang/go/issues/12076/hovercard" href="https://github.com/golang/go/issues/12076">#12076</a> Getpagesize doesn't currently return the actual system's default page size, but rather a hard-coded value.  Per the discussion with <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ianlancetaylor/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ianlancetaylor">@ianlancetaylor</a> on golang-dev [1], the opinion was that syscall.Getpagesize should return the same value as the POSIX call sysconf(_SC_PAGESIZE).</p>
<p dir="auto">This change will be necessary for future platform support on Solaris.</p>
<p dir="auto">While this change could be generally applied (more than likely) to all other POSIX platforms, I'm only planning on making this change for Solaris for now.</p>
<p dir="auto">This issue is being filed to track the change against golang/go separately from x/sys/unix.</p>
<p dir="auto">While it may be viewed as related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="62197372" data-permission-text="Title is private" data-url="https://github.com/golang/go/issues/10180" data-hovercard-type="issue" data-hovercard-url="/golang/go/issues/10180/hovercard" href="https://github.com/golang/go/issues/10180">#10180</a>, I believe it can be resolved independently.</p>
<p dir="auto">[1] <a href="https://groups.google.com/forum/#!topic/golang-dev/ZLzxYzULzU8" rel="nofollow">https://groups.google.com/forum/#!topic/golang-dev/ZLzxYzULzU8</a></p>
<p dir="auto">At least three problems here:<br>
<code class="notranslate">1</code>. cmd/ld INITRND needs to be at least as large as the page size, otherwise<br>
we might trigger kernel bugs. See <a href="https://groups.google.com/forum/#!topic/golang-nuts/29RraQ-t3gc" rel="nofollow">https://groups.google.com/forum/#!topic/golang-nuts/29RraQ-t3gc</a><br>
for a case.</p>
<p dir="auto">However, just using a larger INITRND value will make the binary bigger because<br>
of the zero padding between segments.</p>
<p dir="auto">I think we can have a way to have a much larger INITRND without increasing<br>
the size of the binary by leaving a VM hole between the segments.<br>
(e.g. text segment ends at <code class="notranslate">N*INITRND + x</code>, then we make the next segment's<br>
load address start at <code class="notranslate">(N+1)*INITRND + x + 1</code>, so there is no hole in the file, but<br>
different segments end up on different pages (if <code class="notranslate">INITRND &gt;= page size</code>).</p>
<p dir="auto"><code class="notranslate">2</code>. _PhysPageSize in runtime needs to be a variable and auto detected<br>
at process start up. This might incur a performance overhead, but as the<br>
proliferation of non-4K page size systems (power64, arm, arm64), we should<br>
make the change to continue the Go tradition that it just works without extra<br>
tuning. At least, we should make cmd/dist detect page size and tune the<br>
const in runtime.</p>
<p dir="auto"><code class="notranslate">3</code>. syscall.Getpagesize should return the value in the runtime. Right now,<br>
it's hardcoded on all systems.</p>