This is an optional patch, to provide a small performance improvement.[...]
Alter account_pipe_buffers() so that it returns the new value in
user->pipe_bufs. This means that we can refactor too_many_pipe_buffers_soft()
and too_many_pipe_buffers_hard() to avoid the costs of repeated use of
atomic_long_read() to get the value user->pipe_bufs.
@@ -627,17 +625,18 @@ struct pipe_inode_info *alloc_pipe_info(void)
struct pipe_inode_info *pipe;
unsigned long pipe_bufs = PIPE_DEF_BUFFERS;
struct user_struct *user = get_current_user();
+ unsigned long num_bufs;
pipe = kzalloc(sizeof(struct pipe_inode_info), GFP_KERNEL_ACCOUNT);
if (pipe == NULL)
goto out_free_uid;
- if (too_many_pipe_buffers_soft(user))
+ if (too_many_pipe_buffers_soft(atomic_long_read(&user->pipe_bufs)))
pipe_bufs = 1;
- account_pipe_buffers(user, 0, pipe_bufs);
+ num_bufs = account_pipe_buffers(user, 0, pipe_bufs);
- if (too_many_pipe_buffers_hard(user))
+ if (too_many_pipe_buffers_hard(num_bufs))
goto out_revert_acct;
pipe->bufs = kcalloc(pipe_bufs, sizeof(struct pipe_buffer),