-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chroot builds are slow #179
Comments
Oh, not good. Are there some other standard sandboxing options? (except for LD_PRELOADing some libc hooks) |
I can imagine a cheaper chroot that just bind-mounts the entire Nix store. Maybe we could even put an ACL on /nix/store to deny "r" but not "x" permission to nixbld users. That way builds can only access store paths that they already know. Also, maybe it's faster on newer kernels. |
Well, I don't think packages try finding something by listing /nix/store. In general, maybe we could deny "r" on it for everyone, but I fail to see any significant gain. Maybe providing some cheap variant of chroot by default could be a good compromise (with possibility to switch to stronger guarantees). |
The benefits of chrooted builds are far more significant than the performance cost. Chroot builds should be totally enabled on NixOS by default!!! |
Are the bind mounts done in parallel? |
No. |
@edolstra I'd still prefer purity/determinism over performance and enable chroots on Linux by default. |
On my machine (SDD, running kernel 3.14): real 0m27.129s |
@iElectric: are you sure your measurement is correct? It shows mostly waiting and no real work. Or is that because the work is in fact done in another process? |
👍 for a mini chroot that has all of nix store. This could be reused, no? Same chroot for all builds? |
@vcunat i'd say most of the time it's waiting for nix-daemon IO |
Computers have become faster in the past 2 years. We should re-evaluate whether the speed is really worth the significant impurities. Note that the fact that NixOS default Hydra not using chroot leads to packages "randomly" failing to build locally for those who do use it. So at least Hydra should enable it. |
Hydra does use it. It's the other way around, users like me might not have it enabled and think that a package builds properly when it doesn't. (Happened today with a PHP update, which turns out to do a download during its build.) |
Yes, leaving our deterministic promise aside for a sake of some small overhead. |
When nix sets up chroots, is most of the time spent setting up bind mounts? Or does it do a lot of file copying too? If the latter, have you considered using something like Cowdancer (http://www.netfort.gr.jp/~dancer/software/cowdancer.html.en) to get copy-on-write bind mounts? It's low-overhead and fast to set up. Debian uses it in cowbuilder/pbuilder, which makes for an excellent ephemeral-chrooted build system. |
@benley: COW isn't needed, as all accessible in the chroot is read-only anyway. From the comments it seems noone has analyzed precisely what's the main cost, but bind mounts are suspected (and they probably were never meant to be used so massively). |
Has anyone looked into proot for this purpose? |
"PRoot uses the CPU emulator QEMU user-mode to execute transparently guest programs." I doubt that's faster than bind mounts :-) |
Yeah, PRoot might be faster to setup, but it sounds significantly slower to run longer builds (which happen a lot). Various other preloading solutions might also slow down system calls, although probably not so much. |
@edolstra oh sorry, my understanding was that it only used QEMU when the guest was of a different architecture |
I believe proot only uses qemu when it's running binaries from a non-native architecture. The proot website is fairly clear about that, unless I'm badly misinterpreting it: http://proot.me/ |
It does still intercept system calls in userland, and it's going to have some unavoidable speed overhead. |
Isn't it documented to use ptrace? If so it will signal the controlling On Tue, Jan 20, 2015 at 12:47 AM, Benjamin Staffin <notifications@github.com
|
My sophisticated web searches (i.e. "proot benchmark") didn't show up On Tue Jan 20 2015 at 4:17:27 AM Alexander Kjeldaas <
|
Hello all, I confirm that PRoot uses QEMU to run non-native binaries only, and
My suggestion is to give PRoot a try if your kernel version is equal Regards, |
Seems like using Linux namespaces would dovetail with the pure Darwin stdenv work. All the better if they are faster than chroots. |
They actually already use Linux namespaces. |
Heh, in that case NixOS should call them Containers and pick up some buzzword publicity points. "Build all the things in containers!" containers containers containers containers containers. ;-) |
It would be good to look at how Bazel does it as they are facing similar problems. |
Thanks for the explanations! Maybe we should use a selective approach until Linux namespaces are very fast. While sandboxing ver every derivation is certainly desirable, it would already be a huge benefit if we could, for starters, sandbox "the average build" of nixpkgs libraries and applications. For example, I'd be very happy to pay a 24 ms overhead if in turn my 5 hour Chromium build is guaranteed to be pure. But right now it's full sandboxing or no sandboxing. Another point: The We should probably benchmark whatever |
FWIW, here are the results on my machine (the same one I used for the prior benchmarks), for
And here it is for
So sandboxing is about an order of magnitude slower than running a minimal command. I definitely agree that this amount of time is not important for most use cases today. |
And building a |
@zimbatm Yes, but Nix does not require the use of BTW on Linux 4.17 I get a 37% slowdown in the test mentioned in #179 (comment). That's a big improvement over the 742% slowdown in 2013... |
Any idea of a good threshold for acceptable? I doubt it'll ever be zero cost, but purity-by-default is a big win IMO and I'd be willing to pay a slight cost on it. Especially since the benchmark you're citing mostly affects tiny derivations and not big builds. One even smallish build will completely eclipse a ton of small slowdowns on unit files and NixOS configuration files. |
Having sandboxing turned on by default would be great. It would reduce the number of issues with nixpkgs submissions that don't compile and user reports. We'll be able to trim the PR and Issue templates. That being said, if nix is running inside of a docker container it won't work as docker containers don't support cgroups by default. Back on the subject of sandboxing, is it possible to re-use sandboxes between runs? if sandboxes could be re-used then they could also be pooled where the pool size = maxJobs. |
We must be sound now. We must compete with the likes of Bazel on granularity soon. That's how I see it. |
@copumpkin I think the 37% slowdown is okay-ish, though obviously not ideal. @zimbatm No, I don't think sandboxes can be reused. The main overhead seems to be setting up the mount namespace, which is necessarily different for each build (since they have different input closures). Of course, you could bind-mount all of /nix/store, but that reduces security a bit (since even if it has |
The main overhead seems to be setting up the mount namespace, which is necessarily different for each build (since they have different input closures).
Setting up the namespace or setting up the mounts? I.e., would reusing the namespace, and mounting/unmounting only the paths that differ (keeping the stdenv paths untouched) help in any appreciable way?
|
@7c6f434c Good question! I think we would need to benchmark bind mounting to see. |
Another motivation to enforce the sandboxing is that we could get rid of the |
We-ell, some namespace bugs (kernel-level) could be mitigated by the fact that the real UID outside of namespace is different, so for maximum isolation we might still want to have these users…
|
In ad1c827 I implemented automatic UID allocation from a range. You would still like to ensure that the UID range doesn't clash with any existing accounts, though it's unlikely people have UIDs in the range 872415232+... |
Well, if the range is configurable it should be easy to move outside the ranges used by other tools; definitely simpler than listing eight build users in global passwd. Thanks. |
@edolstra I wanted to implement sandboxing to be on for Docker after @garbas talk, but really that road leads back to Nix doing it by default for overall good experience. Given that we're at the okayish threshold now, and kernel 4.19 was released that will be next LTS, can we make sandboxing by default on? :) |
Why docker? I missed the talk but intuitively it feels like a step backwards |
@copumpkin just to enable sanboxing for https://github.com/NixOS/docker, since it helps sandbox networking during Nix builds. |
Does the Nix sandboxing work inside of Docker now? |
I believe it's worked for quite some time --
but requires permissions/capabilities that aren't
added by default. Don't remember the appropriate flags, sorry,
others might be able to say more.
…On Fri, 02 Nov 2018 16:56:08 -0700, zimbatm ***@***.***> wrote:
Does the Nix sandboxing work inside of Docker now?
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
#179 (comment) part: text/html
|
Oh sorry, I misread and thought you wanted to change our sandboxing mechanism to use docker, rather than get docker to work from inside one of our sandboxes 😄 sorry! |
Based on the talk (IIRC) I think it's actually neither of those xD,
but rather getting our sandbox (and the Nix "story") to work in Docker
(which to some extent is how people expect to "get started" these days).
…On Fri, 02 Nov 2018 18:54:38 -0700, Daniel Peebles ***@***.***> wrote:
Oh sorry, I misread and thought you wanted to change our sandboxing mechanism to _use_ docker, rather than get docker to work from inside one of our sandboxes 😄 sorry!
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
#179 (comment) part: text/html
|
oh, I see, thanks! |
🎉 |
#2759 A wildly different idea for maybe-even-faster sandboxing. |
The solution to this is eBPF-based sandboxing, which would be essentially 'free' if the builder doesnt 'try anything funny'. |
…ns/cachix/install-nix-action-14 chore(deps): bump cachix/install-nix-action from 13 to 14
Chroot builds have a significant overhead. For instance, this expression:
(i.e. a trivial build with 100 trivial dependencies) takes 4.7s to build on my laptop without chroot, but 39.6s with chroot.
The main overhead seems to be in setting up the chroot (i.e. all the bind mounts), but the various CLONE_* flags also have significant overhead.
Unfortunately, there is not much we can do about this since it's all in the kernel, but it does mean we can't enable chroot builds by default on NixOS.
This is on Linux 3.4.70.
The text was updated successfully, but these errors were encountered: