memory accounting fixes
cover memory accounting fixes
Two small memory accounting fixes for 5.9
Pavel Begunkov (2):
io_uring: don't miscount pinned memory
io_uring: return locked and pinned page accounting
fs/io_uring.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
Signature · 1 line
2.24.0
PATCH 1/2 io_uring: don't miscount pinned memory
io_sqe_buffer_unregister() uses cxt->sqo_mm for memory accounting, but io_ring_ctx_free() drops ->sqo_mm before leaving pinned_vm over-accounted. Postpone mm cleanup for when it's not needed anymore.
--- fs/io_uring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/io_uring.c +1 -1
@@ -7655,12 +7655,12 @@ static void io_destroy_buffers(struct io_ring_ctx *ctx)static void io_ring_ctx_free (struct io_ring_ctx *ctx) {io_finish_async (ctx); +io_sqe_buffer_unregister (ctx);if (ctx->sqo_mm) {mmdrop (ctx->sqo_mm); ctx->sqo_mm =NULL ; } -io_sqe_buffer_unregister (ctx);io_sqe_files_unregister (ctx);io_eventfd_unregister (ctx);io_destroy_buffers (ctx);
Signature · 1 line
2.24.0
PATCH 2/2 io_uring: return locked and pinned page accounting
In reply to Pavel BegunkovLocked and pinned memory accounting in io_{,un}account_mem() depends on having ->sqo_mm, which is NULL after a recent change for non SQPOLL'ed io_ring. That disables the accounting.
Return ->sqo_mm initialisation back, and do __io_sq_thread_acquire_mm() based on IORING_SETUP_SQPOLL flag.
--- fs/io_uring.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/io_uring.c +5 -4
@@ -980,7 +980,8 @@ static void io_sq_thread_drop_mm(void)static int __io_sq_thread_acquire_mm (struct io_ring_ctx *ctx) {if (!current->mm) { -if (unlikely (!ctx->sqo_mm || !mmget_not_zero (ctx->sqo_mm))) +if (unlikely (!(ctx->flags &IORING_SETUP_SQPOLL ) || + !mmget_not_zero (ctx->sqo_mm)))return -EFAULT ;kthread_use_mm (ctx->sqo_mm); }
@@ -7244,10 +7245,10 @@ static int io_sq_offload_start(struct io_ring_ctx *ctx, {int ret; -if (ctx->flags &IORING_SETUP_SQPOLL ) { -mmgrab (current->mm); - ctx->sqo_mm = current->mm; +mmgrab (current->mm); + ctx->sqo_mm = current->mm; +if (ctx->flags &IORING_SETUP_SQPOLL ) { ret = -EPERM ;if (!capable (CAP_SYS_ADMIN )) goto err;
Signature · 1 line
2.24.0
Quoted 8 lines · Pavel Begunkov
Two small memory accounting fixes for 5.9
Pavel Begunkov (2):
io_uring: don't miscount pinned memory
io_uring: return locked and pinned page accountingfs/io_uring.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
Thanks, applied.
Signature · 1 line
Jens Axboe