-
Notifications
You must be signed in to change notification settings - Fork 2
implement soft memory limit for docker to use when invoking cpp2v #103
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
Open
simon-skylabs
wants to merge
1
commit into
main
Choose a base branch
from
simon/cpp2v-docker-mem-cap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| REALPATH=$(which grealpath || which realpath) | ||
| SED=$(which gsed || which sed) | ||
| REL_PATH="$($REALPATH `pwd` --relative-to "$DUNE_SOURCEROOT")" | ||
|
|
||
| map_absolute_paths () { | ||
|
|
@@ -46,6 +47,15 @@ if [ "$CPP2V_DOCKER_ENABLED" = "y" ] && ! which docker > /dev/null; then | |
| : | ||
| fi | ||
|
|
||
| units () { | ||
| local pat='s/G/000M/;s/M/000K/;s/K/000B/;s/B//g' | ||
| if [[ $# -eq 1 ]]; then | ||
| echo "$1" | $SED $pat | ||
| else | ||
| $SED $pat | ||
| fi | ||
| } | ||
|
|
||
| if [ "$CPP2V_DOCKER_ENABLED" = "y" ] && which docker > /dev/null; then | ||
| if [ -z "$CPP2V_DOCKER_IMAGE" ]; then | ||
| # We skip the warning if no docker is available | ||
|
|
@@ -61,6 +71,21 @@ if [ "$CPP2V_DOCKER_ENABLED" = "y" ] && which docker > /dev/null; then | |
| ARGS+=( "--workdir" "$BRICK_LIBCPP/$REL_PATH" ) | ||
| ARGS+=( $(map_absolute_paths "$@") ) | ||
|
|
||
| if [[ -n "$CPP2V_DOCKER_MEM_CAP" ]]; then | ||
| MEM_CAP=$(units $CPP2V_DOCKER_MEM_CAP) | ||
| if ! [[ $MEM_CAP =~ [0-9]+ ]]; then | ||
| echo "Misconfiguration: CPP2V_DOCKER_MEM_CAP = '$CPP2V_DOCKER_MEM_CAP', invalid memory amount" | ||
| exit 2 | ||
| fi | ||
| while true; do | ||
| used_mem=$(docker stats --no-stream --format "{{.MemUsage}}" | awk '{print $1}' | head -n 1 | units) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is printing the memory usage of the first container in the list. That can't be good. |
||
| if [[ "$used_mem" -lt $MEM_CAP ]]; then | ||
| break | ||
| fi | ||
| sleep 0.01 | ||
| done | ||
| fi | ||
|
|
||
| cpp2v_args="$( printf '"%q" ' "$@" )" # ensure each argument is quoted as a whole. | ||
| docker run "${ARGS[@]}" "$CPP2V_DOCKER_IMAGE" \ | ||
| /bin/bash -c 'eval $(opam env)'"; cpp2v $cpp2v_args" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this belongs to the user environment, not the static config...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I'd provide a sensible default or any easy way to turn it on. We could comment it out and let the user uncomment and change it they want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather keep customizations out of
duneas far as possible, so there's less to merge. People canexport CPP2V_DOCKER_MEM_CAP=5GBin their normal configs if they want to. Having to configure it twice in dune syntax, and merge customizations with upstream changes, seems a bit too much.Ideally,
duneshould either not exist or coincide withdune.disabled. Not sure about "if-libstdc++".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I think the only sensible default is off — "wait for ~5GB free to start cpp2v" makes some sense, but if I give 40GB to Docker, that means
CPP2V_DOCKER_MEM_CAPshould be 35GB.Anyway, I wanted to approve and merging this for now ASAP, but I noticed other things that need tweaking.