The xarray can be used in many kernel subsystems.
For the page cache, it can support the large folio
which needs special operations.
So this patch adds a new parameter for do_xarray, and
adds a new type field in xarray_ops to distinguish them.
Also adds macro XARRAY_TYPE_PAGE_CACHE for page cache case.
Signed-off-by: Huang Shijie <huangsj(a)hygon.cn>
---
bpf.c | 8 ++++----
defs.h | 5 ++++-
dev.c | 4 ++--
diskdump.c | 10 ++++++++--
filesys.c | 7 +++++--
ipcs.c | 4 ++--
kernel.c | 4 ++--
task.c | 4 ++--
8 files changed, 29 insertions(+), 17 deletions(-)
diff --git a/bpf.c b/bpf.c
index 2840c7d..8702596 100644
--- a/bpf.c
+++ b/bpf.c
@@ -344,7 +344,7 @@ bpf_init(struct bpf_info *bpf)
break;
case IDR_XARRAY:
bpf->progs = do_xarray(symbol_value("prog_idr") + OFFSET(idr_idr_rt),
- XARRAY_COUNT, NULL);
+ XARRAY_COUNT, NULL, 0);
break;
}
@@ -364,7 +364,7 @@ bpf_init(struct bpf_info *bpf)
break;
case IDR_XARRAY:
bpf->progs = do_xarray(symbol_value("prog_idr") + OFFSET(idr_idr_rt),
- XARRAY_GATHER, bpf->proglist);
+ XARRAY_GATHER, bpf->proglist, 0);
break;
}
}
@@ -380,7 +380,7 @@ bpf_init(struct bpf_info *bpf)
break;
case IDR_XARRAY:
bpf->maps = do_xarray(symbol_value("map_idr") + OFFSET(idr_idr_rt),
- XARRAY_COUNT, NULL);
+ XARRAY_COUNT, NULL, 0);
break;
}
@@ -400,7 +400,7 @@ bpf_init(struct bpf_info *bpf)
break;
case IDR_XARRAY:
bpf->maps = do_xarray(symbol_value("map_idr") + OFFSET(idr_idr_rt),
- XARRAY_GATHER, bpf->maplist);
+ XARRAY_GATHER, bpf->maplist, 0);
break;
}
}
diff --git a/defs.h b/defs.h
index a6f4372..8f6784e 100644
--- a/defs.h
+++ b/defs.h
@@ -5691,6 +5691,7 @@ struct xarray_ops {
void (*entry)(ulong node, ulong slot, const char *path,
ulong index, void *private);
uint radix;
+ uint type;
void *private;
};
int do_xarray_traverse(ulong ptr, int is_root, struct xarray_ops *ops);
@@ -5996,7 +5997,9 @@ ulong do_radix_tree(ulong, int, struct list_pair *);
#define RADIX_TREE_ENTRY_MASK 3UL
#define RADIX_TREE_EXCEPTIONAL_ENTRY 2
-ulong do_xarray(ulong, int, struct list_pair *);
+ulong do_xarray(ulong, int, struct list_pair *, int);
+#define XARRAY_TYPE_PAGE_CACHE 1
+
#define XARRAY_COUNT (1)
#define XARRAY_SEARCH (2)
#define XARRAY_DUMP (3)
diff --git a/dev.c b/dev.c
index 1332b0e..23f3219 100644
--- a/dev.c
+++ b/dev.c
@@ -4487,12 +4487,12 @@ static void get_mq_diskio_from_hw_queues(ulong q, struct diskio
*dio)
if (VALID_MEMBER(request_queue_hctx_table)) {
addr = q + OFFSET(request_queue_hctx_table);
- cnt = do_xarray(addr, XARRAY_COUNT, NULL);
+ cnt = do_xarray(addr, XARRAY_COUNT, NULL, 0);
lp = (struct list_pair *)GETBUF(sizeof(struct list_pair) * (cnt + 1));
if (!lp)
error(FATAL, "fail to get memory for list_pair.\n");
lp[0].index = cnt;
- cnt = do_xarray(addr, XARRAY_GATHER, lp);
+ cnt = do_xarray(addr, XARRAY_GATHER, lp, 0);
} else {
addr = q + OFFSET(request_queue_nr_hw_queues);
readmem(addr, KVADDR, &cnt, sizeof(uint),
diff --git a/diskdump.c b/diskdump.c
index 20f8b19..456e5cf 100644
--- a/diskdump.c
+++ b/diskdump.c
@@ -2947,6 +2947,7 @@ lookup_swap_cache(ulonglong pte_val, unsigned char *zram_buf)
struct list_pair lp;
physaddr_t paddr;
static int is_xarray = -1;
+ ulong ret;
if (is_xarray < 0) {
is_xarray = STREQ(MEMBER_TYPE_NAME("address_space", "i_pages"),
"xarray");
@@ -2969,8 +2970,13 @@ lookup_swap_cache(ulonglong pte_val, unsigned char *zram_buf)
swp_space += (swp_offset >> SWAP_ADDRESS_SPACE_SHIFT) * SIZE(address_space);
lp.index = swp_offset;
- if ((is_xarray ? do_xarray : do_radix_tree)
- (swp_space+OFFSET(address_space_page_tree), RADIX_TREE_SEARCH, &lp)) {
+
+ if (is_xarray)
+ ret = do_xarray(swp_space+OFFSET(address_space_page_tree), RADIX_TREE_SEARCH, &lp,
0);
+ else
+ ret = do_radix_tree(swp_space+OFFSET(address_space_page_tree), RADIX_TREE_SEARCH,
&lp);
+
+ if (ret) {
if ((is_xarray ? xa_is_value : radix_tree_exceptional_entry)((ulong)lp.value)) {
/* ignore shadow values */
return NULL;
diff --git a/filesys.c b/filesys.c
index 34944e2..1e070a3 100644
--- a/filesys.c
+++ b/filesys.c
@@ -2289,7 +2289,7 @@ dump_inode_page_cache_info(ulong inode)
if (root_rnode)
count = do_radix_tree(root_rnode, RADIX_TREE_DUMP_CB, &lp);
else if (xarray)
- count = do_xarray(xarray, XARRAY_DUMP_CB, &lp);
+ count = do_xarray(xarray, XARRAY_DUMP_CB, &lp, XARRAY_TYPE_PAGE_CACHE);
if (count != nrpages)
error(INFO, "%s page count: %ld nrpages: %ld\n",
@@ -4305,9 +4305,11 @@ static void do_xarray_dump_cb(ulong node, ulong slot, const char
*path,
* any chance of an overrun.
* For XARRAY_DUMP_CB, the rtp->value must be initialized as a
* callback function. The callback prototype must be: int (*)(ulong);
+ *
+ * type: different xarray use types.
*/
ulong
-do_xarray(ulong root, int flag, struct list_pair *xp)
+do_xarray(ulong root, int flag, struct list_pair *xp, int type)
{
struct do_xarray_info info = {
.count = 0,
@@ -4315,6 +4317,7 @@ do_xarray(ulong root, int flag, struct list_pair *xp)
};
struct xarray_ops ops = {
.radix = 16,
+ .type = type,
.private = &info,
};
diff --git a/ipcs.c b/ipcs.c
index 59dc9b6..9cf2418 100644
--- a/ipcs.c
+++ b/ipcs.c
@@ -1150,13 +1150,13 @@ gather_xarray_entries(ulong ipcs_idr_p)
{
long len;
- ipcs_table.cnt = do_xarray(ipcs_idr_p, XARRAY_COUNT, NULL);
+ ipcs_table.cnt = do_xarray(ipcs_idr_p, XARRAY_COUNT, NULL, 0);
if (ipcs_table.cnt) {
len = sizeof(struct list_pair) * (ipcs_table.cnt+1);
ipcs_table.lp = (struct list_pair *)GETBUF(len);
ipcs_table.lp[0].index = ipcs_table.cnt;
- ipcs_table.cnt = do_xarray(ipcs_idr_p, XARRAY_GATHER, ipcs_table.lp);
+ ipcs_table.cnt = do_xarray(ipcs_idr_p, XARRAY_GATHER, ipcs_table.lp, 0);
} else
ipcs_table.lp = NULL;
}
diff --git a/kernel.c b/kernel.c
index 8781d6a..870fb3b 100644
--- a/kernel.c
+++ b/kernel.c
@@ -6883,7 +6883,7 @@ get_irq_desc_addr(int irq)
break;
case IRQ_DESC_TREE_XARRAY:
cnt = do_xarray(symbol_value("irq_desc_tree"),
- XARRAY_COUNT, NULL);
+ XARRAY_COUNT, NULL, 0);
break;
}
len = sizeof(struct list_pair) * (cnt+1);
@@ -6898,7 +6898,7 @@ get_irq_desc_addr(int irq)
break;
case IRQ_DESC_TREE_XARRAY:
cnt = do_xarray(symbol_value("irq_desc_tree"),
- XARRAY_GATHER, lp);
+ XARRAY_GATHER, lp, 0);
break;
}
diff --git a/task.c b/task.c
index ec04b55..2d9c4e4 100644
--- a/task.c
+++ b/task.c
@@ -2610,7 +2610,7 @@ refresh_xarray_task_table(void)
curpid = CURRENT_PID();
}
- count = do_xarray(tt->pid_xarray, XARRAY_COUNT, NULL);
+ count = do_xarray(tt->pid_xarray, XARRAY_COUNT, NULL, 0);
if (CRASHDEBUG(1))
console("xarray: count: %ld\n", count);
@@ -2641,7 +2641,7 @@ retry_xarray:
tt->callbacks = 0;
xp.index = 0;
xp.value = (void *)&xarray_task_callback;
- count = do_xarray(tt->pid_xarray, XARRAY_DUMP_CB, &xp);
+ count = do_xarray(tt->pid_xarray, XARRAY_DUMP_CB, &xp, 0);
if (CRASHDEBUG(1))
console("do_xarray: count: %ld tt->callbacks: %d\n", count,
tt->callbacks);
--
2.43.0