Module Name: src
Committed By: riastradh
Date: Wed Jan 22 06:18:01 UTC 2014
Modified Files:
src/usr.bin/vndcompress: Makefile common.h vndcompress.c
vnduncompress.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/vndcompress/Makefile
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/vndcompress/common.h
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/vndcompress/vndcompress.c
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/vndcompress/vnduncompress.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/vndcompress/Makefile
diff -u src/usr.bin/vndcompress/Makefile:1.12 src/usr.bin/vndcompress/Makefile:1.13
--- src/usr.bin/vndcompress/Makefile:1.12 Wed Jan 22 06:17:25 2014
+++ src/usr.bin/vndcompress/Makefile Wed Jan 22 06:18:00 2014
@@ -161,7 +161,7 @@ check-pipewindow: smallwindow.cl2
# @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
#
Index: src/usr.bin/vndcompress/common.h
diff -u src/usr.bin/vndcompress/common.h:1.5 src/usr.bin/vndcompress/common.h:1.6
--- src/usr.bin/vndcompress/common.h:1.5 Wed Jan 22 06:17:25 2014
+++ src/usr.bin/vndcompress/common.h Wed Jan 22 06:18:00 2014
@@ -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];
Index: src/usr.bin/vndcompress/vndcompress.c
diff -u src/usr.bin/vndcompress/vndcompress.c:1.21 src/usr.bin/vndcompress/vndcompress.c:1.22
--- src/usr.bin/vndcompress/vndcompress.c:1.21 Wed Jan 22 06:17:25 2014
+++ src/usr.bin/vndcompress/vndcompress.c Wed Jan 22 06:18:00 2014
@@ -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 @@ compress_init(int argc, char **argv, con
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. */
Index: src/usr.bin/vndcompress/vnduncompress.c
diff -u src/usr.bin/vndcompress/vnduncompress.c:1.9 src/usr.bin/vndcompress/vnduncompress.c:1.10
--- src/usr.bin/vndcompress/vnduncompress.c:1.9 Wed Jan 22 06:17:34 2014
+++ src/usr.bin/vndcompress/vnduncompress.c Wed Jan 22 06:18:00 2014
@@ -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 @@ vnduncompress(int argc, char **argv, con
__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);