Skip to content

Commit

Permalink
打印每个zone中每个order对应的contig_page_info (#866)
Browse files Browse the repository at this point in the history
Signed-off-by: gaoyixiang1 <[email protected]>
  • Loading branch information
gaoyixiang1 authored Jul 24, 2024
1 parent 1bdef19 commit dcb5d0c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SEC("kprobe/get_page_from_freelist")
int BPF_KPROBE(get_page_from_freelist, gfp_t gfp_mask, unsigned int order, int alloc_flags,
const struct alloc_context *ac)
{
bpf_printk("1111");
// bpf_printk("1111");
struct pgdat_info node_info = {};
struct zone_info zone_data = {};

Expand Down Expand Up @@ -82,11 +82,16 @@ int BPF_KPROBE(get_page_from_freelist, gfp_t gfp_mask, unsigned int order, int a
zone_data.order = a_order;
struct order_zone order_key = {};
order_key.order = a_order;
if ((u64)z == 0) break;
order_key.zone_ptr = (u64)z;
struct contig_page_info ctg_info = {};
fill_contig_page_info(z, a_order, &ctg_info);
bpf_map_update_elem(&orders,&order_key,&ctg_info,BPF_ANY);
}
bpf_printk("Order: %d, Free pages: %lu, Free blocks total: %lu, Free blocks suitable: %lu",
a_order, ctg_info.free_pages, ctg_info.free_blocks_total, ctg_info.free_blocks_suitable);
bpf_printk("2");
}

bpf_map_update_elem(&zones, &zone_key, &zone_data, BPF_ANY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct zone_info
{
u64 zone_ptr;
u64 zone_start_pfn;
//spanned_pages: 代表的是这个zone中所有的页,包含空洞,计算公式是: zone_end_pfn - zone_start_pfn
//present_pages: 代表的是这个zone中可用的所有物理页,计算公式是:spanned_pages-hole_pages
u64 spanned_pages;
u64 present_pages;
char comm[32];
Expand Down
47 changes: 47 additions & 0 deletions eBPF_Supermarket/Memory_Subsystem/mem_watcher/mem_watcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,24 @@ struct allocation
__u64 size;
size_t count;
};
// ============================= fraginfo====================================
struct order_entry {
struct order_zone okey;
struct ctg_info oinfo;
};

int compare_entries(const void *a, const void *b) {
struct order_entry *entryA = (struct order_entry *)a;
struct order_entry *entryB = (struct order_entry *)b;

if (entryA->okey.zone_ptr != entryB->okey.zone_ptr) {
return (entryA->okey.zone_ptr < entryB->okey.zone_ptr) ? -1 : 1;
} else {
return (entryA->okey.order < entryB->okey.order) ? -1 : 1;
}
}

// ============================= fraginfo====================================
static struct allocation *allocs;

static volatile bool exiting = false;
Expand Down Expand Up @@ -1125,6 +1142,33 @@ void print_zones(int fd) {
}

}
void print_orders(int fd) {
struct order_zone okey = {};
struct ctg_info oinfo;
struct order_entry entries[256];
int entry_count = 0;

while (bpf_map_get_next_key(fd, &okey, &okey) == 0) {
if (bpf_map_lookup_elem(fd, &okey, &oinfo) == 0) {
entries[entry_count].okey = okey;
entries[entry_count].oinfo = oinfo;
entry_count++;
}
}

//排序
qsort(entries, entry_count, sizeof(struct order_entry), compare_entries);

// 打印排序后的
printf(" Order Zone_PTR Free Pages Free Blocks Total Free Blocks Suitable\n");
for (int i = 0; i < entry_count; i++) {
printf(" %-8u 0x%-25llx %-20lu %-20lu %-20lu\n",
entries[i].okey.order, entries[i].okey.zone_ptr, entries[i].oinfo.free_pages,
entries[i].oinfo.free_blocks_total, entries[i].oinfo.free_blocks_suitable);
}
}


static int process_fraginfo(struct fraginfo_bpf *skel_fraginfo)
{

Expand All @@ -1146,6 +1190,9 @@ static int process_fraginfo(struct fraginfo_bpf *skel_fraginfo)
print_nodes(bpf_map__fd(skel_fraginfo->maps.nodes));
printf("\n");
print_zones(bpf_map__fd(skel_fraginfo->maps.zones));
printf("\n");
print_orders(bpf_map__fd(skel_fraginfo->maps.orders));
printf("\n");
}

fraginfo_cleanup:
Expand Down

0 comments on commit dcb5d0c

Please sign in to comment.