Variant for chroot ?
Variant for chroot ?
Posted Mar 14, 2026 1:35 UTC (Sat) by geofft (subscriber, #59789)In reply to: Variant for chroot ? by wtarreau
Parent article: Practical uses for a null filesystem
This is already the behavior of, say, a tmpfs in a mount namespace. It's reference-counted and once the last process referencing it dies, the tmpfs is cleaned up. You can see this very clearly by creating a large file and looking at memory usage before/after a kill -9 of the owning process.
Mostly for amusement purposes, I wrote a mkdtemp() alternative that works by creating a child process in a new unprivileged user+mount namespace and having it pass back a handle to a tmpfs. https://ldpreload.com/p/verytmp.c
A friend ported it to Rust and has a slightly more detailed writeup: https://blinsay.com/posts/verytmp/
(nullfs appears to not be mountable inside a userns, largely because it's a global singleton. So you don't actually need to garbage-collect it, but I guess this also means you might not be a way to actually get to it from a regular userspace process.)
