From: Daniel Jordan <daniel.m.jordan@oracle.com>
To: jgg@ziepe.ca
Cc: akpm@linux-foundation.org, dave@stgolabs.net, jack@suse.cz,
cl@linux.com, linux-mm@kvack.org, kvm@vger.kernel.org,
kvm-ppc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org,
alex.williamson@redhat.com, paulus@ozlabs.org,
benh@kernel.crashing.org, mpe@ellerman.id.au, hao.wu@intel.com,
atull@kernel.org, mdf@kernel.org, aik@ozlabs.ru,
daniel.m.jordan@oracle.com
Subject: [PATCH 5/5] kvm/book3s: use pinned_vm instead of locked_vm to account pinned pages
Date: Mon, 11 Feb 2019 17:44:37 -0500 [thread overview]
Message-ID: <20190211224437.25267-6-daniel.m.jordan@oracle.com> (raw)
In-Reply-To: <20190211224437.25267-1-daniel.m.jordan@oracle.com>
Memory used for TCE tables in kvm_vm_ioctl_create_spapr_tce is currently
accounted to locked_vm because it stays resident and its allocation is
directly triggered from userspace as explained in f8626985c7c2 ("KVM:
PPC: Account TCE-containing pages in locked_vm").
However, since the memory comes straight from the page allocator (and to
a lesser extent unreclaimable slab) and is effectively pinned, it should
be accounted with pinned_vm (see bc3e53f682d9 ("mm: distinguish between
mlocked and pinned pages")).
pinned_vm recently became atomic and so no longer relies on mmap_sem
held as writer: delete.
Signed-off-by: Daniel Jordan <daniel.m.jordan@oracle.com>
---
arch/powerpc/kvm/book3s_64_vio.c | 35 ++++++++++++++------------------
1 file changed, 15 insertions(+), 20 deletions(-)
diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c
index 532ab79734c7..2f8d7c051e4e 100644
--- a/arch/powerpc/kvm/book3s_64_vio.c
+++ b/arch/powerpc/kvm/book3s_64_vio.c
@@ -56,39 +56,34 @@ static unsigned long kvmppc_stt_pages(unsigned long tce_pages)
return tce_pages + ALIGN(stt_bytes, PAGE_SIZE) / PAGE_SIZE;
}
-static long kvmppc_account_memlimit(unsigned long stt_pages, bool inc)
+static long kvmppc_account_memlimit(unsigned long pages, bool inc)
{
long ret = 0;
+ s64 pinned_vm;
if (!current || !current->mm)
return ret; /* process exited */
- down_write(¤t->mm->mmap_sem);
-
if (inc) {
- unsigned long locked, lock_limit;
+ unsigned long lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
- locked = current->mm->locked_vm + stt_pages;
- lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
- if (locked > lock_limit && !capable(CAP_IPC_LOCK))
+ pinned_vm = atomic64_add_return(pages, ¤t->mm->pinned_vm);
+ if (pinned_vm > lock_limit && !capable(CAP_IPC_LOCK)) {
ret = -ENOMEM;
- else
- current->mm->locked_vm += stt_pages;
+ atomic64_sub(pages, ¤t->mm->pinned_vm);
+ }
} else {
- if (WARN_ON_ONCE(stt_pages > current->mm->locked_vm))
- stt_pages = current->mm->locked_vm;
+ pinned_vm = atomic64_read(¤t->mm->pinned_vm);
+ if (WARN_ON_ONCE(pages > pinned_vm))
+ pages = pinned_vm;
- current->mm->locked_vm -= stt_pages;
+ atomic64_sub(pages, ¤t->mm->pinned_vm);
}
- pr_debug("[%d] RLIMIT_MEMLOCK KVM %c%ld %ld/%ld%s\n", current->pid,
- inc ? '+' : '-',
- stt_pages << PAGE_SHIFT,
- current->mm->locked_vm << PAGE_SHIFT,
- rlimit(RLIMIT_MEMLOCK),
- ret ? " - exceeded" : "");
-
- up_write(¤t->mm->mmap_sem);
+ pr_debug("[%d] RLIMIT_MEMLOCK KVM %c%lu %ld/%lu%s\n", current->pid,
+ inc ? '+' : '-', pages << PAGE_SHIFT,
+ atomic64_read(¤t->mm->pinned_vm) << PAGE_SHIFT,
+ rlimit(RLIMIT_MEMLOCK), ret ? " - exceeded" : "");
return ret;
}
--
2.20.1
next prev parent reply other threads:[~2019-02-11 22:44 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-11 22:44 [PATCH 0/5] use pinned_vm instead of locked_vm to account pinned pages Daniel Jordan
2019-02-11 22:44 ` [PATCH 1/5] vfio/type1: " Daniel Jordan
2019-02-11 22:56 ` Jason Gunthorpe
2019-02-11 23:11 ` Daniel Jordan
2019-02-12 18:41 ` Alex Williamson
2019-02-13 0:26 ` Daniel Jordan
2019-02-13 20:03 ` Alex Williamson
2019-02-13 23:07 ` Jason Gunthorpe
2019-02-14 1:46 ` Daniel Jordan
2019-02-11 22:44 ` [PATCH 2/5] vfio/spapr_tce: " Daniel Jordan
2019-02-12 6:56 ` Alexey Kardashevskiy
2019-02-12 16:50 ` Christopher Lameter
2019-02-12 17:18 ` Daniel Jordan
2019-02-13 0:37 ` Alexey Kardashevskiy
2019-02-12 18:56 ` Alex Williamson
2019-02-13 0:34 ` Alexey Kardashevskiy
2019-02-11 22:44 ` [PATCH 3/5] fpga/dlf/afu: " Daniel Jordan
2019-02-11 22:44 ` [PATCH 4/5] powerpc/mmu: " Daniel Jordan
2019-02-13 1:14 ` kbuild test robot
2019-02-11 22:44 ` Daniel Jordan [this message]
2019-02-13 1:43 ` [PATCH 5/5] kvm/book3s: " kbuild test robot
2019-02-11 22:54 ` [PATCH 0/5] " Jason Gunthorpe
2019-02-11 23:15 ` Daniel Jordan
2019-02-14 1:53 ` Ira Weiny
2019-02-14 6:00 ` Jason Gunthorpe
2019-02-14 19:33 ` Ira Weiny
2019-02-14 20:12 ` Jason Gunthorpe
2019-02-14 21:46 ` Ira Weiny
2019-02-14 22:16 ` Jason Gunthorpe
2019-02-15 15:26 ` Christopher Lameter
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=20190211224437.25267-6-daniel.m.jordan@oracle.com \
--to=daniel.m.jordan@oracle.com \
--cc=aik@ozlabs.ru \
--cc=akpm@linux-foundation.org \
--cc=alex.williamson@redhat.com \
--cc=atull@kernel.org \
--cc=benh@kernel.crashing.org \
--cc=cl@linux.com \
--cc=dave@stgolabs.net \
--cc=hao.wu@intel.com \
--cc=jack@suse.cz \
--cc=jgg@ziepe.ca \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-fpga@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mdf@kernel.org \
--cc=mpe@ellerman.id.au \
--cc=paulus@ozlabs.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).