Skip to content

Conversation

@dperny
Copy link
Contributor

@dperny dperny commented Nov 4, 2025

- What I did

Adds support for setting memory swap settings on Swarm services

  • Adds flags memory-swap and memory-swappiness to docker service create and docker service update commands.
  • Adds compose fields memswap_limit and mem_swappiness for docker stack commands.

- How I did it

Ran through all the plumbing as one does any time such a flag is added.

- How to verify it

Includes tests.

- Human readable description for the release notes

Add support for `memory-swap` and `memory-swappiness` flags to `docker service create` and `docker service update` commands.

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@dperny dperny force-pushed the swarm-memory-swap branch from 045f838 to 7fe1bc0 Compare November 4, 2025 16:00
Comment on lines 416 to 421
},
"memswap_limit": {
"type": "integer"
},
"mem_swappiness": {
"type": "integer"
Copy link
Member

@thaJeztah thaJeztah Nov 5, 2025

Choose a reason for hiding this comment

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

This probably needs a new version of the schema; to do so;

  • add a commit that adds a straight copy of the existing schema and update the default version
  • then apply this diff to the copy

Doing it in 2 commits helps making the diff reviewable

Copy link
Member

Choose a reason for hiding this comment

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

See this commit (and PR) for the steps;

thaJeztah and others added 2 commits November 7, 2025 00:24
Adds support for setting memory swap settings on Swarm services

* Adds flags `memory-swap` and `memory-swappiness` to `docker service
create` and `docker service update` commands.
* Adds compose fields `memswap_limit` and `mem_swappiness` for `docker
stack` commands.

Signed-off-by: Drew Erny <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@dperny we also need to have the compose-spec updated with this

cc @glours @ndeloof

@thaJeztah thaJeztah merged commit 5b443bf into docker:master Nov 7, 2025
109 of 110 checks passed

const (
defaultVersion = "3.13"
defaultVersion = "3.14"
Copy link
Contributor

Choose a reason for hiding this comment

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

:-1 this isn't relevant anymore with Compose specification

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the schema is optional in this implementation, but allows for downgrading to a specific version.

Copy link
Contributor

Choose a reason for hiding this comment

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

allows for downgrading to a specific version

Please clarify. The reason compose-spec was made "version-less" is exactly because such "downgrade" doesn't bring any value. There's no place in the many versions where an attribute definition changed - some where removed (but re-introduced in the compose-spec schema) but none had definition updated that would make "downgrading to a specific version" bring any value

@ndeloof
Copy link
Contributor

ndeloof commented Nov 7, 2025

some thoughts:

  • if CLI flag is --memory-swap compose file attribute should be memory_swap, not memswap_limit for consistency and discoverability
  • better first propose changes to the compose spec before making change to the schema in this repo
  • last but not least: any plan to eventually adopt the compose spec for Swarm ? see use compose-go to load and parse compose files #4863

@thaJeztah
Copy link
Member

if CLI flag is --memory-swap compose file attribute should be memory_swap, not memswap_limit for consistency and discoverability

Good call; let me update this; it didn't ship yet in a non-pre release, so we can update.

better first propose changes to the compose spec before making change to the schema in this repo

Noted. We had to make a call, and it was nearly 2AM 🙈 ; inclusion of this feature (at least in the API) was agreed on to be a release-blocker, but the CLI-side was not merged yet; I made preparations to split out the schema changes #6619 (comment), but didn't have time to remove the compose / stack changes separate, so we went ahead and brought this in for the RC.

I can either revert all compose changes, and only keep the CLI side, or if changing the names to memory_swap and memory_swappiness would be OK for the compose-spec, I can update those (then look at adding it to the compose-spec).

Let me at least start with those renames.

Limits *ResourceLimit `yaml:",omitempty" json:"limits,omitempty"`
Reservations *Resource `yaml:",omitempty" json:"reservations,omitempty"`
MemswapLimit *int64 `mapstructure:"memswap_limit" yaml:"memswap_limit,omitempty" json:"memswap_limit,omitempty"`
MemSwappiness *int64 `mapstructure:"mem_swappiness" yaml:"mem_swappiness,omitempty" json:"mem_swappiness,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why introduce those, while service definition already defines memswap_limit and mem_swappiness?
This duplication will just bring more confusion to the compose syntax

@ndeloof
Copy link
Contributor

ndeloof commented Nov 7, 2025

On the compose-spec side, deploy section only exists for being initially introduced for Docker Swarm, so whatever is made there would be ok. I'm just concerned we get (more) attribute duplicated into the deploy section for no obvious reason. As those already exists for ~ a decade at service level, I don't see any benefit to add more

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.

5 participants