Units for `--ulimit memlock` is counter intuitive
Issue Description
Description
From Linux, the units for memlock are in kb. However podman run --ulimit memlock appears to use bytes. Since I wasn't able to find podman documentation to indicate it uses bytes instead of kb, using this setting was counter intuitive.
Notes:
I have not tried other --ulimit settings that are based on size, but it appears at least a few others use kb in Linux and I'm guessing those may also be affected by this.
Steps to reproduce the issue
Using 4096 I expect to get 4096k but in the container, limits -a shows 4k for "max locked memory"
podman run --rm -it --ulimit memlock=4096 ubuntu
root@40f6f7125f2d:/# ulimit -a
real-time non-blocking time (microseconds, -R) unlimited
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 255054
max locked memory (kbytes, -l) 4
max memory size (kbytes, -m) unlimited
open files (-n) 524288
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 255054
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
I attempted adding a unit to the call like --ulimit memlock=4096kb or --ulimit memlock=4096k but that immediately fails:
podman run --rm -it --ulimit memlock=4096kb ubuntu
Error: ulimit option "memlock=4096kb" requires name=SOFT:HARD, failed to be parsed: strconv.ParseInt: parsing "4096kb": invalid syntax
Describe the results you received
Using --ulimit memlock=4096, limits -a shows 4 k for "max locked memory"
Describe the results you expected
Using --ulimit memlock=4096, I expect limits -a shows 4096 k for "max locked memory"
podman info output
host:
arch: s390x
buildahVersion: 1.33.8
cgroupControllers:
- memory
- pids
cgroupManager: systemd
cgroupVersion: v2
conmon:
package: conmon-2.1.10-1.el9.s390x
path: /usr/bin/conmon
version: 'conmon version 2.1.10, commit: c9210c60cb5abd93b5c667cfc268079ff6ae6d3c'
cpuUtilization:
idlePercent: 82.96
systemPercent: 1.01
userPercent: 16.03
cpus: 8
databaseBackend: sqlite
distribution:
distribution: rhel
version: "9.4"
eventLogger: file
freeLocks: 2048
hostname: <************>
idMappings:
gidmap:
- container_id: 0
host_id: 1024
size: 1
- container_id: 1
host_id: 1476256
size: 65536
uidmap:
- container_id: 0
host_id: 1022
size: 1
- container_id: 1
host_id: 1476256
size: 65536
kernel: 5.14.0-427.37.1.el9_4.s390x
linkmode: dynamic
logDriver: k8s-file
memFree: 4834336768
memTotal: 66918596608
networkBackend: netavark
networkBackendInfo:
backend: netavark
dns:
package: aardvark-dns-1.10.0-3.el9_4.s390x
path: /usr/libexec/podman/aardvark-dns
version: aardvark-dns 1.10.0
package: netavark-1.10.3-1.el9.s390x
path: /usr/libexec/podman/netavark
version: netavark 1.10.3
ociRuntime:
name: crun
package: crun-1.14.3-1.el9.s390x
path: /usr/bin/crun
version: |-
crun version 1.14.3
commit: 1961d211ba98f532ea52d2e80f4c20359f241a98
rundir: /run/user/1022/crun
spec: 1.0.0
+SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +YAJL
os: linux
pasta:
executable: ""
package: ""
version: ""
remoteSocket:
exists: false
path: /run/user/1022/podman/podman.sock
security:
apparmorEnabled: false
capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
rootless: true
seccompEnabled: true
seccompProfilePath: /usr/share/containers/seccomp.json
selinuxEnabled: true
serviceIsRemote: false
slirp4netns:
executable: /usr/bin/slirp4netns
package: slirp4netns-1.2.3-1.el9.s390x
version: |-
slirp4netns version 1.2.3
commit: c22fde291bb35b354e6ca44d13be181c76a0a432
libslirp: 4.4.0
SLIRP_CONFIG_VERSION_MAX: 3
libseccomp: 2.5.2
swapFree: 3976904704
swapTotal: 4831834112
uptime: 211h 1m 38.00s (Approximately 8.79 days)
variant: ""
plugins:
authorization: null
log:
- k8s-file
- none
- passthrough
- journald
network:
- bridge
- macvlan
- ipvlan
volume:
- local
registries:
search:
- registry.access.redhat.com
- registry.redhat.io
- docker.io
store:
configFile: <************>
containerStore:
number: 0
paused: 0
running: 0
stopped: 0
graphDriverName: overlay
graphOptions: {}
graphRoot: <************>
graphRootAllocated: 4003169959936
graphRootUsed: 749845946368
graphStatus:
Backing Filesystem: extfs
Native Overlay Diff: "true"
Supports d_type: "true"
Supports shifting: "false"
Supports volatile: "true"
Using metacopy: "false"
imageCopyTmpDir: <************>
imageStore:
number: 1
runRoot: /run/user/1022/containers
transientStore: false
volumePath: <************>
version:
APIVersion: 4.9.4-rhel
Built: 1723107071
BuiltTime: Thu Aug 8 03:51:11 2024
GitCommit: ""
GoVersion: go1.21.11 (Red Hat 1.21.11-1.el9_4)
Os: linux
OsArch: linux/s390x
Version: 4.9.4-rhel
Podman in a container
No
Privileged Or Rootless
Rootless
Upstream Latest Release
No
Additional environment details
No response
Additional information
Limits.conf doc pages showing memlock as kb
- https://www.man7.org/linux/man-pages/man5/limits.conf.5.html
- https://linux.die.net/man/5/limits.conf
- https://wiki.archlinux.org/title/Limits.conf
Hi @cjvolzka,
Thanks for the detailed report — the confusion is understandable, but I traced this through the codebase and I don't think it's a bug. Here's the root cause:
What's happening
--ulimit values flow through essentially unmodified:
pkg/specgenutil/specgen.goparses the flag withunits.ParseUlimit()— a plainstrconv.ParseInt, no unit suffixes or scaling.- The result lands directly in
specs.POSIXRlimit{Soft, Hard}in the OCI spec. - The runtime applies it via
setrlimit(2).
Per getrlimit(2), RLIMIT_MEMLOCK is specified in bytes. So --ulimit memlock=4096 correctly sets a 4096-byte limit.
The 4 you're seeing is a display artifact, not an input problem. ulimit -a rescales several resources for readability — dividing by 1024 for -l, -d, -m, -s, -v, and by 512 for -c, -f. So 4096 bytes prints as 4 kbytes.
Your own output actually proves this: POSIX message queues (bytes, -q) 819200 — RLIMIT_MSGQUEUE is also byte-valued, but bash has no divisor for -q, so it prints the raw value. Same pipeline, different display divisor.
On the limits.conf references: that's pam_limits(8), a separate subsystem with its own config-file conventions — it's not the interface --ulimit targets, so those units don't carry over here.
Why we shouldn't change the units
Reinterpreting memlock=4096 as kilobytes would silently shift every existing memlock/stack/core/fsize/rss config by 1024× — no error, no warning. It would also break Docker CLI parity, containers.conf default_ulimits, Quadlet Ulimit=, and the kube ulimit annotation. Not worth the compat risk.
Proposed fix — docs only
Update docs/source/markdown/options/ulimit.md (shared across run/create/update/Quadlet man pages):
- State that size-based types take bytes, per
setrlimit(2). - Add a unit table:
| Type | --ulimit input |
ulimit -a display |
|---|---|---|
core, fsize |
bytes | 512-byte blocks |
data, memlock, rss, stack |
bytes | kbytes |
msgqueue |
bytes | bytes |
rttime |
microseconds | microseconds |
cpu |
seconds | seconds |
locks, nofile, nproc, sigpending, nice, rtprio |
count/value | same |
- Worked example:
--ulimit memlock=4194304→ulimit -lreads4096.
On unit suffixes (memlock=4m)
Reasonable enhancement, but shouldn't be patched into Podman alone — parsing is fanned out across pkg/specgenutil, pkg/specgen/generate/kube, containers.conf validation in go.podman.io/common, and Buildah's ulimit parser. Fixing one would mean podman run accepts suffixes while podman build and containers.conf reject them. If wanted, it should land once upstream in go.podman.io/common, and needs a decision on non-byte types first (does nofile=1k mean 1000 files, or error?).
If the docs-only scope looks right, I can put up the PR.
I'm ok with a doc only update.
Definitely agreed on not changing the behavior for when units are not explicitly set. That would likely break an untold number of scripts and would be very user unfriendly.
Making the CLI recognize explicit units would be a "would be nice" but not a requirement. That was just a suggestion if it was easy but it sounds like it would be a fair scale effort.
Having the docs clarify what's happening would be just fine. It might still trip up someone trying it blind the first time, but after that doesn't work that way, people are more likely to then actually read the related doc and quickly adjust. Ideally the appropriate part of the man podman page would also have some short blurb about the units that differ from shell defaults or even a small "see full docs for units used" would be just fine as that gives a clue the units might not be obvious.
Regardless which way the fix goes, thank you so much for taking a look at this!