cli icon indicating copy to clipboard operation
cli copied to clipboard

cli/compose: memswap_limit -> memory_swap, mem_swappiness -> memory_swappiness

Open thaJeztah opened this issue 1 month ago • 6 comments

  • follow-up to https://github.com/docker/cli/pull/6619

Align the names in the compose / stack schema with the command-line flags, instead of aligning with the existing options in the compose-schema (which I think originated from v1); https://github.com/compose-spec/compose-spec/blob/a08f8d51631b7127ddac3d2c65537db429d0f1d0/spec.md?plain=1#L1440-L1461

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes



- A picture of a cute animal (not mandatory but encouraged)

thaJeztah avatar Nov 07 '25 14:11 thaJeztah

@ndeloof I'm guessing the naming originated from what was already in the compose-spec at a different place; https://github.com/compose-spec/compose-spec/blob/a08f8d51631b7127ddac3d2c65537db429d0f1d0/spec.md?plain=1#L1440-L1461

Would there be a motivation to align with those, or just go with this one?

## mem_swappiness

`mem_swappiness` defines as a percentage, a value between 0 and 100, for the host kernel to swap out
anonymous memory pages used by a container.

- `0`: Turns off anonymous page swapping.
- `100`: Sets all anonymous pages as swappable.

The default value is platform specific.

## memswap_limit

`memswap_limit` defines the amount of memory the container is allowed to swap to disk. This is a modifier
attribute that only has meaning if [`memory`](deploy.md#memory) is also set. Using swap lets the container write excess
memory requirements to disk when the container has exhausted all the memory that is available to it.
There is a performance penalty for applications that swap memory to disk often.

- If `memswap_limit` is set to a positive integer, then both `memory` and `memswap_limit` must be set. `memswap_limit` represents the total amount of memory and swap that can be used, and `memory` controls the amount used by non-swap memory. So if `memory`="300m" and `memswap_limit`="1g", the container can use 300m of memory and 700m (1g - 300m) swap.
- If `memswap_limit` is set to 0, the setting is ignored, and the value is treated as unset.
- If `memswap_limit` is set to the same value as `memory`, and `memory` is set to a positive integer, the container does not have access to swap.
- If `memswap_limit` is unset, and `memory` is set, the container can use as much swap as the `memory` setting, if the host container has swap memory configured. For instance, if `memory`="300m" and `memswap_limit` is not set, the container can use 600m in total of memory and swap.
- If `memswap_limit` is explicitly set to -1, the container is allowed to use unlimited swap, up to the amount available on the host system.

thaJeztah avatar Nov 07 '25 14:11 thaJeztah

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests.

:loudspeaker: Thoughts on this report? Let us know!

codecov-commenter avatar Nov 07 '25 14:11 codecov-commenter

The flags align with the ones on docker run, docker create

  -m, --memory bytes                     Memory limit
      --memory-reservation bytes         Memory soft limit
      --memory-swap bytes                Swap limit equal to memory plus swap: '-1' to enable
                                         unlimited swap
      --memory-swappiness int            Tune container memory swappiness (0 to 100) (default -1)

And docker update;

  -m, --memory bytes               Memory limit
      --memory-reservation bytes   Memory soft limit
      --memory-swap bytes          Swap limit equal to memory plus swap: -1 to enable unlimited swap

The new ones are on docker service create / docker service update;

      --memory-swap bytes                  Swap Bytes (-1 for unlimited)
      --memory-swappiness int              Tune memory swappiness (0-100), -1 to reset to default
                                           (default -1)

thaJeztah avatar Nov 07 '25 21:11 thaJeztah

oh indeed, I guess it's to late to complain on https://github.com/docker/compose/issues/2383 that the compose attribute should align with CLI flags 🥲

ndeloof avatar Nov 07 '25 21:11 ndeloof

Thanks, @thaJeztah, for doing this.

dperny avatar Nov 10 '25 16:11 dperny

Pending the discussion; we may need to go ahead with https://github.com/docker/cli/pull/6642 first, then move from there; would that be OK for you, @dperny ?

thaJeztah avatar Nov 10 '25 17:11 thaJeztah