Skip to content

MemoryWorker: use sanitizer info for allocated counter - #2349

Open
k-morozov wants to merge 7 commits into
antalya-26.6from
cas/memworker-split-allocated-source
Open

MemoryWorker: use sanitizer info for allocated counter#2349
k-morozov wants to merge 7 commits into
antalya-26.6from
cas/memworker-split-allocated-source

Conversation

@k-morozov

@k-morozov k-morozov commented Sep 11, 2026

Copy link
Copy Markdown

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

MemoryWorker now corrects MemoryTracker using allocated memory from ASan/TSan/MSan instead of resident memory in sanitizer builds when cgroups are available, fixing inaccurate memory accounting in such builds.

k-morozov and others added 2 commits September 11, 2026 11:07
Signed-off-by: Konstantin Morozov <just.morozov.k@gmail.com>
With jemalloc, `MemoryTracker::updateAllocated` gets the resident memory
from the current source (cgroup or jemalloc `stats.resident`), not jemalloc
`stats.allocated`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WUN1x2LvAoA4aBu4cevokZ
Signed-off-by: Konstantin Morozov <just.morozov.k@gmail.com>
@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown

Workflow [PR], commit [9460991]

@k-morozov

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-11T09:34:02.917284Z a51202b Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: a51202bf38

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@k-morozov
k-morozov marked this pull request as ready for review September 11, 2026 09:53
Signed-off-by: Konstantin Morozov <just.morozov.k@gmail.com>
Comment thread src/Common/MemoryWorker.cpp Outdated

#include <unistd.h>

#if defined(ADDRESS_SANITIZER)

@ianton-ru ianton-ru Sep 11, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this not required for memory and thread sanitizers?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

We discussed only ASAN and I decided to update logic only for it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do other sanitizers use less memory? @filimonov, we need help!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Msan was also failing, but since all 3 expose the same interface, probably it would be better to do the same for all

@k-morozov k-morozov Sep 11, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Do other sanitizers use less memory?

MSAN doesn't use redzones and its overhead (memory) is ussually less, TSAN builds shadow memory and vector clocks for sync primitives (more expensive).

Updated, MSAN and TSAN were added.


usage.allocated = usage.resident;
#if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || defined(MEMORY_SANITIZER)
usage.allocated = __sanitizer_get_current_allocated_bytes();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Am I right that
usage.resident - total memory usage from OS point of view (including sanitizer usage)
usage.allocated - "program" memory usage without sanitizer usage
?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

usage.allocated - "program" memory usage without sanitizer usage

Yes, without any additional allocation for sanitizers. For example redzones, shodow memory.

usage.allocated = usage.resident;
#if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || defined(MEMORY_SANITIZER)
usage.allocated = __sanitizer_get_current_allocated_bytes();
#endif

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Was warning about double assignment suppressed?
May be change on

#if defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER) || defined(MEMORY_SANITIZER)
    usage.allocated = __sanitizer_get_current_allocated_bytes();
#else
    usage.allocated = usage.resident;
#endif

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks. Updated.

Signed-off-by: Konstantin Morozov <just.morozov.k@gmail.com>
Signed-off-by: Konstantin Morozov <just.morozov.k@gmail.com>
Signed-off-by: Konstantin Morozov <just.morozov.k@gmail.com>
@ilejn

ilejn commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

It worth explaining in a comment why do we distinguish 'allocated' and 'resident' for sanitizers and in which cases use one or another.
Generally LGTM.

@ianton-ru

Copy link
Copy Markdown

Agree with @ilejn about comments with description for struct MemoryUsage.

Signed-off-by: Konstantin Morozov <just.morozov.k@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants