From: Li RongQing via Linux-erofs <linux-erofs@lists.ozlabs.org>
To: xiang@kernel.org, chao@kernel.org, huyue2@coolpad.com,
jefflexu@linux.alibaba.com, dhavale@google.com,
linux-erofs@lists.ozlabs.org
Cc: Li RongQing <lirongqing@baidu.com>
Subject: [PATCH] erofs: Consider NUMA affinity when allocating memory for per-CPU pcpubuf
Date: Mon, 15 Apr 2024 14:19:40 +0800 [thread overview]
Message-ID: <20240415061940.56864-1-lirongqing@baidu.com> (raw)
per-CPU pcpubufs are dominantly accessed from their own local CPUs,
so allocate them node-local to improve performance.
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
fs/erofs/internal.h | 1 +
fs/erofs/pcpubuf.c | 5 +++--
fs/erofs/utils.c | 14 ++++++++++++++
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 39c6711..94c8b62 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -446,6 +446,7 @@ int __init erofs_init_sysfs(void);
void erofs_exit_sysfs(void);
struct page *erofs_allocpage(struct page **pagepool, gfp_t gfp);
+struct page *erofs_allocpage_node(struct page **pagepool, gfp_t gfp, int nid);
static inline void erofs_pagepool_add(struct page **pagepool, struct page *page)
{
set_page_private(page, (unsigned long)*pagepool);
diff --git a/fs/erofs/pcpubuf.c b/fs/erofs/pcpubuf.c
index c7a4b1d..b0b05a3 100644
--- a/fs/erofs/pcpubuf.c
+++ b/fs/erofs/pcpubuf.c
@@ -62,16 +62,17 @@ int erofs_pcpubuf_growsize(unsigned int nrpages)
for_each_possible_cpu(cpu) {
struct erofs_pcpubuf *pcb = &per_cpu(erofs_pcb, cpu);
struct page **pages, **oldpages;
+ int nid = cpu_to_node(cpu);
void *ptr, *old_ptr;
- pages = kmalloc_array(nrpages, sizeof(*pages), GFP_KERNEL);
+ pages = kmalloc_array_node(nrpages, sizeof(*pages), GFP_KERNEL, nid);
if (!pages) {
ret = -ENOMEM;
break;
}
for (i = 0; i < nrpages; ++i) {
- pages[i] = erofs_allocpage(&pagepool, GFP_KERNEL);
+ pages[i] = erofs_allocpage_node(&pagepool, GFP_KERNEL, nid);
if (!pages[i]) {
ret = -ENOMEM;
oldpages = pages;
diff --git a/fs/erofs/utils.c b/fs/erofs/utils.c
index 518bdd6..ba5ba68 100644
--- a/fs/erofs/utils.c
+++ b/fs/erofs/utils.c
@@ -18,6 +18,20 @@ struct page *erofs_allocpage(struct page **pagepool, gfp_t gfp)
return page;
}
+
+struct page *erofs_allocpage_node(struct page **pagepool, gfp_t gfp, int nid)
+{
+ struct page *page = *pagepool;
+
+ if (page) {
+ DBG_BUGON(page_ref_count(page) != 1);
+ *pagepool = (struct page *)page_private(page);
+ } else {
+ page = alloc_pages_node(nid, gfp, 0);
+ }
+ return page;
+}
+
void erofs_release_pages(struct page **pagepool)
{
while (*pagepool) {
--
2.9.4
next reply other threads:[~2024-04-15 6:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 6:19 Li RongQing via Linux-erofs [this message]
2024-04-15 7:58 ` [PATCH] erofs: Consider NUMA affinity when allocating memory for per-CPU pcpubuf Gao Xiang
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=20240415061940.56864-1-lirongqing@baidu.com \
--to=linux-erofs@lists.ozlabs.org \
--cc=chao@kernel.org \
--cc=dhavale@google.com \
--cc=huyue2@coolpad.com \
--cc=jefflexu@linux.alibaba.com \
--cc=lirongqing@baidu.com \
--cc=xiang@kernel.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 read-only IMAP folder(s) and NNTP newsgroup(s).