Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/vndcompress Change vndcompress to use a default wind...



details:   https://anonhg.NetBSD.org/src/rev/e24a0200e10f
branches:  trunk
changeset: 326215:e24a0200e10f
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Jan 22 06:18:00 2014 +0000

description:
Change vndcompress to use a default window size of 512.

For vnduncompress on nonseekable input, the window size is as large
as it needs to be by default, as before.  Not clear that this is the
right choice -- by default vnduncompress on nonseekable input will
just use unbounded memory unsolicited.

diffstat:

 usr.bin/vndcompress/Makefile        |   2 +-
 usr.bin/vndcompress/common.h        |  11 ++++++++++-
 usr.bin/vndcompress/vndcompress.c   |  10 +++++++---
 usr.bin/vndcompress/vnduncompress.c |  20 +++++++++++++++-----
 4 files changed, 33 insertions(+), 10 deletions(-)

diffs (124 lines):

diff -r e0fb0648505b -r e24a0200e10f usr.bin/vndcompress/Makefile
--- a/usr.bin/vndcompress/Makefile      Wed Jan 22 06:17:51 2014 +0000
+++ b/usr.bin/vndcompress/Makefile      Wed Jan 22 06:18:00 2014 +0000
@@ -161,7 +161,7 @@
 #      @echo '# expecting failure...'
 #      if head -c $$((64 * 1024 * 1024)) < /dev/zero \
 #          | (ulimit -v $$((139 * 1024)) && \
-#              ./vndcompress -l 64m -b 512 /dev/stdin /dev/null); then \
+#              ./vndcompress -w 0 -l 64m -b 512 /dev/stdin /dev/null); then \
 #        echo 'unexpected pass!' && exit 1; \
 #      fi
 #
diff -r e0fb0648505b -r e24a0200e10f usr.bin/vndcompress/common.h
--- a/usr.bin/vndcompress/common.h      Wed Jan 22 06:17:51 2014 +0000
+++ b/usr.bin/vndcompress/common.h      Wed Jan 22 06:18:00 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: common.h,v 1.5 2014/01/22 06:17:25 riastradh Exp $     */
+/*     $NetBSD: common.h,v 1.6 2014/01/22 06:18:00 riastradh Exp $     */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -109,7 +109,16 @@
 #define        MAX_N_BLOCKS                                                    \
        (MIN(UINT32_MAX, (SIZE_MAX / sizeof(uint64_t))) - 1)
 #define        MAX_N_OFFSETS           (MAX_N_BLOCKS + 1)
+
+/*
+ * The window size is at most the number of offsets, so it has the same
+ * maximum bound.  The default window size is chosen so that windows
+ * fit in one 4096-byte page of memory.  We could use 64k bytes, or
+ * st_blksize, to maximize I/O transfer size, but the transfers won't
+ * be aligned without a lot of extra work.
+ */
 #define        MAX_WINDOW_SIZE         MAX_N_OFFSETS
+#define        DEF_WINDOW_SIZE         512
 
 struct cloop2_header {
        char            cl2h_magic[128];
diff -r e0fb0648505b -r e24a0200e10f usr.bin/vndcompress/vndcompress.c
--- a/usr.bin/vndcompress/vndcompress.c Wed Jan 22 06:17:51 2014 +0000
+++ b/usr.bin/vndcompress/vndcompress.c Wed Jan 22 06:18:00 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vndcompress.c,v 1.21 2014/01/22 06:17:25 riastradh Exp $       */
+/*     $NetBSD: vndcompress.c,v 1.22 2014/01/22 06:18:00 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: vndcompress.c,v 1.21 2014/01/22 06:17:25 riastradh Exp $");
+__RCSID("$NetBSD: vndcompress.c,v 1.22 2014/01/22 06:18:00 riastradh Exp $");
 
 #include <sys/endian.h>
 
@@ -473,12 +473,16 @@
                    S->blocksize, S->size);
        assert(S->n_blocks <= MAX_N_BLOCKS);
 
+       /* Choose a window size.  */
+       const uint32_t window_size = (ISSET(O->flags, FLAG_w)? O->window_size :
+           DEF_WINDOW_SIZE);
+
        /* Create an offset table for the blocks; one extra for the end.  */
        __CTASSERT(MAX_N_BLOCKS <= (UINT32_MAX - 1));
        S->n_offsets = (S->n_blocks + 1);
        __CTASSERT(MAX_N_OFFSETS == (MAX_N_BLOCKS + 1));
        __CTASSERT(MAX_N_OFFSETS <= (SIZE_MAX / sizeof(uint64_t)));
-       offtab_init(&S->offtab, S->n_offsets, O->window_size, S->cloop2_fd,
+       offtab_init(&S->offtab, S->n_offsets, window_size, S->cloop2_fd,
            CLOOP2_OFFSET_TABLE_OFFSET);
 
        /* Attempt to restart a partial transfer if requested.  */
diff -r e0fb0648505b -r e24a0200e10f usr.bin/vndcompress/vnduncompress.c
--- a/usr.bin/vndcompress/vnduncompress.c       Wed Jan 22 06:17:51 2014 +0000
+++ b/usr.bin/vndcompress/vnduncompress.c       Wed Jan 22 06:18:00 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vnduncompress.c,v 1.9 2014/01/22 06:17:34 riastradh Exp $      */
+/*     $NetBSD: vnduncompress.c,v 1.10 2014/01/22 06:18:00 riastradh Exp $     */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: vnduncompress.c,v 1.9 2014/01/22 06:17:34 riastradh Exp $");
+__RCSID("$NetBSD: vnduncompress.c,v 1.10 2014/01/22 06:18:00 riastradh Exp $");
 
 #include <sys/endian.h>
 
@@ -114,18 +114,28 @@
        __CTASSERT((MAX_N_BLOCKS + 1) == MAX_N_OFFSETS);
        const uint32_t n_offsets = (n_blocks + 1);
 
-       /* Make sure we can handle it with the requested window size.  */
-       if ((O->window_size != 0) && (O->window_size < n_offsets)) {
+       /* Choose a working window size.  */
+       uint32_t window_size;
+       if (ISSET(O->flags, FLAG_w) && (O->window_size < n_offsets)) {
                if (lseek(cloop2_fd, 0, SEEK_CUR) == -1) {
                        if (errno == ESPIPE)
                                errx(1, "window too small, nonseekable input");
                        else
                                err(1, "window too small and lseek failed");
                }
+               window_size = O->window_size;
+       } else {
+               if (lseek(cloop2_fd, 0, SEEK_CUR) == -1) {
+                       if (errno != ESPIPE)
+                               warn("lseek");
+                       window_size = 0;
+               } else {
+                       window_size = DEF_WINDOW_SIZE;
+               }
        }
 
        /* Initialize the offset table and start reading it in.  */
-       offtab_init(&offtab, n_offsets, O->window_size, cloop2_fd,
+       offtab_init(&offtab, n_offsets, window_size, cloop2_fd,
            CLOOP2_OFFSET_TABLE_OFFSET);
        offtab_reset_read(&offtab, &err1, &errx1);
 



Home | Main Index | Thread Index | Old Index