From: Alistair Popple <apopple@nvidia.com>
To: linux-mm@kvack.org, cgroups@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, jgg@nvidia.com,
jhubbard@nvidia.com, tjmercier@google.com, hannes@cmpxchg.org,
surenb@google.com, mkoutny@suse.com, daniel@ffwll.ch,
Alistair Popple <apopple@nvidia.com>,
Christian Benvenuti <benve@cisco.com>,
Nelson Escobar <neescoba@cisco.com>,
Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
linux-rdma@vger.kernel.org
Subject: [RFC PATCH 06/19] RDMA/usnic: convert to use vm_account
Date: Tue, 24 Jan 2023 16:42:35 +1100 [thread overview]
Message-ID: <03ed2d166826cd7055810c66a175e20fa2153c52.1674538665.git-series.apopple@nvidia.com> (raw)
In-Reply-To: <cover.f52b9eb2792bccb8a9ecd6bc95055705cfe2ae03.1674538665.git-series.apopple@nvidia.com>
Convert to using a vm_account structure to account pinned memory to
both the mm and the pins cgroup.
Signed-off-by: Alistair Popple <apopple@nvidia.com>
Cc: Christian Benvenuti <benve@cisco.com>
Cc: Nelson Escobar <neescoba@cisco.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: linux-rdma@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
drivers/infiniband/hw/usnic/usnic_uiom.c | 13 +++++--------
drivers/infiniband/hw/usnic/usnic_uiom.h | 1 +
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/drivers/infiniband/hw/usnic/usnic_uiom.c b/drivers/infiniband/hw/usnic/usnic_uiom.c
index c301b3b..250276e 100644
--- a/drivers/infiniband/hw/usnic/usnic_uiom.c
+++ b/drivers/infiniband/hw/usnic/usnic_uiom.c
@@ -89,8 +89,6 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable,
struct page **page_list;
struct scatterlist *sg;
struct usnic_uiom_chunk *chunk;
- unsigned long locked;
- unsigned long lock_limit;
unsigned long cur_base;
unsigned long npages;
int ret;
@@ -123,10 +121,8 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable,
uiomr->owning_mm = mm = current->mm;
mmap_read_lock(mm);
- locked = atomic64_add_return(npages, ¤t->mm->pinned_vm);
- lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
-
- if ((locked > lock_limit) && !capable(CAP_IPC_LOCK)) {
+ vm_account_init_current(&uiomr->vm_account);
+ if (vm_account_pinned(&uiomr->vm_account, npages)) {
ret = -ENOMEM;
goto out;
}
@@ -178,7 +174,8 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable,
out:
if (ret < 0) {
usnic_uiom_put_pages(chunk_list, 0);
- atomic64_sub(npages, ¤t->mm->pinned_vm);
+ vm_unaccount_pinned(&uiomr->vm_account, npages);
+ vm_account_release(&uiomr->vm_account);
} else
mmgrab(uiomr->owning_mm);
@@ -430,7 +427,7 @@ void usnic_uiom_reg_release(struct usnic_uiom_reg *uiomr)
{
__usnic_uiom_reg_release(uiomr->pd, uiomr, 1);
- atomic64_sub(usnic_uiom_num_pages(uiomr), &uiomr->owning_mm->pinned_vm);
+ vm_unaccount_pinned(&uiomr->vm_account, usnic_uiom_num_pages(uiomr));
__usnic_uiom_release_tail(uiomr);
}
diff --git a/drivers/infiniband/hw/usnic/usnic_uiom.h b/drivers/infiniband/hw/usnic/usnic_uiom.h
index 5a9acf9..5c296a7 100644
--- a/drivers/infiniband/hw/usnic/usnic_uiom.h
+++ b/drivers/infiniband/hw/usnic/usnic_uiom.h
@@ -72,6 +72,7 @@ struct usnic_uiom_reg {
struct list_head chunk_list;
struct work_struct work;
struct mm_struct *owning_mm;
+ struct vm_account vm_account;
};
struct usnic_uiom_chunk {
--
git-series 0.9.1
next prev parent reply other threads:[~2023-01-24 5:45 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 02/19] drivers/vhost: Convert to use vm_account Alistair Popple
2023-01-24 5:55 ` Michael S. Tsirkin
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
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
2023-01-24 15:22 ` Bernard Metzler
2023-01-24 15:56 ` Bernard Metzler
2023-01-30 11:34 ` Alistair Popple
2023-01-30 13:27 ` Bernard Metzler
2023-01-24 5:42 ` Alistair Popple [this message]
2023-01-24 14:41 ` [RFC PATCH 06/19] RDMA/usnic: convert " Jason Gunthorpe
2023-01-30 11:10 ` Alistair Popple
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
2023-01-30 11:12 ` Alistair Popple
2023-01-30 13:21 ` Jason Gunthorpe
2023-01-24 5:42 ` [RFC PATCH 10/19] net: skb: Switch to using vm_account Alistair Popple
2023-01-24 14:51 ` Jason Gunthorpe
2023-01-30 11:17 ` Alistair Popple
2023-02-06 4:36 ` Alistair Popple
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 12/19] kvm/book3s_64_vio: Convert account_locked_vm() to vm_account_pinned() Alistair Popple
2023-01-24 5:42 ` [RFC PATCH 13/19] fpga: dfl: afu: convert to use vm_account Alistair Popple
2023-01-24 5:42 ` [RFC PATCH 14/19] mm: Introduce a cgroup for pinned memory Alistair Popple
2023-01-27 21:44 ` Tejun Heo
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
2023-01-31 0:54 ` Alistair Popple
2023-01-31 5:14 ` Yosry Ahmed
2023-01-31 11:22 ` Alistair Popple
2023-01-31 19:49 ` Yosry Ahmed
2023-01-24 20:12 ` Jason Gunthorpe
2023-01-31 13:57 ` David Hildenbrand
2023-01-31 14:03 ` Jason Gunthorpe
2023-01-31 14:06 ` David Hildenbrand
2023-01-31 14:10 ` Jason Gunthorpe
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=03ed2d166826cd7055810c66a175e20fa2153c52.1674538665.git-series.apopple@nvidia.com \
--to=apopple@nvidia.com \
--cc=benve@cisco.com \
--cc=cgroups@vger.kernel.org \
--cc=daniel@ffwll.ch \
--cc=hannes@cmpxchg.org \
--cc=jgg@nvidia.com \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=neescoba@cisco.com \
--cc=surenb@google.com \
--cc=tjmercier@google.com \
/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).