skarnet / execline

The execline scripting language
https://skarnet.org/software/execline/
ISC License
149 stars 19 forks source link

Busybox-style build #9

Closed pg83 closed 2 years ago

pg83 commented 2 years ago

Hi.

Statically linked binaries for execline costs 15 megabytes. It is a lot! Can you, please, provide a busybox-style binary for them?

skarnet commented 2 years ago

Statically linked binaries for execline should not cost more than 2.5 megabytes total. If you're getting more, it means your libc is not well-suited to static linking. Typically, the glibc is terrible with static linking (and doesn't support it entirely, some things don't work correctly). In that case, you don't really have a choice - just link the libc dynamically.

Multicall binaries have drawbacks. They shouldn't be used as a crutch or a workaround to a libc problem; they should only be used when they're appropriate for the project, which isn't the case with execline.

I'm sorry, but it's a no.

pg83 commented 2 years ago

they should only be used when they're appropriate for the project, which isn't the case with execline.

I understand you postion, but why "which isn't the case with execline"? execline is basically a collection of command-line programs, and, I think, busybox-style model fits this case perfectly.

Typically, the glibc is terrible

Completely agree, I use musl.

pg83 commented 2 years ago

Multicall binaries have drawbacks

I am aware of one such a problem - suid binaries. Can you share your knowledge on this topic?

pg83 commented 2 years ago

Statically linked binaries for execline should not cost more than 2.5 megabytes total.

busybox-style binary will costs approx. 500k

pg83 commented 2 years ago

@skarnet

skarnet commented 2 years ago

If your project cannot afford the 2.5 MB of disk that execline uses, it certainly cannot afford the increase in CPU and RAM usage that a multicall binary would use.

pg83 commented 2 years ago

You did not get 15 MB of binaries with musl. You have been providing incorrect information. That's not the right move if you want me to answer you.

This is kinda rude, you just called me a lier. Please, do not do this again.

pg-> ls -la /mix/store/PF3CAoXgxWTmzNTq-bin-execline/bin/
total 14899
dr-xr-xr-x    2 mix      1000          3488 Feb 17 04:53 .
drwxr-xr-x    3 mix      1000          3488 Feb 17 04:53 ..
-r-xr-xr-x    1 mix      1000        494800 Feb 17 04:53 background
-r-xr-xr-x    1 mix      1000        496136 Feb 17 04:53 backtick
-r-xr-xr-x    1 mix      1000        536456 Feb 17 04:53 case
lrwxrwxrwx    1 mix      1000            11 Feb 17 04:53 cd -> execline-cd
-r-xr-xr-x    1 mix      1000        491280 Feb 17 04:53 define
-r-xr-xr-x    1 mix      1000         13272 Feb 17 04:53 dollarat
-r-xr-xr-x    1 mix      1000        488608 Feb 17 04:53 elgetopt
-r-xr-xr-x    1 mix      1000        491600 Feb 17 04:53 elgetpositionals
-r-xr-xr-x    1 mix      1000        520856 Feb 17 04:53 elglob
-r-xr-xr-x    1 mix      1000        488904 Feb 17 04:53 emptyenv
-r-xr-xr-x    1 mix      1000        491336 Feb 17 04:53 envfile
-r-xr-xr-x    1 mix      1000         13080 Feb 17 04:53 exec
-r-xr-xr-x    1 mix      1000         12560 Feb 17 04:53 execline-cd
-r-xr-xr-x    1 mix      1000         12936 Feb 17 04:53 execline-umask
-r-xr-xr-x    1 mix      1000        496688 Feb 17 04:53 execlineb
-r-xr-xr-x    1 mix      1000          7808 Feb 17 04:53 exit
-r-xr-xr-x    1 mix      1000         13672 Feb 17 04:53 export
-r-xr-xr-x    1 mix      1000         14424 Feb 17 04:53 fdblock
-r-xr-xr-x    1 mix      1000         13208 Feb 17 04:53 fdclose
-r-xr-xr-x    1 mix      1000         14120 Feb 17 04:53 fdmove
-r-xr-xr-x    1 mix      1000         16232 Feb 17 04:53 fdreserve
-r-xr-xr-x    1 mix      1000         13920 Feb 17 04:53 fdswap
-r-xr-xr-x    1 mix      1000         15848 Feb 17 04:53 forbacktickx
-r-xr-xr-x    1 mix      1000        491272 Feb 17 04:53 foreground
-r-xr-xr-x    1 mix      1000        496600 Feb 17 04:53 forstdin
-r-xr-xr-x    1 mix      1000        492632 Feb 17 04:53 forx
-r-xr-xr-x    1 mix      1000        486032 Feb 17 04:53 getcwd
-r-xr-xr-x    1 mix      1000         14960 Feb 17 04:53 getpid
-r-xr-xr-x    1 mix      1000         21000 Feb 17 04:53 heredoc
-r-xr-xr-x    1 mix      1000        488032 Feb 17 04:53 homeof
-r-xr-xr-x    1 mix      1000        491304 Feb 17 04:53 if
-r-xr-xr-x    1 mix      1000        491072 Feb 17 04:53 ifelse
-r-xr-xr-x    1 mix      1000        491392 Feb 17 04:53 ifte
-r-xr-xr-x    1 mix      1000        492904 Feb 17 04:53 ifthenelse
-r-xr-xr-x    1 mix      1000        491864 Feb 17 04:53 importas
-r-xr-xr-x    1 mix      1000        489312 Feb 17 04:53 loopwhilex
-r-xr-xr-x    1 mix      1000        493064 Feb 17 04:53 multidefine
-r-xr-xr-x    1 mix      1000        529024 Feb 17 04:53 multisubstitute
-r-xr-xr-x    1 mix      1000        496944 Feb 17 04:53 pipeline
-r-xr-xr-x    1 mix      1000         13696 Feb 17 04:53 piperw
-r-xr-xr-x    1 mix      1000        492552 Feb 17 04:53 posix-cd
-r-xr-xr-x    1 mix      1000        490096 Feb 17 04:53 posix-umask
-r-xr-xr-x    1 mix      1000         16456 Feb 17 04:53 redirfd
-r-xr-xr-x    1 mix      1000        488464 Feb 17 04:53 runblock
-r-xr-xr-x    1 mix      1000        488344 Feb 17 04:53 shift
-r-xr-xr-x    1 mix      1000        498416 Feb 17 04:53 trap
-r-xr-xr-x    1 mix      1000         15016 Feb 17 04:53 tryexec
lrwxrwxrwx    1 mix      1000            14 Feb 17 04:53 umask -> execline-umask
-r-xr-xr-x    1 mix      1000         13560 Feb 17 04:53 unexport
-r-xr-xr-x    1 mix      1000         22904 Feb 17 04:53 wait
-r-xr-xr-x    1 mix      1000        487008 Feb 17 04:53 withstdinas
pg-> du /mix/store/PF3CAoXgxWTmzNTq-bin-execline/bin/
14896   /mix/store/PF3CAoXgxWTmzNTq-bin-execline/bin/
pg-> 

I have a custom musl build, with custom allocator, which alone adds 150-200k to each binary. But it is musl, no doubt.

In stripped form they will costs 11.5M.

pg83 commented 2 years ago

multicall binaries trade off execution time and run-time memory footprint for disk footprint.

Actually, you are wrong. May be you do not do proper tests? In case of regular and permanent usage, multicall binaries are faster to start(one linear disk read into vfs) and eats less memory(cause common code block can be eliminated by lto).

And you should know that not whole binary read into memory, but only page-faulted pages, so in case of multicall binary even if you are calling one sub-binary, overhead is really small.

Yes, I actually measured it.

pg83 commented 2 years ago

If your project cannot afford the 2.5 MB of disk that execline uses,

Hm, but it is your arguments for execline usage?

"No overhead due to unneeded features. Since every command performs its task then executes another command, all occupied resources are instantly freed. By contrast, a shell stays in memory during the whole execution time."

My current setup have 1.5M busybox binary(with built-in shell). I decide using execline in my startup scripts as an optimization, and it will be an optimization, iff execline binaries will costs less than 1.5M.

ceache commented 2 years ago

Hi Anton,

Just to be clear, you are saying you added a special allocator to the musl libc with which you statically linked the 50 binaries in execline, special allocator that bloats each of these binaries by 200kb. So your allocator is responsible for 10MB out of your execline build 15MB total size.

Considering the memory usage pattern of execline which is to allocate as little as possible, as infrequently as possible and exec chain to always "start clean", what could be the benefit of such a large, presumably complex, allocator?

Especially since you statically link your musl in (and thus it is not shared), wouldn't it make more sense to change your "mix" (nix?) derivation to use a lean musl with a simple allocator instead?

Without even going into the multicall binary debate, the premise of the problem here is not clear to me.

On Wed, Feb 16, 2022, 21:00 Anton Samokhvalov @.***> wrote:

You did not get 15 MB of binaries with musl. You have been providing incorrect information. That's not the right move if you want me to answer you.

This is kinda rude, you just called me a lier. Please, do not do this again.

pg-> ls -la /mix/store/PF3CAoXgxWTmzNTq-bin-execline/bin/ total 14899 dr-xr-xr-x 2 mix 1000 3488 Feb 17 04:53 . drwxr-xr-x 3 mix 1000 3488 Feb 17 04:53 .. -r-xr-xr-x 1 mix 1000 494800 Feb 17 04:53 background -r-xr-xr-x 1 mix 1000 496136 Feb 17 04:53 backtick -r-xr-xr-x 1 mix 1000 536456 Feb 17 04:53 case lrwxrwxrwx 1 mix 1000 11 Feb 17 04:53 cd -> execline-cd -r-xr-xr-x 1 mix 1000 491280 Feb 17 04:53 define -r-xr-xr-x 1 mix 1000 13272 Feb 17 04:53 dollarat -r-xr-xr-x 1 mix 1000 488608 Feb 17 04:53 elgetopt -r-xr-xr-x 1 mix 1000 491600 Feb 17 04:53 elgetpositionals -r-xr-xr-x 1 mix 1000 520856 Feb 17 04:53 elglob -r-xr-xr-x 1 mix 1000 488904 Feb 17 04:53 emptyenv -r-xr-xr-x 1 mix 1000 491336 Feb 17 04:53 envfile -r-xr-xr-x 1 mix 1000 13080 Feb 17 04:53 exec -r-xr-xr-x 1 mix 1000 12560 Feb 17 04:53 execline-cd -r-xr-xr-x 1 mix 1000 12936 Feb 17 04:53 execline-umask -r-xr-xr-x 1 mix 1000 496688 Feb 17 04:53 execlineb -r-xr-xr-x 1 mix 1000 7808 Feb 17 04:53 exit -r-xr-xr-x 1 mix 1000 13672 Feb 17 04:53 export -r-xr-xr-x 1 mix 1000 14424 Feb 17 04:53 fdblock -r-xr-xr-x 1 mix 1000 13208 Feb 17 04:53 fdclose -r-xr-xr-x 1 mix 1000 14120 Feb 17 04:53 fdmove -r-xr-xr-x 1 mix 1000 16232 Feb 17 04:53 fdreserve -r-xr-xr-x 1 mix 1000 13920 Feb 17 04:53 fdswap -r-xr-xr-x 1 mix 1000 15848 Feb 17 04:53 forbacktickx -r-xr-xr-x 1 mix 1000 491272 Feb 17 04:53 foreground -r-xr-xr-x 1 mix 1000 496600 Feb 17 04:53 forstdin -r-xr-xr-x 1 mix 1000 492632 Feb 17 04:53 forx -r-xr-xr-x 1 mix 1000 486032 Feb 17 04:53 getcwd -r-xr-xr-x 1 mix 1000 14960 Feb 17 04:53 getpid -r-xr-xr-x 1 mix 1000 21000 Feb 17 04:53 heredoc -r-xr-xr-x 1 mix 1000 488032 Feb 17 04:53 homeof -r-xr-xr-x 1 mix 1000 491304 Feb 17 04:53 if -r-xr-xr-x 1 mix 1000 491072 Feb 17 04:53 ifelse -r-xr-xr-x 1 mix 1000 491392 Feb 17 04:53 ifte -r-xr-xr-x 1 mix 1000 492904 Feb 17 04:53 ifthenelse -r-xr-xr-x 1 mix 1000 491864 Feb 17 04:53 importas -r-xr-xr-x 1 mix 1000 489312 Feb 17 04:53 loopwhilex -r-xr-xr-x 1 mix 1000 493064 Feb 17 04:53 multidefine -r-xr-xr-x 1 mix 1000 529024 Feb 17 04:53 multisubstitute -r-xr-xr-x 1 mix 1000 496944 Feb 17 04:53 pipeline -r-xr-xr-x 1 mix 1000 13696 Feb 17 04:53 piperw -r-xr-xr-x 1 mix 1000 492552 Feb 17 04:53 posix-cd -r-xr-xr-x 1 mix 1000 490096 Feb 17 04:53 posix-umask -r-xr-xr-x 1 mix 1000 16456 Feb 17 04:53 redirfd -r-xr-xr-x 1 mix 1000 488464 Feb 17 04:53 runblock -r-xr-xr-x 1 mix 1000 488344 Feb 17 04:53 shift -r-xr-xr-x 1 mix 1000 498416 Feb 17 04:53 trap -r-xr-xr-x 1 mix 1000 15016 Feb 17 04:53 tryexec lrwxrwxrwx 1 mix 1000 14 Feb 17 04:53 umask -> execline-umask -r-xr-xr-x 1 mix 1000 13560 Feb 17 04:53 unexport -r-xr-xr-x 1 mix 1000 22904 Feb 17 04:53 wait -r-xr-xr-x 1 mix 1000 487008 Feb 17 04:53 withstdinas pg-> du /mix/store/PF3CAoXgxWTmzNTq-bin-execline/bin/ 14896 /mix/store/PF3CAoXgxWTmzNTq-bin-execline/bin/ pg->

I have a custom musl build, with custom allocator, which alone adds 150-200k to each binary. But it is musl, no doubt.

In stripped form they will costs 11.5M.

— Reply to this email directly, view it on GitHub https://github.com/skarnet/execline/issues/9#issuecomment-1042491663, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIFTHU7JUPBY5XJXP3TTHLU3RJDHANCNFSM5OP6Z4OA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

pg83 commented 2 years ago

So, a solution which will be be strictly better than my current setup anyway will include a multicall-binary for execline :) And after that allocator change give me 200k from 500k of multicall-binary.

pg83 commented 2 years ago

To be absolutely clear - iff I change allocator alone, I still will have 2.5M execline binaries, which is still bigger than my current busybox setup(1.5M)

skarnet commented 2 years ago

Static linking with mimalloc apparently adds 450 kB to every binary that uses malloc. You say this allocator has good tradeoffs. Okay.

If you do that with your whole distro, execline is going to be the least of your problems. Are you going to ask every upstream to bend to your needs, needs that come from questionable technical choices?

I will now be unsubscribing from this issue.

pg83 commented 2 years ago

@skarnet You missing main point. With pure musl execline will costs 2.5M, which is much bigger than pure busybox(1.5M).

Are you going to ask every upstream to bend to your needs, needs that come from questionable technical choices?

Nope, as I can build any code with any allocator. But it will not help to execline to compete with busybox :)

I will now be unsubscribing from this issue.

Completely understandable, cause you can not cope with my technical arguments.

pg83 commented 8 months ago

@skarnet thanks a lot! https://github.com/skarnet/execline/commit/edf81b0d16322e5d49ec22f394b669d9094daac1