I'm trying to create a system call that is able to report on memory management statistics. My goal is to be able to report on the following:
I'm not entirely knowledgeable on how to access this information. I know that in mmzone.h
there is an array I can use called vm_stat
injunction with the enum zone_stat_item
and enum node_stat_item
that will allow me to gather information about 1, but does mmzone.h
contain information about 2 through 8. For example, would I use vm_stat[NR_SLAB_RECLAIMABLE]
and vm_stat[NR_SLAB_UNRECLAIMABLE]
to calculate 2? If not, where would I be able to access information that would satisfy 2 through 8? I'm confused because the variable names alone I find to be not very descriptive.
I don't know about 2,5,6,7, or 8. However, for 3 and 4 you can iterate through all the zones(using the for_each_zone
macro that is also definedin mmzone.h
), and use the enum zone_stat_item:
enum zone_stat_item {
/* First 128 byte cacheline (assuming 64 bit words) */
NR_FREE_PAGES,
NR_ZONE_LRU_BASE, /* Used only for compaction and reclaim retry */
NR_ZONE_INACTIVE_ANON = NR_ZONE_LRU_BASE,
NR_ZONE_ACTIVE_ANON,
NR_ZONE_INACTIVE_FILE,
NR_ZONE_ACTIVE_FILE,
NR_ZONE_UNEVICTABLE,
NR_ZONE_WRITE_PENDING, /* Count of dirty, writeback and unstable pages */
NR_MLOCK, /* mlock()ed pages found and moved off LRU */
NR_PAGETABLE, /* used for pagetables */
NR_KERNEL_STACK_KB, /* measured in KiB */
/* Second 128 byte cacheline */
NR_BOUNCE,
#if IS_ENABLED(CONFIG_ZSMALLOC)
NR_ZSPAGES, /* allocated in zsmalloc */
#endif
NR_FREE_CMA_PAGES,
NR_VM_ZONE_STAT_ITEMS };
If you take a look at vmstat.h
you will find this useful function:
static inline unsigned long zone_page_state(struct zone *zone,
enum zone_stat_item item){
long x = atomic_long_read(&zone->vm_stat[item]);
#ifdef CONFIG_SMP
if (x < 0)
x = 0;
#endif
return x;
}
Which you can use to get the values for each of those elements in that enum. To get answer 3 you add the NR_ACTIVE_ANON
with the NR_ACTIVE_FILE
for each zone. For 4, you get the sum of NR_INACTIVE_ANON
and NR_INACTIVE_FILE
for each zone.
Let me know how you are able to get the remaining items if you end up figuring it out.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.