what happened? on a system with 4GB of RAM x11vnc refused to start with error:
shmget fails: No space left on device
# reboot could solve that problem... are we at this point where GNU Linux just as Windows needs frequent reboots to fix problems # that are results from too much software complexity? :( # if reboot is not an option (right now) try this and schedule reboot for later: sysctl -a | grep shm kernel.shm_next_id = -1 kernel.shm_rmid_forced = 0 kernel.shmall = 18446744073692774399 kernel.shmmax = 18446744073692774399 kernel.shmmni = 4096 <- this is what will be increased vm.hugetlb_shm_group = 0 echo 'kernel.shmmni = 8192' >> /etc/sysctl.conf sysctl -p /etc/sysctl.conf # afterwards x11vnc starts without problems X-D
what AI has to say about it: (WARNING! COULD BE WRONG!)
what’s the problem?
Possible causes include failed shared memory allocation due to kernel limits or full disk spaces. I’ll suggest commands like `df -h /dev/shm`, `ipcs -m`, and `sysctl kernel.shmmax` for checking this space. The steps will involve verifying `/dev/shm`, adjusting sizes, and rebooting if needed. Keeping it all concise is key!It’s the OS error ENOSPC from shmget(2): the kernel refused to create or attach a System V shared-memory segment because there’s no available “space” for it. Common causes and fixes:
Causes
– /dev/shm (tmpfs) is full.
– Kernel System V shared-memory limits reached (kernel.shmmax, kernel.shmall, or number of segments).
– Too many orphaned shared-memory segments left by processes.
– Container or cgroup tmpfs quota too small.
Quick checks (run as root or with sudo)
– Check tmpfs usage: df -h /dev/shm
– List System V segments: ipcs -m
– Check kernel limits: sysctl kernel.shmmax kernel.shmall
– Check overall memory usage: free -h
Fixes
– Free space in /dev/shm: remove unused files or unmount/remount tmpfs with larger size:
sudo mount -o remount,size=2G /dev/shm
– Remove orphaned segments: identify with ipcs -m then remove with ipcrm -m <shmid>
– Increase limits: sudo sysctl -w kernel.shmmax=<bytes> and kernel.shmall=<pages> (make persistent in /etc/sysctl.conf)
– For containers: increase –shm-size for Docker or adjust the container’s tmpfs/cgroups limits.
– If unsure, reboot (will clear ephemeral shared memory) as a last resort.
will the fix have sideffects?
Increasing kernel.shmmni (the maximum number of System V shared-memory segments system-wide) affects resource availability and system behavior. Key consequences:
– Higher concurrent segments allowed: more processes or libraries can create independent shared-memory segments without hitting the “too many segments” limit.
– Greater potential memory usage: each segment can consume kernel-managed resources and (when attached) user memory; raising shmmni lets total shared-memory allocation grow, risking overall memory pressure.
– Increased kernel bookkeeping: more segments means more kernel data structures (small per-segment overhead), slightly higher kernel memory usage and possibly minor performance overhead on operations that walk segment lists (ipcs, cleanup).
– Greater fragmentation and management complexity: many small segments can make accounting and cleanup harder and increase chance of orphaned segments.
– Security/availability risk: raises the surface for resource exhaustion (accidental or malicious) — a process could create many segments and deprive others of shared memory or general memory.
– Interaction with other limits: shmmni is only a count; practical limits still depend on kernel.shmmax (max bytes per segment) and kernel.shmall (total pages). Raising shmmni without appropriate shmmax/shmall adjustments may be pointless.
– Container/cgroup implications: containers with their own IPC namespace or cgroup limits may still be constrained regardless of the host shmmni.
– Need for monitoring and cleanup: higher limit increases need to track usage and remove orphaned segments.
Practical guidance (concise):
– Only raise shmmni if you hit the limit (ipcs shows many segments and shmget fails with ENOSPC).
– Increase moderately and test under load.
– Adjust shmmax/shmall in concert if larger or more segments are required.
– Monitor with ipcs -m, free -h, and kernel logs; consider limits per user or automation to clean stale segments to avoid exhaustion.
Commands to inspect (example):
– ipcs -m
– sysctl kernel.shmmni kernel.shmmax kernel.shmall
– grep shm /proc/sys/kernel/*
what’s the difference between /tmp and /dev/shm ?
shm = shared memory
Backing and type
/dev/shm: tmpfs (in-RAM filesystem, may use swap).
/tmp: usually disk-backed (ext4, xfs, etc.); on some systems it may be tmpfs (tmpfs if system configured).
Intended use
/dev/shm: POSIX/shared memory (shm_open/mmap) and very-fast in-memory temp storage for IPC.
/tmp: general-purpose temporary files for applications and users.
Performance
/dev/shm: much faster (memory) — lower latency and higher throughput.
/tmp: slower if disk-backed; similar to /dev/shm only if /tmp is tmpfs.
Size & limits
/dev/shm: limited by tmpfs mount size (often fraction of RAM) and consumes RAM/swap.
/tmp: limited by disk partition size (or tmpfs size if mounted as tmpfs).
Persistence & lifetime
/dev/shm: ephemeral; contents lost on reboot.
/tmp: usually cleared on reboot (varies by distro) but can persist for session depending on policy.
Typical consequences of filling
/dev/shm: can cause shared-memory allocation failures (ENOSPC) and reduce available RAM.
/tmp: can fill disk, causing general I/O problems and file-creation failures.
Security/permissions
Both follow normal filesystem permissions; /tmp commonly uses sticky bit (t) to prevent deletion by other users. /dev/shm also often uses sticky bit.
How to inspect/resize
Check usage: df -h /dev/shm ; df -h /tmp
Resize /dev/shm: sudo mount -o remount,size=2G /dev/shm
/tmp resize requires disk partition changes or mounting as tmpfs.
Use /dev/shm for fast IPC or short-lived in-memory temp data; use /tmp for general temporary files unless you need the speed of memory.
liked this article?
- only together we can create a truly free world
- plz support dwaves to keep it up & running!
- (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
- really really hate advertisement
- contribute: whenever a solution was found, blog about it for others to find!
- talk about, recommend & link to this blog and articles
- thanks to all who contribute!
