Skip to content

Commit 906f904

Browse files
committed
Revert "fs/pipe: use kvcalloc to allocate a pipe_buffer array"
This reverts commit 5a519c8. It turns out that making the pipe almost arbitrarily large has some rather unexpected downsides. The kernel test robot reports a kernel warning that is due to pipe->max_usage now growing to the point where the iter_file_splice_write() buffer allocation can no longer be satisfied as a slab allocation, and the int nbufs = pipe->max_usage; struct bio_vec *array = kcalloc(nbufs, sizeof(struct bio_vec), GFP_KERNEL); code sequence there will now always fail as a result. That code could be modified to use kvcalloc() too, but I feel very uncomfortable making those kinds of changes for a very niche use case that really should have other options than make these kinds of fundamental changes to pipe behavior. Maybe the CRIU process dumping should be multi-threaded, and use multiple pipes and multiple cores, rather than try to use one larger pipe to minimize splice() calls. Reported-by: kernel test robot <oliver.sang@intel.com> Link: https://lore.kernel.org/all/20220420073717.GD16310@xsang-OptiPlex-9020/ Cc: Andrei Vagin <avagin@gmail.com> Cc: Dmitry Safonov <0x7f454c46@gmail.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a6823e4 commit 906f904

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

fs/pipe.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ struct pipe_inode_info *alloc_pipe_info(void)
804804
if (too_many_pipe_buffers_hard(user_bufs) && pipe_is_unprivileged_user())
805805
goto out_revert_acct;
806806

807-
pipe->bufs = kvcalloc(pipe_bufs, sizeof(struct pipe_buffer),
807+
pipe->bufs = kcalloc(pipe_bufs, sizeof(struct pipe_buffer),
808808
GFP_KERNEL_ACCOUNT);
809809

810810
if (pipe->bufs) {
@@ -849,7 +849,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
849849
#endif
850850
if (pipe->tmp_page)
851851
__free_page(pipe->tmp_page);
852-
kvfree(pipe->bufs);
852+
kfree(pipe->bufs);
853853
kfree(pipe);
854854
}
855855

@@ -1264,7 +1264,8 @@ int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots)
12641264
if (nr_slots < n)
12651265
return -EBUSY;
12661266

1267-
bufs = kvcalloc(nr_slots, sizeof(*bufs), GFP_KERNEL_ACCOUNT);
1267+
bufs = kcalloc(nr_slots, sizeof(*bufs),
1268+
GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
12681269
if (unlikely(!bufs))
12691270
return -ENOMEM;
12701271

@@ -1291,7 +1292,7 @@ int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots)
12911292
head = n;
12921293
tail = 0;
12931294

1294-
kvfree(pipe->bufs);
1295+
kfree(pipe->bufs);
12951296
pipe->bufs = bufs;
12961297
pipe->ring_size = nr_slots;
12971298
if (pipe->max_usage > nr_slots)

0 commit comments

Comments
 (0)