From: Sumitra Sharma <sumitraartsy@gmail.com>
To: "Jérôme Glisse" <jglisse@redhat.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: Deepak R Varma <drv@mailo.com>,
"Fabio M. De Francesco" <fmdefrancesco@gmail.com>,
Ira Weiny <ira.weiny@intel.com>
Subject: [PATCH] staging: lib: Use memcpy_to/from_page()
Date: Thu, 8 Jun 2023 07:25:53 -0700 [thread overview]
Message-ID: <20230608142553.GA341787@sumitra.com> (raw)
Deprecate kmap() in favor of kmap_local_page() due to high
cost, restricted mapping space, the overhead of a global lock
for synchronization, and making the process sleep in the
absence of free slots.
kmap_local_page() offers thread-local and CPU-local mappings,
take pagefaults in a local kmap region and preserves preemption
by saving the mappings of outgoing task and restoring those of
the incoming one during a context switch.
It is faster than kmap(), and in functions "dmirror_do_read" and
"dmirror_do_write" the mappings are kept local to the thread.
Therefore, replace kmap/mem*()/kunmap pattern with
memcpy_to/from_page() and remove the unused variable "tmp".
Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com>
---
Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
lib/test_hmm.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/lib/test_hmm.c b/lib/test_hmm.c
index 67e6f83fe0f8..cc96dfa54122 100644
--- a/lib/test_hmm.c
+++ b/lib/test_hmm.c
@@ -368,16 +368,13 @@ static int dmirror_do_read(struct dmirror *dmirror, unsigned long start,
for (pfn = start >> PAGE_SHIFT; pfn < (end >> PAGE_SHIFT); pfn++) {
void *entry;
struct page *page;
- void *tmp;
entry = xa_load(&dmirror->pt, pfn);
page = xa_untag_pointer(entry);
if (!page)
return -ENOENT;
- tmp = kmap(page);
- memcpy(ptr, tmp, PAGE_SIZE);
- kunmap(page);
+ memcpy_from_page((char *)ptr, page, 0, PAGE_SIZE);
ptr += PAGE_SIZE;
bounce->cpages++;
@@ -437,16 +434,13 @@ static int dmirror_do_write(struct dmirror *dmirror, unsigned long start,
for (pfn = start >> PAGE_SHIFT; pfn < (end >> PAGE_SHIFT); pfn++) {
void *entry;
struct page *page;
- void *tmp;
entry = xa_load(&dmirror->pt, pfn);
page = xa_untag_pointer(entry);
if (!page || xa_pointer_tag(entry) != DPT_XA_TAG_WRITE)
return -ENOENT;
- tmp = kmap(page);
- memcpy(tmp, ptr, PAGE_SIZE);
- kunmap(page);
+ memcpy_to_page(page, 0, (char *)ptr, PAGE_SIZE);
ptr += PAGE_SIZE;
bounce->cpages++;
--
2.25.1
reply other threads:[~2023-06-08 14:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230608142553.GA341787@sumitra.com \
--to=sumitraartsy@gmail.com \
--cc=drv@mailo.com \
--cc=fmdefrancesco@gmail.com \
--cc=ira.weiny@intel.com \
--cc=jglisse@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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).