* [PATCH 5.9 0/2] memory accounting fixes
@ 2020-07-18 8:31 Pavel Begunkov
2020-07-18 8:31 ` [PATCH 1/2] io_uring: don't miscount pinned memory Pavel Begunkov
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Pavel Begunkov @ 2020-07-18 8:31 UTC (permalink / raw)
To: Jens Axboe, io-uring
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(-)
--
2.24.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] io_uring: don't miscount pinned memory
2020-07-18 8:31 [PATCH 5.9 0/2] memory accounting fixes Pavel Begunkov
@ 2020-07-18 8:31 ` Pavel Begunkov
2020-07-18 8:31 ` [PATCH 2/2] io_uring: return locked and pinned page accounting Pavel Begunkov
2020-07-18 14:37 ` [PATCH 5.9 0/2] memory accounting fixes Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2020-07-18 8:31 UTC (permalink / raw)
To: Jens Axboe, io-uring
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.
Fixes: 309758254ea62 ("io_uring: report pinned memory usage")
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 644e5727389c..e535152fefab 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -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);
--
2.24.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] io_uring: return locked and pinned page accounting
2020-07-18 8:31 [PATCH 5.9 0/2] memory accounting fixes Pavel Begunkov
2020-07-18 8:31 ` [PATCH 1/2] io_uring: don't miscount pinned memory Pavel Begunkov
@ 2020-07-18 8:31 ` Pavel Begunkov
2020-07-18 14:37 ` [PATCH 5.9 0/2] memory accounting fixes Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2020-07-18 8:31 UTC (permalink / raw)
To: Jens Axboe, io-uring
Locked 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.
Fixes: 8eb06d7e8dd85 ("io_uring: fix missing ->mm on exit")
Signed-off-by: Pavel Begunkov <[email protected]>
---
fs/io_uring.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index e535152fefab..57e1f26b6a6b 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -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;
--
2.24.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 5.9 0/2] memory accounting fixes
2020-07-18 8:31 [PATCH 5.9 0/2] memory accounting fixes Pavel Begunkov
2020-07-18 8:31 ` [PATCH 1/2] io_uring: don't miscount pinned memory Pavel Begunkov
2020-07-18 8:31 ` [PATCH 2/2] io_uring: return locked and pinned page accounting Pavel Begunkov
@ 2020-07-18 14:37 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2020-07-18 14:37 UTC (permalink / raw)
To: Pavel Begunkov, io-uring
On 7/18/20 2:31 AM, Pavel Begunkov wrote:
> 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(-)
Thanks, applied.
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-07-18 14:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-18 8:31 [PATCH 5.9 0/2] memory accounting fixes Pavel Begunkov
2020-07-18 8:31 ` [PATCH 1/2] io_uring: don't miscount pinned memory Pavel Begunkov
2020-07-18 8:31 ` [PATCH 2/2] io_uring: return locked and pinned page accounting Pavel Begunkov
2020-07-18 14:37 ` [PATCH 5.9 0/2] memory accounting fixes Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox