[git commit] libbb: use ARG_MAX for bb_arg_max() only if it's 60k+
Denys Vlasenko
vda.linux at googlemail.com
Wed Nov 26 14:17:59 UTC 2014
commit: http://git.busybox.net/busybox/commit/?id=04c14176023c65550fd46c2e44a1aa04d426d69a
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master
Sometimes ARG_MAX is small (like 32k) yet sysconf(_SC_ARG_MAX)
is big, and people prefer using the bigger value.
OTOH, with sufficiently large ARG_MAX, further wins from
sysconf(_SC_ARG_MAX) being bigger are exponentially smaller:
you can see 4 times fewer fork+execs when you run find, but
when each execed process already takes a thousand parameters
it's likely execution time is dominated by what that process
does with each parameter.
Thus, with this change ARG_MAX is used if it's sufficiently big,
otherwise sysconf(_SC_ARG_MAX) is used.
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
include/libbb.h | 7 +++++--
libbb/sysconf.c | 2 +-
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/include/libbb.h b/include/libbb.h
index cc2bea3..17a0089 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -731,11 +731,14 @@ extern void *xmalloc_open_read_close(const char *filename, size_t *maxsz_p) FAST
/* Never returns NULL */
extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
-#if defined ARG_MAX
+#if defined(ARG_MAX) && (ARG_MAX >= 60*1024 || !defined(_SC_ARG_MAX))
+/* Use _constant_ maximum if: defined && (big enough || no variable one exists) */
# define bb_arg_max() ((unsigned)ARG_MAX)
-#elif defined _SC_ARG_MAX
+#elif defined(_SC_ARG_MAX)
+/* Else use variable one (a bit more expensive) */
unsigned bb_arg_max(void) FAST_FUNC;
#else
+/* If all else fails */
# define bb_arg_max() ((unsigned)(32 * 1024))
#endif
unsigned bb_clk_tck(void) FAST_FUNC;
diff --git a/libbb/sysconf.c b/libbb/sysconf.c
index 0319019..cfad9cd 100644
--- a/libbb/sysconf.c
+++ b/libbb/sysconf.c
@@ -8,7 +8,7 @@
*/
#include "libbb.h"
-#if !defined(ARG_MAX) && defined(_SC_ARG_MAX)
+#if !defined(bb_arg_max)
unsigned FAST_FUNC bb_arg_max(void)
{
return sysconf(_SC_ARG_MAX);
More information about the busybox-cvs
mailing list