On Thu, Dec 11, 2025 at 10:14 AM Lidong Yan <[email protected]> wrote:
>
> Hi everyone, I am a newcomer reading Go runtime code, and I noticed that
> ```go
> type scavChunkData struct {
> // Only the first 10 bits are used.
> inUse uint16
>
> // Only the first 10 bits are used.
> lastInUse uint16
>
> // gen is the generation counter from a scavengeIndex from the
> // last time this scavChunkData was updated.
> gen uint32
>
> // Note: only 6 bits are available.
> scavChunkFlags
> }
> ```
>
> in scavChunkData, we only use 1-bit of scavChunkFlags to indicate whether 
> there is free pages in a chunk. This could be imprecise because we use the 
> following code to compute whether there are free pages,
> ```go
> nofree = inUse == pagesInChunk
> ```
>
> I think we could use a 10-bit counter to record how many pages are freed. Why 
> go use a 1-bit flag instead of a 10-bit counter? Is it for performance 
> reasons?

I don't know all the details here, but scavChunkData packs into a
64-bit value (see the pack method). That is useful because that 64-bit
value can be loaded and stored atomically. It works out that there are
only six bits available for scavChunkFlags, as the comment says. So a
10-bit counter isn't available.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVyppxSK96Qrvzg%2B3ReuQbjjhO2raSqjdEB_Gfp1XViNQ%40mail.gmail.com.

Reply via email to