Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/rsrc: refactor io_{un}account_mem() to take {user,mm}_struct param

Refactor io_{un}account_mem() to take user_struct and mm_struct
directly, instead of accessing it from the ring ctx.

Signed-off-by: David Wei <dw@davidwei.uk>
Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

David Wei and committed by
Jens Axboe
6ab39b39 1fa7a341

+21 -16
+14 -12
io_uring/rsrc.c
··· 56 56 return 0; 57 57 } 58 58 59 - void io_unaccount_mem(struct io_ring_ctx *ctx, unsigned long nr_pages) 59 + void io_unaccount_mem(struct user_struct *user, struct mm_struct *mm_account, 60 + unsigned long nr_pages) 60 61 { 61 - if (ctx->user) 62 - __io_unaccount_mem(ctx->user, nr_pages); 62 + if (user) 63 + __io_unaccount_mem(user, nr_pages); 63 64 64 - if (ctx->mm_account) 65 - atomic64_sub(nr_pages, &ctx->mm_account->pinned_vm); 65 + if (mm_account) 66 + atomic64_sub(nr_pages, &mm_account->pinned_vm); 66 67 } 67 68 68 - int io_account_mem(struct io_ring_ctx *ctx, unsigned long nr_pages) 69 + int io_account_mem(struct user_struct *user, struct mm_struct *mm_account, 70 + unsigned long nr_pages) 69 71 { 70 72 int ret; 71 73 72 - if (ctx->user) { 73 - ret = __io_account_mem(ctx->user, nr_pages); 74 + if (user) { 75 + ret = __io_account_mem(user, nr_pages); 74 76 if (ret) 75 77 return ret; 76 78 } 77 79 78 - if (ctx->mm_account) 79 - atomic64_add(nr_pages, &ctx->mm_account->pinned_vm); 80 + if (mm_account) 81 + atomic64_add(nr_pages, &mm_account->pinned_vm); 80 82 81 83 return 0; 82 84 } ··· 147 145 } 148 146 149 147 if (imu->acct_pages) 150 - io_unaccount_mem(ctx, imu->acct_pages); 148 + io_unaccount_mem(ctx->user, ctx->mm_account, imu->acct_pages); 151 149 imu->release(imu->priv); 152 150 io_free_imu(ctx, imu); 153 151 } ··· 686 684 if (!imu->acct_pages) 687 685 return 0; 688 686 689 - ret = io_account_mem(ctx, imu->acct_pages); 687 + ret = io_account_mem(ctx->user, ctx->mm_account, imu->acct_pages); 690 688 if (ret) 691 689 imu->acct_pages = 0; 692 690 return ret;
+4 -2
io_uring/rsrc.h
··· 120 120 int io_files_update_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 121 121 122 122 int __io_account_mem(struct user_struct *user, unsigned long nr_pages); 123 - int io_account_mem(struct io_ring_ctx *ctx, unsigned long nr_pages); 124 - void io_unaccount_mem(struct io_ring_ctx *ctx, unsigned long nr_pages); 123 + int io_account_mem(struct user_struct *user, struct mm_struct *mm_account, 124 + unsigned long nr_pages); 125 + void io_unaccount_mem(struct user_struct *user, struct mm_struct *mm_account, 126 + unsigned long nr_pages); 125 127 126 128 static inline void __io_unaccount_mem(struct user_struct *user, 127 129 unsigned long nr_pages)
+3 -2
io_uring/zcrx.c
··· 200 200 } 201 201 202 202 mem->account_pages = io_count_account_pages(pages, nr_pages); 203 - ret = io_account_mem(ifq->ctx, mem->account_pages); 203 + ret = io_account_mem(ifq->ctx->user, ifq->ctx->mm_account, mem->account_pages); 204 204 if (ret < 0) 205 205 mem->account_pages = 0; 206 206 ··· 389 389 io_release_area_mem(&area->mem); 390 390 391 391 if (area->mem.account_pages) 392 - io_unaccount_mem(area->ifq->ctx, area->mem.account_pages); 392 + io_unaccount_mem(area->ifq->ctx->user, area->ifq->ctx->mm_account, 393 + area->mem.account_pages); 393 394 394 395 kvfree(area->freelist); 395 396 kvfree(area->nia.niovs);