question about TestPageAllocAlloc, AllFree1

53 views
Skip to first unread message

Leah Stapleton

unread,
May 7, 2024, 6:49:56 AMMay 7
to golang-nuts
I have a question about scavenging arising one of the runtime tests in runtime/mpagealloc.go. The test in question is the " AllFree1" test case in TestPageAllocAlloc.

According to my understanding, in the runtime, there is a distinction between reclaiming memory and scavenging memory.  Reclaiming memory is reusing free memory for allocations while scavenging is returning memory back to the OS that is no longer needed by the application.

Step 1. the test starts off by setting up some scavenging state by scavening one page at index 0, and two pages starting at index two

scav: map[ChunkIdx][]BitRange{
BaseChunkIdx: {{0, 1}, {2, 2}},
},
If you inspect the bitmap, you can see the scavenged pages set starting at the appropriate index

0000000000000000000000000000000000000000000000000000000000001101


Step 2. It then allocates 5 pages in succession
for iter, i := range v.5hits {
   address, scav := b.Alloc(i.npages)
}

Step 3. Afterwards, if you print the bits you can see the five allocations in the first positions

The 5 allocations

0000000000000000000000000000000000000000000000000000000000011111


The corresponding scavenged bit map is all set to 0, so the allocations used the scavenged pages:


0000000000000000000000000000000000000000000000000000000000000000


So my question is....is that "scavenging" or more properly "reclaiming"? The allocations occupy the positions that were previously scavenged, so I'm guessing the memory has been re-used (in the logic of the test) rather than returned to the OS. 



Reply all
Reply to author
Forward
0 new messages