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

Add containerized linux memory manager #22997

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mohsaka
Copy link
Contributor

@mohsaka mohsaka commented Jun 12, 2024

Description

This PR helps shrink memory usage when we detect at the system level that Prestissimo is running out of
memory.

This PR implements a LinuxMemoryChecker which can be enabled by setting the CMake flag PRESTO_MEMORY_CHECKER_TYPE=LINUX_MEMORY_CHECKER.

We currently are using this memory manager for our deployments to prevent OOMKills. It has been well tested on CentOS.

Note that mallocBytes, periodicCb, heapDumpCb, removeDumpFile are not supported.

LinuxMemoryChecker:
We are currently using inactive_anon + active_anon to track the current system memory usage.

Our first attempt was using memInfo memTotal - memAvailable. However memInfo is not containerized so we reserve this as a last resort.

Next we tried to use what docker/kubernetes uses for their calculation. cgroup usage_in_bytes - total_inactive_files. However we found out that usage_in_bytes is a fuzz value and has a chance for the sync to occur after the shrink polling interval. This would result in double shrinks.

Therefore we decided on values from the memory.stat file that are real time statistics. At first we tried to use the calculation suggested by the kernel team RSS+CACHE(+SWAP). However we noticed that this value was not closely related to the value in usage_in_bytes which is used to OOMKill. We then looked at all of the values in the stat file and decided that inactive_anon + active_anon moves closest to that of usage_in_bytes

NOTE: We do not know if cgroup V2 memory.current is a fuzz value. It may be better than what we currently use. For consistency we will match cgroup V1 and change if necessary.

Motivation and Context

Impact

Test Plan

Contributor checklist

  • Please make sure your submission complies with our development, formatting, commit message, and attribution guidelines.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== RELEASE NOTES ==

General Changes
* ... :pr:`12345`
* ... :pr:`12345`

Hive Connector Changes
* ... :pr:`12345`
* ... :pr:`12345`

If release note is NOT required, use:

== NO RELEASE NOTE ==

@mohsaka mohsaka self-assigned this Jun 12, 2024
@mohsaka mohsaka requested a review from a team as a code owner June 12, 2024 23:35
Copy link
Contributor

@czentgr czentgr left a comment

Choose a reason for hiding this comment

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

Thanks for adding this!

Copy link

linux-foundation-easycla bot commented Jul 19, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: minhancao / name: Minhan Cao (ae622b4)
  • ✅ login: mohsaka (40a3a63)

@minhancao minhancao self-assigned this Jul 19, 2024
@minhancao minhancao force-pushed the linux-memory-manager branch 2 times, most recently from 53b5e8e to 772fd86 Compare July 23, 2024 21:12
Copy link
Contributor

@czentgr czentgr left a comment

Choose a reason for hiding this comment

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

Thank you. Please squash the commits into a single commit and rebase.

@minhancao minhancao force-pushed the linux-memory-manager branch 2 times, most recently from 233ea59 to 0007587 Compare July 30, 2024 19:58
Copy link
Contributor

@czentgr czentgr left a comment

Choose a reason for hiding this comment

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

@majetideepak Can you please also take a look when you get a chance?

presto-native-execution/presto_cpp/main/PrestoServer.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

Thanks @minhancao and @mohsaka. Have some comments related to this code.

Copy link
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

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

Thanks for the doc! Only a few nits of suggested formatting and phrasing.

presto-docs/src/main/sphinx/presto_cpp/features.rst Outdated Show resolved Hide resolved
presto-docs/src/main/sphinx/presto_cpp/features.rst Outdated Show resolved Hide resolved
steveburnett
steveburnett previously approved these changes Aug 9, 2024
Copy link
Contributor

@steveburnett steveburnett left a comment

Choose a reason for hiding this comment

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

LGTM! (docs)

Pull updated branch, new doc build. Thanks!

@majetideepak
Copy link
Collaborator

I have some feedback on this. I will complete the review by EOD.

@czentgr
Copy link
Contributor

czentgr commented Aug 14, 2024

@minhancao Can you please squash the commits into a single commit?

Copy link
Contributor

@czentgr czentgr left a comment

Choose a reason for hiding this comment

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

One more minor fix in the doc. Rest looks good.

presto-docs/src/main/sphinx/presto_cpp/properties.rst Outdated Show resolved Hide resolved
czentgr
czentgr previously approved these changes Oct 7, 2024
Copy link
Contributor

@czentgr czentgr left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks!

@minhancao
Copy link

@bikramSingh91 The comments are all now addressed and is ready to merge. Please take another look when you can, thanks!

@bikramSingh91
Copy link
Contributor

bikramSingh91 commented Oct 7, 2024

@bikramSingh91 The comments are all now addressed and is ready to merge. Please take another look when you can, thanks!

Looks good to me!

@majetideepak
Copy link
Collaborator

@xiaoxmeng, @bikramSingh91 can you please import this again?
Meta CI is required and is failing.
Meta Internal-Only Changes Check — The Diff and Pull Request are not in sync!

xiaoxmeng
xiaoxmeng previously approved these changes Oct 8, 2024
@xiaoxmeng
Copy link
Contributor

@xiaoxmeng, @bikramSingh91 can you please import this again? Meta CI is required and is failing. Meta Internal-Only Changes Check — The Diff and Pull Request are not in sync!

@majetideepak @bikramSingh91 will take care once this change is landed on github.

@majetideepak
Copy link
Collaborator

@tdcmeehan can you please approve and help land this? It looks like a committer approval is needed. Thanks.

tdcmeehan
tdcmeehan previously approved these changes Oct 8, 2024
@majetideepak
Copy link
Collaborator

@xiaoxmeng You need to import it to get this to land. A required CI test is failing
Internal-Only Changes Check — The Diff and Pull Request are not in sync!

Copy link
Collaborator

@majetideepak majetideepak left a comment

Choose a reason for hiding this comment

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

We saw an issue with this internally. I will update once this is fixed.

@czentgr
Copy link
Contributor

czentgr commented Oct 9, 2024

Please also rebase this PR.

@minhancao minhancao force-pushed the linux-memory-manager branch 2 times, most recently from 1b93112 to 1b03a96 Compare October 9, 2024 19:55
czentgr
czentgr previously approved these changes Oct 9, 2024
Copy link
Contributor

@czentgr czentgr left a comment

Choose a reason for hiding this comment

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

Thank you!

if (boost::regex_match(line.data(), match, regex)) {
if (match.size() > 1) {
std::string numStr(match[1].str());
return std::stoul(numStr);
Copy link
Contributor

@czentgr czentgr Oct 10, 2024

Choose a reason for hiding this comment

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

This is incorrect. This will return a 32-bit integer which will overflow and is limited. Errno could be set to indicate a truncation warning.
It either needs to be std::stroull or use the original folly::to<size_t>(numStr);.

Copy link

@minhancao minhancao Oct 10, 2024

Choose a reason for hiding this comment

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

Thanks for the catch! Changing to use folly::to<size_t>(numStr);

@minhancao minhancao dismissed stale reviews from majetideepak and czentgr via 1ea7b0a October 10, 2024 17:09
@minhancao minhancao force-pushed the linux-memory-manager branch 2 times, most recently from 1ea7b0a to 40a3a63 Compare October 10, 2024 18:39
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.

10 participants