coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] wc,*sum: indicate potentially more performant buffering


From: Pádraig Brady
Subject: [PATCH] wc,*sum: indicate potentially more performant buffering
Date: Sun, 5 Aug 2012 19:31:10 +0100

We already use _IOLBF so that we output lines atomically.
However there is no need to output lines _immediately_
and doing so can cause overhead.  For example on
recent GNU/Linux systems, processes writing to a pipe,
will encourage the process reading the pipe to wake up.
Thus if processing many small files, these utilties
can induce excessive context switching.

Now the existing setvbuf() interface is rich enough
to express atomic but not immediate line output,
by specifying a size along with the _IOLBF mode.
Unfortunately glibc-2.14.1 at least just ignores a size
when specified with _IOLBF.  By introducing a size here,
we will take advantage of possible improved processing
on other or later glibc systems.

* src/cksum.c (main): Add BUFSIZ to setvbuf(..,_IOLBLF,..).
 src/md5sum.c: Likewise.
 src/sum.c: Likewise.
 src/wc.c: Likewise.
---
 src/cksum.c  |    2 +-
 src/md5sum.c |    2 +-
 src/sum.c    |    2 +-
 src/wc.c     |    2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/cksum.c b/src/cksum.c
index 332f41d..58b5162 100644
--- a/src/cksum.c
+++ b/src/cksum.c
@@ -292,7 +292,7 @@ main (int argc, char **argv)
 
   /* Line buffer stdout to ensure lines are written atomically and immediately
      so that processes running in parallel do not intersperse their output.  */
-  setvbuf (stdout, NULL, _IOLBF, 0);
+  setvbuf (stdout, NULL, _IOLBF, BUFSIZ);
 
   parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, Version,
                       usage, AUTHORS, (char const *) NULL);
diff --git a/src/md5sum.c b/src/md5sum.c
index f7e0849..b6ae69e 100644
--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -658,7 +658,7 @@ main (int argc, char **argv)
 
   /* Line buffer stdout to ensure lines are written atomically and immediately
      so that processes running in parallel do not intersperse their output.  */
-  setvbuf (stdout, NULL, _IOLBF, 0);
+  setvbuf (stdout, NULL, _IOLBF, BUFSIZ);
 
   while ((opt = getopt_long (argc, argv, "bctw", long_options, NULL)) != -1)
     switch (opt)
diff --git a/src/sum.c b/src/sum.c
index df01207..4fb24da 100644
--- a/src/sum.c
+++ b/src/sum.c
@@ -236,7 +236,7 @@ main (int argc, char **argv)
 
   /* Line buffer stdout to ensure lines are written atomically and immediately
      so that processes running in parallel do not intersperse their output.  */
-  setvbuf (stdout, NULL, _IOLBF, 0);
+  setvbuf (stdout, NULL, _IOLBF, BUFSIZ);
 
   have_read_stdin = false;
 
diff --git a/src/wc.c b/src/wc.c
index 5017377..17b784c 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -608,7 +608,7 @@ main (int argc, char **argv)
 
   /* Line buffer stdout to ensure lines are written atomically and immediately
      so that processes running in parallel do not intersperse their output.  */
-  setvbuf (stdout, NULL, _IOLBF, 0);
+  setvbuf (stdout, NULL, _IOLBF, BUFSIZ);
 
   print_lines = print_words = print_chars = print_bytes = false;
   print_linelength = false;
-- 
1.7.6.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]