Skip to content

Commit 9aad72b

Browse files
calebsanderaxboe
authored andcommitted
btrfs/ioctl: store btrfs_uring_encoded_data in io_btrfs_cmd
btrfs is the only user of struct io_uring_cmd_data and its op_data field. Switch its ->uring_cmd() implementations to store the struct btrfs_uring_encoded_data * in the struct io_btrfs_cmd, overlayed with io_uring_cmd's pdu field. This avoids having to touch another cache line to access the struct btrfs_uring_encoded_data *, and allows op_data and struct io_uring_cmd_data to be removed. Signed-off-by: Caleb Sander Mateos <[email protected]> Acked-by: David Sterba <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 733c43f commit 9aad72b

1 file changed

Lines changed: 27 additions & 11 deletions

File tree

fs/btrfs/ioctl.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4629,6 +4629,13 @@ static int btrfs_ioctl_encoded_write(struct file *file, void __user *argp, bool
46294629
return ret;
46304630
}
46314631

4632+
struct btrfs_uring_encoded_data {
4633+
struct btrfs_ioctl_encoded_io_args args;
4634+
struct iovec iovstack[UIO_FASTIOV];
4635+
struct iovec *iov;
4636+
struct iov_iter iter;
4637+
};
4638+
46324639
/*
46334640
* Context that's attached to an encoded read io_uring command, in cmd->pdu. It
46344641
* contains the fields in btrfs_uring_read_extent that are necessary to finish
@@ -4650,6 +4657,7 @@ struct btrfs_uring_priv {
46504657
};
46514658

46524659
struct io_btrfs_cmd {
4660+
struct btrfs_uring_encoded_data *data;
46534661
struct btrfs_uring_priv *priv;
46544662
};
46554663

@@ -4708,6 +4716,7 @@ static void btrfs_uring_read_finished(struct io_uring_cmd *cmd, unsigned int iss
47084716
kfree(priv->pages);
47094717
kfree(priv->iov);
47104718
kfree(priv);
4719+
kfree(bc->data);
47114720
}
47124721

47134722
void btrfs_uring_read_extent_endio(void *ctx, int err)
@@ -4791,13 +4800,6 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
47914800
return ret;
47924801
}
47934802

4794-
struct btrfs_uring_encoded_data {
4795-
struct btrfs_ioctl_encoded_io_args args;
4796-
struct iovec iovstack[UIO_FASTIOV];
4797-
struct iovec *iov;
4798-
struct iov_iter iter;
4799-
};
4800-
48014803
static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue_flags)
48024804
{
48034805
size_t copy_end_kernel = offsetofend(struct btrfs_ioctl_encoded_io_args, flags);
@@ -4813,7 +4815,11 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue
48134815
struct extent_state *cached_state = NULL;
48144816
u64 start, lockend;
48154817
void __user *sqe_addr;
4816-
struct btrfs_uring_encoded_data *data = io_uring_cmd_get_async_data(cmd)->op_data;
4818+
struct io_btrfs_cmd *bc = io_uring_cmd_to_pdu(cmd, struct io_btrfs_cmd);
4819+
struct btrfs_uring_encoded_data *data = NULL;
4820+
4821+
if (cmd->flags & IORING_URING_CMD_REISSUE)
4822+
data = bc->data;
48174823

48184824
if (!capable(CAP_SYS_ADMIN)) {
48194825
ret = -EPERM;
@@ -4842,7 +4848,7 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue
48424848
goto out_acct;
48434849
}
48444850

4845-
io_uring_cmd_get_async_data(cmd)->op_data = data;
4851+
bc->data = data;
48464852

48474853
if (issue_flags & IO_URING_F_COMPAT) {
48484854
#if defined(CONFIG_64BIT) && defined(CONFIG_COMPAT)
@@ -4940,6 +4946,9 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue
49404946
add_rchar(current, ret);
49414947
inc_syscr(current);
49424948

4949+
if (ret != -EIOCBQUEUED && ret != -EAGAIN)
4950+
kfree(data);
4951+
49434952
return ret;
49444953
}
49454954

@@ -4950,7 +4959,11 @@ static int btrfs_uring_encoded_write(struct io_uring_cmd *cmd, unsigned int issu
49504959
struct file *file;
49514960
ssize_t ret;
49524961
void __user *sqe_addr;
4953-
struct btrfs_uring_encoded_data *data = io_uring_cmd_get_async_data(cmd)->op_data;
4962+
struct io_btrfs_cmd *bc = io_uring_cmd_to_pdu(cmd, struct io_btrfs_cmd);
4963+
struct btrfs_uring_encoded_data *data = NULL;
4964+
4965+
if (cmd->flags & IORING_URING_CMD_REISSUE)
4966+
data = bc->data;
49544967

49554968
if (!capable(CAP_SYS_ADMIN)) {
49564969
ret = -EPERM;
@@ -4972,7 +4985,7 @@ static int btrfs_uring_encoded_write(struct io_uring_cmd *cmd, unsigned int issu
49724985
goto out_acct;
49734986
}
49744987

4975-
io_uring_cmd_get_async_data(cmd)->op_data = data;
4988+
bc->data = data;
49764989

49774990
if (issue_flags & IO_URING_F_COMPAT) {
49784991
#if defined(CONFIG_64BIT) && defined(CONFIG_COMPAT)
@@ -5062,6 +5075,9 @@ static int btrfs_uring_encoded_write(struct io_uring_cmd *cmd, unsigned int issu
50625075
if (ret > 0)
50635076
add_wchar(current, ret);
50645077
inc_syscw(current);
5078+
5079+
if (ret != -EAGAIN)
5080+
kfree(data);
50655081
return ret;
50665082
}
50675083

0 commit comments

Comments
 (0)