Skip to content

Conversation

@wk8
Copy link
Contributor

@wk8 wk8 commented Sep 12, 2018

- What I did

API change to support memory-swap and memory-swappiness settings on services

- How I did it

Added the two new fields to the protobuf definition

- How to test it

N/A, this is not used in swarkit. Follow-up PR to come on moby/moby

- Description for the changelog

Added support for tuning swap in services. This is equivalent to docker run's --memory-swap and --memory-swappiness flags.

@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ git clone -b "wk8/memory_flags" [email protected]:wk8/swarmkit.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842354427968
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

@wk8 wk8 changed the title Wk8/memory flags Adding support for swap settings Sep 12, 2018
@codecov
Copy link

codecov bot commented Sep 12, 2018

Codecov Report

Merging #2747 into master will increase coverage by 0.14%.
The diff coverage is n/a.

@@            Coverage Diff            @@
##           master   #2747      +/-   ##
=========================================
+ Coverage   61.75%   61.9%   +0.14%     
=========================================
  Files         134     134              
  Lines       21890   21890              
=========================================
+ Hits        13518   13550      +32     
+ Misses       6905    6884      -21     
+ Partials     1467    1456      -11

int64 memory_swap = 27;

// Tune container memory swappiness (0 to 100) (default -1)
google.protobuf.Int64Value memory_swappiness = 28;
Copy link
Contributor

Choose a reason for hiding this comment

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

why 0 to 100? nit: maybe add a comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

also, curious why Int64Value instead of int64?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lazily copied from docker run's help message: --memory-swappiness int Tune container memory swappiness (0 to 100) (default -1) :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

what's the difference between google.protobuf.Int64Value and the int64 above it? Does it make this compile to *int64 in practice?

Copy link
Collaborator

Choose a reason for hiding this comment

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

at first, i was 🤔 🤔 🤔 about google.protobuf.Int64Value, but now I see that there is a pretty substantial semantic difference between set and not set for this value, and Int64Value is probably cleaner than a pointer, even if we can hack a pointer into the compiled proto (which we can, I think).

LGTM.

Copy link
Collaborator

Choose a reason for hiding this comment

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

And even if Int64Value was a pain in the butt, it's not like we do anything with it other than pass it down into the docker engine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@anshulpundir "what does (default -1) mean? Where is the default set?" => I guess somewhere deeper in moby?

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to specify that default value here then? What does the default value mean mean to the API consumer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

map<string, string> sysctls = 26;

// Swap limit equal to memory plus swap: '-1' to enable unlimited swap
int64 memory_swap = 27;
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we not need google.protobuf.Int64Value for this field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

right. if I don't want to change previously set memory swap value, how do I specify that?
Basically, why does memory_swappiness need to be nullable but memory_swap does not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"if I don't want to change previously set memory swap value, how do I specify that?" => I think that's the same for all the params here:

  • moby's API does expect a full service spec for both creates and updates, you can't just PATCH an existing service
  • if your services are created/updated using docker-compose.yml file, then you have all the params in there, and they will all be around when updating
  • if you use the CLI, then it's responsible for fetching the current service spec and merging with the new params (https://github.com/docker/cli/blob/master/cli/command/service/update.go#L239-L482); arguably it would be nice to have the API handle that eventually?

So in particular, memory_swappiness doesn't need to be nullable... It just seems good to be consistent with moby's container spec struct?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok cool lets move forward as is for consistency.

@wk8 wk8 force-pushed the wk8/memory_flags branch 3 times, most recently from 1fb3a3a to bc0eadf Compare September 17, 2018 22:53
@anshulpundir
Copy link
Contributor

LGMT!

@dperny dperny merged commit 7da74a7 into moby:master Sep 22, 2018
wk8 added a commit to wk8/moby that referenced this pull request Sep 24, 2018
With integration tests

Relevant Swarmkit PR: moby/swarmkit#2747
(updated the vendored version of Swarkit to that)

Signed-off-by: Jean Rouge <[email protected]>
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.

4 participants