]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
fuse: use kvmalloc to allocate array of pipe_buffer structs.
authorAndrey Ryabinin <aryabinin@virtuozzo.com>
Tue, 17 Jul 2018 16:00:34 +0000 (19:00 +0300)
committerMiklos Szeredi <mszeredi@redhat.com>
Thu, 26 Jul 2018 14:13:12 +0000 (16:13 +0200)
The amount of pipe->buffers is basically controlled by userspace by
fcntl(... F_SETPIPE_SZ ...) so it could be large. High order allocations
could be slow (if memory is heavily fragmented) or may fail if the order
is larger than PAGE_ALLOC_COSTLY_ORDER.

Since the 'bufs' doesn't need to be physically contiguous, use
the kvmalloc_array() to allocate memory. If high order
page isn't available, the kvamalloc*() will fallback to 0-order.

Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/dev.c

index de3d273c9366093e03c1a626535fe488991a312b..1050c1cc22fe7f7acaab45b89a8067482b53b8e6 100644 (file)
@@ -1373,8 +1373,8 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
        if (!fud)
                return -EPERM;
 
-       bufs = kmalloc_array(pipe->buffers, sizeof(struct pipe_buffer),
-                            GFP_KERNEL);
+       bufs = kvmalloc_array(pipe->buffers, sizeof(struct pipe_buffer),
+                             GFP_KERNEL);
        if (!bufs)
                return -ENOMEM;
 
@@ -1407,7 +1407,7 @@ out:
        for (; page_nr < cs.nr_segs; page_nr++)
                put_page(bufs[page_nr].page);
 
-       kfree(bufs);
+       kvfree(bufs);
        return ret;
 }
 
@@ -1957,8 +1957,8 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
 
        pipe_lock(pipe);
 
-       bufs = kmalloc_array(pipe->buffers, sizeof(struct pipe_buffer),
-                            GFP_KERNEL);
+       bufs = kvmalloc_array(pipe->buffers, sizeof(struct pipe_buffer),
+                             GFP_KERNEL);
        if (!bufs) {
                pipe_unlock(pipe);
                return -ENOMEM;
@@ -2017,7 +2017,7 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
                pipe_buf_release(pipe, &bufs[idx]);
 
 out:
-       kfree(bufs);
+       kvfree(bufs);
        return ret;
 }