dgraph-io / ristretto

A high performance memory-bound Go cache
https://dgraph.io/blog/post/introducing-ristretto-high-perf-go-cache/
Apache License 2.0
5.54k stars 364 forks source link

[BUG]: <sync.Pool GC> #337

Closed AyangHuang closed 1 year ago

AyangHuang commented 1 year ago

What version of Ristretto are you using?

The next is sync.Pool source file.

// go/src/sync/pool.go

func init() {
    runtime_registerPoolCleanup(poolCleanup)
}

func poolCleanup() {
    // This function is called with the world stopped, at the beginning of a garbage collection.
    // It must not allocate and probably should not call any runtime functions.

    // Because the world is stopped, no pool user can be in a
    // pinned section (in effect, this has all Ps pinned).

    // Drop victim caches from all pools.
    for _, p := range oldPools {
        p.victim = nil
        p.victimSize = 0
    }

    // Move primary cache to victim cache.
    for _, p := range allPools {
        p.victim = p.local
        p.victimSize = p.localSize
        p.local = nil
        p.localSize = 0
    }

    // The pools with non-empty primary caches now have non-empty
    // victim caches and no pools have primary caches.
    oldPools, allPools = allPools, nil
}

What version of Go are you using?

none

Have you tried reproducing the issue with the latest release?

None

What is the hardware spec (RAM, CPU, OS)?

none

What steps will reproduce the bug?

none

Expected behavior and actual result.

none

Additional information

none