public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Bijan Mottahedeh <bijan.mottahedeh@oracle.com>
Cc: io-uring@vger.kernel.org
Subject: Re: [RFC 2/2] io_uring: report pinned memory usage
Date: Sun, 14 Jun 2020 09:57:40 -0600	[thread overview]
Message-ID: <87ca7d67-95ab-2d91-8dd3-beb6dcd56e93@kernel.dk> (raw)
In-Reply-To: <32054e77-0ee4-ebab-d2c3-fef92261eecf@oracle.com>

On 6/12/20 10:43 PM, Bijan Mottahedeh wrote:
> On 6/12/2020 8:19 AM, Jens Axboe wrote:
>> On 6/12/20 9:16 AM, Jens Axboe wrote:
>>> On 6/11/20 8:23 PM, Bijan Mottahedeh wrote:
>>>> Long term, it makes sense to separate reporting and enforcing of pinned
>>>> memory usage.
>>>>
>>>> Signed-off-by: Bijan Mottahedeh <bijan.mottahedeh@oracle.com>
>>>>
>>>> It is useful to view
>>>> ---
>>>>   fs/io_uring.c | 4 ++++
>>>>   1 file changed, 4 insertions(+)
>>>>
>>>> diff --git a/fs/io_uring.c b/fs/io_uring.c
>>>> index 4248726..cf3acaa 100644
>>>> --- a/fs/io_uring.c
>>>> +++ b/fs/io_uring.c
>>>> @@ -7080,6 +7080,8 @@ static int io_sq_offload_start(struct io_ring_ctx *ctx,
>>>>   static void io_unaccount_mem(struct user_struct *user, unsigned long nr_pages)
>>>>   {
>>>>   	atomic_long_sub(nr_pages, &user->locked_vm);
>>>> +	if (current->mm)
>>>> +		atomic_long_sub(nr_pages, &current->mm->pinned_vm);
>>>>   }
>>>>   
>>>>   static int io_account_mem(struct user_struct *user, unsigned long nr_pages)
>>>> @@ -7096,6 +7098,8 @@ static int io_account_mem(struct user_struct *user, unsigned long nr_pages)
>>>>   			return -ENOMEM;
>>>>   	} while (atomic_long_cmpxchg(&user->locked_vm, cur_pages,
>>>>   					new_pages) != cur_pages);
>>>> +	if (current->mm)
>>>> +		atomic_long_add(nr_pages, &current->mm->pinned_vm);
>>>>   
>>>>   	return 0;
>>>>   }
>>> current->mm should always be valid for these, so I think you can skip the
>>> checking of that and just make it unconditional.
>> Two other issues with this:
>>
>> - It's an atomic64, so seems more appropriate to use the atomic64 helpers
>>    for this one.
>> - The unaccount could potentially be a different mm, if the ring is shared
>>    and one task sets it up while another tears it down. So we'd need something
>>    to ensure consistency here.
>>
> Are you referring to a case where one process creates a ring and sends 
> the ring fd to another process?

Or a simpler case, where someone has submissions and completions running
on separate threads, and it just so happens that the completion side is
the one to exit the ring.

-- 
Jens Axboe


      reply	other threads:[~2020-06-14 15:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-12  2:23 [RFC 0/2] io_uring: disallow overlapping ranges for buffer registration Bijan Mottahedeh
2020-06-12  2:23 ` [RFC 1/2] " Bijan Mottahedeh
2020-06-12 15:16   ` Jens Axboe
2020-06-12 18:22     ` Bijan Mottahedeh
2020-06-14 15:56       ` Jens Axboe
2020-06-12  2:23 ` [RFC 2/2] io_uring: report pinned memory usage Bijan Mottahedeh
2020-06-12 15:16   ` Jens Axboe
2020-06-12 15:19     ` Jens Axboe
2020-06-12 15:50       ` Jens Axboe
2020-06-13  4:43       ` Bijan Mottahedeh
2020-06-14 15:57         ` Jens Axboe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ca7d67-95ab-2d91-8dd3-beb6dcd56e93@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=bijan.mottahedeh@oracle.com \
    --cc=io-uring@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox