From: Shivank Garg <shivankg@amd.com>
To: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Borislav Petkov <bp@alien8.de>,
Ankur Arora <ankur.a.arora@oracle.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
"Thomas Gleixner" <tglx@kernel.org>,
Bharata B Rao <bharata@amd.com>,
"Hrushikesh Salunke" <hsalunke@amd.com>,
Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
David Laight <david.laight.linux@gmail.com>,
David Rientjes <rientjes@google.com>,
Linus Torvalds <torvalds@linuxfoundation.org>,
"Teja Vojjala" <tejavojjala@google.com>,
Huan Nguyen <nhuhuan@google.com>,
"Pedro Falcato" <pfalcato@suse.de>,
Peter Zijlstra <peterz@infradead.org>, Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Nico Pache <nico.pache@linux.dev>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
Kiryl Shutsemau <kas@kernel.org>,
Ying Huang <ying.huang@linux.alibaba.com>
Cc: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
<x86@kernel.org>, Shivank Garg <shivankg@amd.com>
Subject: [PATCH v4 1/6] mm/highmem: introduce copy_mc_can_batch() and __copy_mc_pages()
Date: Tue, 1 Dec 2026 08:29:47 +0000 [thread overview]
Message-ID: <20261201-batpagecopy-v4-1-dd82a573e573@amd.com> (raw)
In-Reply-To: <20261201-batpagecopy-v4-0-dd82a573e573@amd.com>
Copying a page range with machine check handling one page at a time, as
folio_mc_copy() does with copy_mc_highpage(), makes one
copy_mc_to_kernel() call per page. Each call pays the startup cost of the
string instruction ("REP; MOVSB" on x86 CPUs with ERMS).
Add copy_mc_can_batch(), which tells whether a page range can be copied
with a single copy_mc_to_kernel() call, and __copy_mc_pages(), which
does that copy. On a machine check, __copy_mc_pages() queues the
poisoned source page for memory_failure(), as copy_mc_highpage() does,
and returns -EHWPOISON.
copy_mc_to_kernel() cannot reschedule, so batching requires
CONFIG_PREEMPTION, and the pages must be in the linear map, so it also
requires !CONFIG_HIGHMEM. Since commit 7dadeaa6e851 ("sched: Further
restrict the preemption modes"), x86 and powerpc, the only architectures
that select ARCH_HAS_COPY_MC, only offer the full, lazy and RT
preemption models, also with PREEMPT_DYNAMIC, so they can always batch.
The following patches use them for the page range copies
copy_mc_highpages() and copy_mc_user_highpages().
Signed-off-by: Shivank Garg <shivankg@amd.com>
---
include/linux/highmem.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index c3240f70471d..1bb0c1b707e3 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -490,6 +490,32 @@ static inline int copy_mc_highpage(struct page *to, struct page *from)
}
#endif
+/*
+ * Return true if a page range can be copied with one copy_mc_to_kernel() call.
+ * That call does not reschedule, so the kernel must be preemptible, and the
+ * pages must be in the linear map.
+ */
+static inline bool copy_mc_can_batch(void)
+{
+ return IS_ENABLED(CONFIG_ARCH_HAS_COPY_MC) &&
+ IS_ENABLED(CONFIG_PREEMPTION) && !IS_ENABLED(CONFIG_HIGHMEM);
+}
+
+/* Only valid if copy_mc_can_batch() returns true. */
+static inline int __copy_mc_pages(struct page *to, struct page *from,
+ unsigned long nr_pages)
+{
+ unsigned long len = nr_pages << PAGE_SHIFT;
+ unsigned long ret;
+
+ ret = copy_mc_to_kernel(page_address(to), page_address(from), len);
+ if (!ret)
+ return 0;
+
+ memory_failure_queue(page_to_pfn(from) + ((len - ret) >> PAGE_SHIFT), 0);
+ return -EHWPOISON;
+}
+
static inline void memcpy_page(struct page *dst_page, size_t dst_off,
struct page *src_page, size_t src_off,
size_t len)
--
2.53.0
next prev parent reply other threads:[~2026-12-01 8:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 8:29 [PATCH v4 0/6] mm: copy page ranges with one copy_mc_to_kernel() call Shivank Garg
2026-12-01 8:29 ` Shivank Garg [this message]
2026-12-01 8:29 ` [PATCH v4 2/6] mm: introduce copy_mc_highpages() and batch copy in folio_mc_copy() Shivank Garg
2026-12-01 8:29 ` [PATCH v4 3/6] mm/khugepaged: copy each folio with copy_mc_highpages() in collapse_file() Shivank Garg
2026-12-01 8:29 ` [PATCH v4 4/6] mm/highmem: introduce copy_mc_user_highpages() Shivank Garg
2026-12-01 8:29 ` [PATCH v4 5/6] mm: factor out the locality range computation from folio_zero_user() Shivank Garg
2026-12-01 8:29 ` [PATCH v4 6/6] mm: copy_user_large_folio(): copy page ranges Shivank Garg
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=20261201-batpagecopy-v4-1-dd82a573e573@amd.com \
--to=shivankg@amd.com \
--cc=akpm@linux-foundation.org \
--cc=ankur.a.arora@oracle.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=bharata@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=david.laight.linux@gmail.com \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=hpa@zytor.com \
--cc=hsalunke@amd.com \
--cc=kas@kernel.org \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=nhuhuan@google.com \
--cc=nico.pache@linux.dev \
--cc=peterz@infradead.org \
--cc=pfalcato@suse.de \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=surenb@google.com \
--cc=tejavojjala@google.com \
--cc=tglx@kernel.org \
--cc=torvalds@linuxfoundation.org \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=x86@kernel.org \
--cc=ying.huang@linux.alibaba.com \
--cc=ziy@nvidia.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
all inboxes | Powered by JetHome®