public inbox for [email protected]
 help / color / mirror / Atom feed
From: Jens Axboe <[email protected]>
To: Bijan Mottahedeh <[email protected]>
Cc: [email protected]
Subject: Re: [RFC 2/2] io_uring: report pinned memory usage
Date: Fri, 12 Jun 2020 09:19:18 -0600	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

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 <[email protected]>
>>
>> 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.

-- 
Jens Axboe


  reply	other threads:[~2020-06-12 15:19 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 [this message]
2020-06-12 15:50       ` Jens Axboe
2020-06-13  4:43       ` Bijan Mottahedeh
2020-06-14 15:57         ` Jens Axboe

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 \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /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