-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cgroups2: Reduce allocations for manager.Stat
This change works towards bringing down allocations for manager.Stat(). There's quite a few things we can do: 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. 3. Rework the type of map we stored these values in. We were using map[string]interface{} as some of the files can have a string of "max" inside, but we can be a little smarter about when to try converting to a uint64 so we don't need to store values as an interface{} which cut down on a few allocs. 4. Finally, and funnily enough the biggest win, was just not calling f.Readdir(-1) and swapping this for f.Readdirnames as it doesn't return a slice of interfaces. All in all on Go 1.19.4 this drops allocations in Stat from 324 to 230, or 33.94%. Signed-off-by: Danny Canter <danny@dcantah.dev>
- Loading branch information
Showing
5 changed files
with
129 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters