Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4650)

Issue 49460043: code review 49460043: runtime: fix 32-bit malloc for pointers >= 0x80000000 (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 3 months ago by iant
Modified:
10 years, 3 months ago
Reviewers:
rsc
CC:
golang-codereviews, rsc
Visibility:
Public.

Description

runtime: fix 32-bit malloc for pointers >= 0x80000000 The spans array is allocated in runtime·mallocinit. On a 32-bit system the number of entries in the spans array is MaxArena32 / PageSize, which (2U << 30) / (1 << 12) == (1 << 19). So we are allocating an array that can hold 19 bits for an index that can hold 20 bits. According to the comment in the function, this is intentional: we only allocate enough spans (and bitmaps) for a 2G arena, because allocating more would probably be wasteful. But since the span index is simply the upper 20 bits of the memory address, this scheme only works if memory addresses are limited to the low 2G of memory. That would be OK if we were careful to enforce it, but we're not. What we are careful to enforce, in functions like runtime·MHeap_SysAlloc, is that we always return addresses between the heap's arena_start and arena_start + MaxArena32. We generally get away with it because we start allocating just after the program end, so we only run into trouble with programs that allocate a lot of memory, enough to get past address 0x80000000. This changes the code that computes a span index to subtract arena_start on 32-bit systems just as we currently do on 64-bit systems.

Patch Set 1 #

Patch Set 2 : diff -r 97922776ba6f https://code.google.com/p/go #

Unified diffs Side-by-side diffs Delta from patch set Stats (+12 lines, -24 lines) Patch
M src/pkg/runtime/malloc.goc View 1 chunk +1 line, -2 lines 0 comments Download
M src/pkg/runtime/mgc0.c View 4 chunks +4 lines, -8 lines 0 comments Download
M src/pkg/runtime/mheap.c View 7 chunks +7 lines, -14 lines 0 comments Download

Messages

Total messages: 3
iant
Hello golang-codereviews@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go
10 years, 3 months ago (2014-01-09 01:52:05 UTC) #1
rsc
LGTM
10 years, 3 months ago (2014-01-09 21:18:34 UTC) #2
iant
10 years, 3 months ago (2014-01-09 23:00:03 UTC) #3
*** Submitted as https://code.google.com/p/go/source/detail?r=1d814e59a8df ***

runtime: fix 32-bit malloc for pointers >= 0x80000000

The spans array is allocated in runtime·mallocinit.  On a
32-bit system the number of entries in the spans array is
MaxArena32 / PageSize, which (2U << 30) / (1 << 12) == (1 << 19).
So we are allocating an array that can hold 19 bits for an
index that can hold 20 bits.  According to the comment in the
function, this is intentional: we only allocate enough spans
(and bitmaps) for a 2G arena, because allocating more would
probably be wasteful.

But since the span index is simply the upper 20 bits of the
memory address, this scheme only works if memory addresses are
limited to the low 2G of memory.  That would be OK if we were
careful to enforce it, but we're not.  What we are careful to
enforce, in functions like runtime·MHeap_SysAlloc, is that we
always return addresses between the heap's arena_start and
arena_start + MaxArena32.

We generally get away with it because we start allocating just
after the program end, so we only run into trouble with
programs that allocate a lot of memory, enough to get past
address 0x80000000.

This changes the code that computes a span index to subtract
arena_start on 32-bit systems just as we currently do on
64-bit systems.

R=golang-codereviews, rsc
CC=golang-codereviews
https://codereview.appspot.com/49460043
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b