* [PATCH] erofs: Consider NUMA affinity when allocating memory for per-CPU pcpubuf
@ 2024-04-15 6:19 Li RongQing via Linux-erofs
2024-04-15 7:58 ` Gao Xiang
0 siblings, 1 reply; 2+ messages in thread
From: Li RongQing via Linux-erofs @ 2024-04-15 6:19 UTC (permalink / raw)
To: xiang, chao, huyue2, jefflexu, dhavale, linux-erofs; +Cc: Li RongQing
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] erofs: Consider NUMA affinity when allocating memory for per-CPU pcpubuf
2024-04-15 6:19 [PATCH] erofs: Consider NUMA affinity when allocating memory for per-CPU pcpubuf Li RongQing via Linux-erofs
@ 2024-04-15 7:58 ` Gao Xiang
0 siblings, 0 replies; 2+ messages in thread
From: Gao Xiang @ 2024-04-15 7:58 UTC (permalink / raw)
To: Li RongQing; +Cc: huyue2, linux-erofs
Hi RongQing,
On Mon, Apr 15, 2024 at 02:19:40PM +0800, Li RongQing wrote:
> 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>
Thanks for your patch! Yeah, NUMA-aware is important to
NUMA bare metal server scenarios.
In the next cycle, we also reduce the total number of buffers
since we don't such many per-CPU buffers if there are too many
CPUs: we called "global buffers" and maintain CPU->global
buffer mappings. Also erofs_allocpage() won't be used to
allocate too.
For more details, see my for-next branch:
https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git/log/?h=dev
So could you make some difference to make the new global
buffers NUMA-aware? (both for allocation and mapping, maybe
the allocation is still a priority stuff if per-CPU is needed
anyway.)
Thanks,
Gao Xiang
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-15 7:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-15 6:19 [PATCH] erofs: Consider NUMA affinity when allocating memory for per-CPU pcpubuf Li RongQing via Linux-erofs
2024-04-15 7:58 ` Gao Xiang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.