Skip to content

Commit

Permalink
Increase Linux pipe buffer on zfs recv size to the maximum system size
Browse files Browse the repository at this point in the history
Closes openzfs#1161

Signed-off-by: Richard Yao <[email protected]>
  • Loading branch information
ryao committed Mar 11, 2015
1 parent 7f3e466 commit 2195470
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/libzfs/libzfs_sendrecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <sys/mnttab.h>
#include <sys/avl.h>
#include <sys/debug.h>
#include <sys/stat.h>
#include <stddef.h>
#include <pthread.h>
#include <umem.h>
Expand Down Expand Up @@ -3293,11 +3294,33 @@ int
zfs_receive(libzfs_handle_t *hdl, const char *tosnap, recvflags_t *flags,
int infd, avl_tree_t *stream_avl)
{
struct stat sb;
char *top_zfs = NULL;
int err;
int cleanup_fd;
uint64_t action_handle = 0;

if (fstat(infd, &sb) == -1) {
perror("fstat");
return (-2);
}

/*
* It is not uncommon for gigabytes to be processed in zfs receive.
* Speculatively increase the buffer size via Linux-specific fcntl()
* call.
*/
if (S_ISFIFO(sb.st_mode)) {
FILE *procf = fopen("/proc/sys/fs/pipe-max-size", "r");

if (procf != NULL) {
unsigned long pipe_max_size;
fscanf(procf, "%lu", &pipe_max_size);
(void) fcntl(infd, F_SETPIPE_SZ, pipe_max_size);
fclose(procf);
}
}

cleanup_fd = open(ZFS_DEV, O_RDWR);
VERIFY(cleanup_fd >= 0);

Expand Down

0 comments on commit 2195470

Please sign in to comment.