Skip to content

Commit

Permalink
Merge pull request #879 from gaoyixiang1/develop
Browse files Browse the repository at this point in the history
根据提取到的zone信息计算每个zone中在不同order下的碎片化程度
  • Loading branch information
chenamy2017 authored Sep 6, 2024
2 parents eb91365 + 629106a commit 8aa66cd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ int BPF_KPROBE(get_page_from_freelist, gfp_t gfp_mask, unsigned int order, int a
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
66 changes: 52 additions & 14 deletions eBPF_Supermarket/Memory_Subsystem/mem_watcher/mem_watcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -1193,18 +1193,39 @@ static int process_memleak(struct memleak_bpf *skel_memleak, struct env env)
}

// ================================================== fraginfo====================================================================
void print_nodes(int fd) {
struct pgdat_info pinfo;
__u64 key = 0, next_key;
printf(" Node ID PGDAT_PTR NR_ZONES \n");
while (bpf_map_get_next_key(fd, &key, &next_key) == 0) {
bpf_map_lookup_elem(fd, &next_key, &pinfo);
printf(" %5d 0x%llx %5d\n",
pinfo.node_id, pinfo.pgdat_ptr, pinfo.nr_zones);
key = next_key;
}
}
//compute order
static int __fragmentation_index(unsigned int order, long unsigned int total,long unsigned int suitable,long unsigned int free) {
unsigned long requested = 1UL << order;
if (order > MAX_ORDER)
return 0;
if (!total)
return 0;
if (suitable)
return -1000;
double res1,res2;
res1 = (double)(free * 1000ULL)/requested;
res1 +=1000;
res2 = (double)res1/total;
return 1000 - res2;
}
static int unusable_free_index(unsigned int order, long unsigned int total,long unsigned int suitable,long unsigned int free)
{
/* No free memory is interpreted as all free memory is unusable */
if (free == 0)
return 1000;

/*
* Index should be a value between 0 and 1. Return a value to 3
* decimal places.
*
* 0 => no fragmentation
* 1 => high fragmentation
*/
long unsigned int res1 = free - (suitable<<order);
double res = (res1*1000ULL)/free;
return res;

}
void print_zones(int fd) {
struct zone_info zinfo;
__u64 key = 0, next_key;
Expand All @@ -1217,6 +1238,17 @@ void print_zones(int fd) {
}

}
void print_nodes(int fd) {
struct pgdat_info pinfo;
__u64 key = 0, next_key;
printf(" Node ID PGDAT_PTR NR_ZONES \n");
while (bpf_map_get_next_key(fd, &key, &next_key) == 0) {
bpf_map_lookup_elem(fd, &next_key, &pinfo);
printf(" %5d 0x%llx %5d\n",
pinfo.node_id, pinfo.pgdat_ptr, pinfo.nr_zones);
key = next_key;
}
}
void print_orders(int fd) {
struct order_zone okey = {};
struct ctg_info oinfo;
Expand All @@ -1235,11 +1267,17 @@ void print_orders(int fd) {
qsort(entries, entry_count, sizeof(struct order_entry), compare_entries);

// 打印排序后的
printf(" Order Zone_PTR Free Pages Free Blocks Total Free Blocks Suitable\n");
printf(" Order Zone_PTR Free Pages Free Blocks Total Free Blocks Suitable SCOREA SCOREB\n");
for (int i = 0; i < entry_count; i++) {
printf(" %-8u 0x%-25llx %-20lu %-20lu %-20lu\n",
int res = __fragmentation_index(entries[i].okey.order,entries[i].oinfo.free_blocks_total,entries[i].oinfo.free_blocks_suitable,entries[i].oinfo.free_pages);
int tmp = unusable_free_index(entries[i].okey.order,entries[i].oinfo.free_blocks_total,entries[i].oinfo.free_blocks_suitable,entries[i].oinfo.free_pages);
int part1 = res/1000;
int dec1 = res%1000;
int part2 = tmp/1000;
int dec2 = tmp%1000;
printf(" %-8u 0x%-25llx %-20lu %-20lu %-20lu %2d.%03d %d.%03d\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);
entries[i].oinfo.free_blocks_total, entries[i].oinfo.free_blocks_suitable,part1,dec1,part2,dec2);
}
}

Expand Down

0 comments on commit 8aa66cd

Please sign in to comment.