libbb/copyfd.c: don't mmap a largish buffer if we only want to copy a few kb
authorDenys Vlasenko <vda.linux@googlemail.com>
Fri, 19 Mar 2010 13:34:30 +0000 (14:34 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 19 Mar 2010 13:34:30 +0000 (14:34 +0100)
function                                             old     new   delta
bb_full_fd_action                                    283     295     +12

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb/copyfd.c

index c5f8b5b8763a12437be5e74607e5587e67bde9d3..f42eb76239890085f7f15cb086967872fcf677dc 100644 (file)
@@ -22,6 +22,8 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
        char *buffer;
        int buffer_size;
 
+       if (size > 0 && size <= 4 * 1024)
+               goto use_small_buf;
        /* We want page-aligned buffer, just in case kernel is clever
         * and can do page-aligned io more efficiently */
        buffer = mmap(NULL, CONFIG_FEATURE_COPYBUF_KB * 1024,
@@ -30,6 +32,7 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
                        /* ignored: */ -1, 0);
        buffer_size = CONFIG_FEATURE_COPYBUF_KB * 1024;
        if (buffer == MAP_FAILED) {
+ use_small_buf:
                buffer = alloca(4 * 1024);
                buffer_size = 4 * 1024;
        }