Skip to content

DNM: test#4499

Open
dustymabe wants to merge 3 commits intocoreos:mainfrom
dustymabe:dusty-dnm
Open

DNM: test#4499
dustymabe wants to merge 3 commits intocoreos:mainfrom
dustymabe:dusty-dnm

Conversation

@dustymabe
Copy link
Member

No description provided.

The cgroup available memory calculation used memory.current (total
cgroup usage) directly, which includes page cache (file-backed memory).
Since page cache is reclaimable by the kernel under memory pressure, it
should not count as unavailable. This caused GetCurrentMemAvailableMiB()
to significantly underestimate available memory, making QEMU instance
scheduling overly conservative.

Read the "file" field from /sys/fs/cgroup/memory.stat, which reports
the page cache size in bytes, and subtract it from current usage before
computing available memory. The effective formula becomes:

  available = limit - (current - page_cache)

This mirrors how /proc/meminfo computes MemAvailable by considering
reclaimable caches.

A new helper getCgroupMemoryStatField() is added for parsing individual
fields from memory.stat, returning 0 gracefully if the file or field is
absent.

Written-by: <anthropic/claude-opus-4.6>
Let's pass in a boolean and also warn on the first wait and then
periodically after that.
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors memory reservation logging in mantle/kola/harness.go to provide earlier warnings, and improves the accuracy of available memory calculation in cgroup environments in mantle/system/nproc.go by accounting for reclaimable page cache. The changes are well-implemented and improve both logging behavior and correctness. I have one minor suggestion to simplify an error handling block to follow a more common Go idiom.

Comment on lines +238 to +242
if os.IsNotExist(err) {
return 0, nil
} else if err != nil {
return 0, fmt.Errorf("reading memory.stat: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This error handling block can be simplified to a more common Go idiom by checking for err != nil first, and then handling the specific os.IsNotExist case within that block. This can improve readability.

Suggested change
if os.IsNotExist(err) {
return 0, nil
} else if err != nil {
return 0, fmt.Errorf("reading memory.stat: %w", err)
}
if err != nil {
if os.IsNotExist(err) {
return 0, nil
}
return 0, fmt.Errorf("reading memory.stat: %w", err)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant