Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cgroup2: Reduce allocations for manager.Stat #281

Merged
merged 2 commits into from
May 10, 2023

Commits on Apr 26, 2023

  1. Cgroups2: Reduce allocations for manager.Stat

    This change works towards bringing down allocations for manager.Stat().
    There's two things this change does:
    
    1. Swap to opening a file and issuing a single read for uint64/"max" values.
    Previously we were doing os.ReadFile's which returns a byte slice, so it needs
    to allocate.
    2. Sizing the map we store {controller}.stat values in. We store 40+ stats in this
    map and the default bucket size for Go seems to be smaller than this, so we'd incur
    a couple allocs at runtime when adding these.
    
    Signed-off-by: Danny Canter <danny@dcantah.dev>
    dcantah committed Apr 26, 2023
    Configuration menu
    Copy the full SHA
    92a7d65 View commit details
    Browse the repository at this point in the history

Commits on Apr 28, 2023

  1. Cgroup2: Reduce allocations in readHugeTlbStats

    In the journey of continuing to reduce allocations in manager.Stat,
    this sets its eyes on optimizing readHugeTlbStats. The number of allocs
    shaved off here is tied to the number of files in the cgroup directory
    as f.Readdir(-1) was being called which returns a slice of interfaces.
    To optimize this we can use a trick runc's cgroup code does which is to
    take advantage of the fact that we know exactly what files we need to
    open as they're fixed, the only variable portion is the hugepage sizes
    available on the host. To get around this we can compute the hugepage
    sizes in a sync.Once, and all future manager.Stat calls can reap the
    benefits as we don't need to Readdir() the entire cgroup path to search
    for hugetlb.pagesize.foobar's.
    
    This brings the total number of allocations on Go 1.19.4 down to 199 from
    the starting point of 322.
    
    Signed-off-by: Danny Canter <danny@dcantah.dev>
    Co-authored-by: Kir Kolyshkin <kolyshkin@gmail.com>
    dcantah and kolyshkin committed Apr 28, 2023
    Configuration menu
    Copy the full SHA
    a8621bd View commit details
    Browse the repository at this point in the history