Skip to content

Commit 8ab95f2

Browse files
authored
Merge pull request #2985 from yoniko/zstd-output-file-buffer
ZSTD CLI: Use buffered output
2 parents 1598e6c + df5013b commit 8ab95f2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

programs/fileio.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,17 @@ FIO_openDstFile(FIO_ctx_t* fCtx, FIO_prefs_t* const prefs,
726726
if (f == NULL) {
727727
DISPLAYLEVEL(1, "zstd: %s: %s\n", dstFileName, strerror(errno));
728728
}
729+
/* An increased buffer size can provide a significant performance boost on some platforms.
730+
* Note that providing a NULL buf with a size that's not 0 is not defined in ANSI C, but is defined
731+
* in an extension. There are three possibilities here -
732+
* 1. Libc supports the extended version and everything is good.
733+
* 2. Libc ignores the size when buf is NULL, in which case everything will continue as if we didn't
734+
* call `setvbuf`.
735+
* 3. We fail the call and execution continues but a warning message might be shown.
736+
* In all cases due execution continues. For now, I believe that this is a more cost-effective
737+
* solution than managing the buffers allocations ourselves (will require an API change). */
738+
if(setvbuf(f, NULL, _IOFBF, 1 MB))
739+
DISPLAYLEVEL(2, "Warning: setvbuf failed for %s\n", dstFileName);
729740
return f;
730741
}
731742
}

0 commit comments

Comments
 (0)