Add memory swap to swarm

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 <derny@mirantis.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Drew Erny
2025-11-04 09:12:26 -06:00
committed by Sebastiaan van Stijn
parent d0c86d39ef
commit 71828f2792
13 changed files with 98 additions and 11 deletions

View File

@ -560,6 +560,10 @@ func convertResources(source composetypes.Resources) (*swarm.ResourceRequirement
GenericResources: generic,
}
}
// These fields are themselves pointers -- we can simply assign, no need to
// nil-check them. Nil is nil.
resources.SwapBytes = source.MemswapLimit
resources.MemorySwappiness = source.MemSwappiness
return resources, nil
}

View File

@ -81,6 +81,9 @@ func TestConvertExtraHosts(t *testing.T) {
}
func TestConvertResourcesFull(t *testing.T) {
// create some variables so we can get pointers
memswap := int64(72090)
swappiness := int64(27)
source := composetypes.Resources{
Limits: &composetypes.ResourceLimit{
NanoCPUs: "0.003",
@ -90,6 +93,8 @@ func TestConvertResourcesFull(t *testing.T) {
NanoCPUs: "0.002",
MemoryBytes: composetypes.UnitBytes(200000000),
},
MemswapLimit: &memswap,
MemSwappiness: &swappiness,
}
resources, err := convertResources(source)
assert.NilError(t, err)
@ -103,6 +108,8 @@ func TestConvertResourcesFull(t *testing.T) {
NanoCPUs: 2000000,
MemoryBytes: 200000000,
},
SwapBytes: &memswap,
MemorySwappiness: &swappiness,
}
assert.Check(t, is.DeepEqual(expected, resources))
}