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.
This commit is contained in:
parent
120dc04ff6
commit
f13ecd80a5
@ -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
|
||||
#
|
||||
|
@ -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];
|
||||
|
@ -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, const struct options *O,
|
||||
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. */
|
||||
|
@ -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, const struct options *O __unused)
|
||||
__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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user