cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alistair Popple <apopple-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
To: Bernard Metzler <BMT-OA+xvbQnYDHMbYB6QlFGEg@public.gmane.org>
Cc: Jason Gunthorpe <jgg-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
	"linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org"
	<linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org>,
	"cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"jhubbard-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org"
	<jhubbard-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
	"tjmercier-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org"
	<tjmercier-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	"hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org"
	<hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>,
	"surenb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org"
	<surenb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	"mkoutny-IBi9RG/b67k@public.gmane.org"
	<mkoutny-IBi9RG/b67k@public.gmane.org>,
	"daniel-/w4YWyX8dFk@public.gmane.org"
	<daniel-/w4YWyX8dFk@public.gmane.org>,
	Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	"linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: Re: [RFC PATCH 05/19] RMDA/siw: Convert to use vm_account
Date: Mon, 30 Jan 2023 22:34:50 +1100	[thread overview]
Message-ID: <87lelkz23e.fsf@nvidia.com> (raw)
In-Reply-To: <SA0PR15MB3919F0CCF1D878DE8B243B0199C99-QVqTciyWr1pbckbNN7pyz4d3EbNNOtPMvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>


Bernard Metzler <BMT-OA+xvbQnYDHMbYB6QlFGEg@public.gmane.org> writes:

>> -----Original Message-----
>> From: Jason Gunthorpe <jgg-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>> Sent: Tuesday, 24 January 2023 15:37
>> To: Alistair Popple <apopple-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>> Cc: linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org; cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; linux-
>> kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; jhubbard-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org; tjmercier-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org;
>> hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org; surenb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org; mkoutny-IBi9RG/b67k@public.gmane.org; daniel-/w4YWyX8dFk@public.gmane.org;
>> Bernard Metzler <BMT-OA+xvbQnYDHMbYB6QlFGEg@public.gmane.org>; Leon Romanovsky <leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>;
>> linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>> Subject: [EXTERNAL] Re: [RFC PATCH 05/19] RMDA/siw: Convert to use
>> vm_account
>> 
>> On Tue, Jan 24, 2023 at 04:42:34PM +1100, Alistair Popple wrote:
>> 
>> > @@ -385,20 +382,16 @@ struct siw_umem *siw_umem_get(u64 start, u64 len,
>> bool writable)
>> >  	if (!umem)
>> >  		return ERR_PTR(-ENOMEM);
>> >
>> > -	mm_s = current->mm;
>> > -	umem->owning_mm = mm_s;
>> >  	umem->writable = writable;
>> >
>> > -	mmgrab(mm_s);
>> > +	vm_account_init_current(&umem->vm_account);
>> >
>> >  	if (writable)
>> >  		foll_flags |= FOLL_WRITE;
>> >
>> > -	mmap_read_lock(mm_s);
>> > +	mmap_read_lock(current->mm);
>> >
>> > -	mlock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
>> > -
>> > -	if (num_pages + atomic64_read(&mm_s->pinned_vm) > mlock_limit) {
>> > +	if (vm_account_pinned(&umem->vm_account, num_pages)) {
>> >  		rv = -ENOMEM;
>> >  		goto out_sem_up;
>> >  	}
>> > @@ -429,7 +422,6 @@ struct siw_umem *siw_umem_get(u64 start, u64 len,
>> bool writable)
>> >  				goto out_sem_up;
>> >
>> >  			umem->num_pages += rv;
>> > -			atomic64_add(rv, &mm_s->pinned_vm);
>> 
>> Also fixes the race bug
>
> But introduces another one. In that loop, umem->num_pages keeps the
> number of pages currently pinned, not the target number. The current
> patch uses that umem->num_pages to call vm_unaccount_pinned() in
> siw_umem_release(). Bailing out before all pages are pinned would
> mess up that accounting during release. Maybe introduce another
> parameter to siw_umem_release(), or better have another umem member
> 'umem->num_pages_accounted' for correct accounting during release.

Yes, I see the problem thanks for pointing it out. Will fix for the next
version.

> Bernard.
>> 
>> Jason


  parent reply	other threads:[~2023-01-30 11:34 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24  5:42 [RFC PATCH 00/19] mm: Introduce a cgroup to limit the amount of locked and pinned memory Alistair Popple
2023-01-24  5:42 ` [RFC PATCH 01/19] mm: Introduce vm_account Alistair Popple
2023-01-24  6:29   ` Christoph Hellwig
2023-01-24 14:32   ` Jason Gunthorpe
2023-01-30 11:36     ` Alistair Popple
2023-01-31 14:00   ` David Hildenbrand
2023-01-24  5:42 ` [RFC PATCH 07/19] vfio/type1: Charge pinned pages to pinned_vm instead of locked_vm Alistair Popple
2023-01-24  5:42 ` [RFC PATCH 08/19] vfio/spapr_tce: Convert accounting to pinned_vm Alistair Popple
2023-01-24  5:42 ` [RFC PATCH 09/19] io_uring: convert to use vm_account Alistair Popple
2023-01-24 14:44   ` Jason Gunthorpe
     [not found]     ` <Y8/uyBKHf5XoXvTW-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2023-01-30 11:12       ` Alistair Popple
2023-01-30 13:21         ` Jason Gunthorpe
2023-01-24  5:42 ` [RFC PATCH 12/19] kvm/book3s_64_vio: Convert account_locked_vm() to vm_account_pinned() Alistair Popple
     [not found] ` <cover.f52b9eb2792bccb8a9ecd6bc95055705cfe2ae03.1674538665.git-series.apopple-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2023-01-24  5:42   ` [RFC PATCH 02/19] drivers/vhost: Convert to use vm_account Alistair Popple
2023-01-24  5:55     ` Michael S. Tsirkin
     [not found]       ` <20230124005356-mutt-send-email-mst-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2023-01-30 10:43         ` Alistair Popple
2023-01-24 14:34     ` Jason Gunthorpe
2023-01-24  5:42   ` [RFC PATCH 03/19] drivers/vdpa: Convert vdpa to use the new vm_structure Alistair Popple
     [not found]     ` <f2e4696380f6678527a14e885556cb1bbd314737.1674538665.git-series.apopple-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2023-01-24 14:35       ` Jason Gunthorpe
2023-01-24  5:42   ` [RFC PATCH 04/19] infiniband/umem: Convert to use vm_account Alistair Popple
2023-01-24  5:42   ` [RFC PATCH 05/19] RMDA/siw: " Alistair Popple
2023-01-24 14:37     ` Jason Gunthorpe
     [not found]       ` <Y8/tGIeg5mI9bDOa-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2023-01-24 15:22         ` Bernard Metzler
2023-01-24 15:56         ` Bernard Metzler
     [not found]           ` <SA0PR15MB3919F0CCF1D878DE8B243B0199C99-QVqTciyWr1pbckbNN7pyz4d3EbNNOtPMvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2023-01-30 11:34             ` Alistair Popple [this message]
2023-01-30 13:27               ` Bernard Metzler
2023-01-24  5:42   ` [RFC PATCH 06/19] RDMA/usnic: convert " Alistair Popple
     [not found]     ` <03ed2d166826cd7055810c66a175e20fa2153c52.1674538665.git-series.apopple-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2023-01-24 14:41       ` Jason Gunthorpe
     [not found]         ` <Y8/uGL+TA7ow4Zmu-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2023-01-30 11:10           ` Alistair Popple
2023-01-24  5:42   ` [RFC PATCH 10/19] net: skb: Switch to using vm_account Alistair Popple
     [not found]     ` <9b54eef0b41b678cc5f318bd5ae0917bba5b8e21.1674538665.git-series.apopple-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2023-01-24 14:51       ` Jason Gunthorpe
2023-01-30 11:17         ` Alistair Popple
     [not found]           ` <87pmawz2ma.fsf-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2023-02-06  4:36             ` Alistair Popple
     [not found]               ` <878rhbflcs.fsf-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2023-02-06 13:14                 ` Jason Gunthorpe
2023-01-24  5:42   ` [RFC PATCH 11/19] xdp: convert to use vm_account Alistair Popple
2023-01-24  5:42   ` [RFC PATCH 13/19] fpga: dfl: afu: " Alistair Popple
2023-01-24  5:42   ` [RFC PATCH 14/19] mm: Introduce a cgroup for pinned memory Alistair Popple
     [not found]     ` <183372b80aac73e640d9f5ac3c742d505fc6c1f2.1674538665.git-series.apopple-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2023-01-27 21:44       ` Tejun Heo
     [not found]         ` <Y9RFs+90TyzVMs83-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2023-01-30 13:20           ` Jason Gunthorpe
2023-01-24  5:42   ` [RFC PATCH 15/19] mm/util: Extend vm_account to charge pages against the pin cgroup Alistair Popple
2023-01-24  5:42   ` [RFC PATCH 16/19] mm/util: Refactor account_locked_vm Alistair Popple
2023-01-24  5:42   ` [RFC PATCH 17/19] mm: Convert mmap and mlock to use account_locked_vm Alistair Popple
2023-01-24  5:42   ` [RFC PATCH 18/19] mm/mmap: Charge locked memory to pins cgroup Alistair Popple
2023-01-24  5:42   ` [RFC PATCH 19/19] selftests/vm: Add pins-cgroup selftest for mlock/mmap Alistair Popple
2023-01-24 18:26   ` [RFC PATCH 00/19] mm: Introduce a cgroup to limit the amount of locked and pinned memory Yosry Ahmed
     [not found]     ` <CAJD7tkavoSu9WOnw4Nbxz41nq+Rm6Sq5EeOjh3CTyA=AT5=ujg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-01-31  0:54       ` Alistair Popple
     [not found]         ` <874js7zf38.fsf-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2023-01-31  5:14           ` Yosry Ahmed
     [not found]             ` <CAJD7tkZTvXjoNZYC99yekbA0zHkD4iFj0J3+8dsOMht6rxrRcQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-01-31 11:22               ` Alistair Popple
     [not found]                 ` <87r0vblzf3.fsf-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2023-01-31 19:49                   ` Yosry Ahmed
2023-01-24 20:12   ` Jason Gunthorpe
2023-01-31 13:57     ` David Hildenbrand
     [not found]       ` <6369225e-3522-341b-cd20-d95b1f11ea71-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2023-01-31 14:03         ` Jason Gunthorpe
2023-01-31 14:06           ` David Hildenbrand
     [not found]             ` <2e78d261-9ae9-d203-446e-eaa3c652ca6e-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2023-01-31 14:10               ` Jason Gunthorpe
     [not found]                 ` <Y9khYwunmC/xdXT9-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2023-01-31 14:15                   ` David Hildenbrand
2023-01-31 14:21                     ` Jason Gunthorpe

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=87lelkz23e.fsf@nvidia.com \
    --to=apopple-ddmlm1+adcrqt0dzr+alfa@public.gmane.org \
    --cc=BMT-OA+xvbQnYDHMbYB6QlFGEg@public.gmane.org \
    --cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=daniel-/w4YWyX8dFk@public.gmane.org \
    --cc=hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org \
    --cc=jgg-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=jhubbard-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mkoutny-IBi9RG/b67k@public.gmane.org \
    --cc=surenb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=tjmercier-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.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;
as well as URLs for NNTP newsgroup(s).