[patch]add some metrics about free pages
"Wu, Liming" <[email protected]>
| Newsgroups | gmane.comp.sysutils.pcp |
|---|---|
| Message-ID | <[email protected]> |
Hi:
This patch add some metrics about free pages(/proc/zoneinfo) .
please refer to the attachment for the details.
Output is as follows.
# pminfo -f mem.zone
mem.zone.dma_free
inst [0 or "node0"] value 3816
mem.zone.dma32_free
inst [0 or "node0"] value 16834
mem.zone.normal_free
inst [0 or "node0"] value 13868
Thanks,
--
Liming Wu
--
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links:
You receive all messages sent to this group.
View/Reply Online (#14902): https://groups.io/g/pcp/message/14902
View All Messages In Topic (1): https://groups.io/g/pcp/topic/3804331
Mute This Topic: https://groups.io/mt/3804331?uid=174580
New Topic: https://groups.io/g/pcp/post
Change Your Subscription: https://groups.io/g/pcp/editsub?uid=174580
Group Home: https://groups.io/g/pcp
Contact Group Owner: [email protected]
Terms of Service: https://groups.io/static/tos
Unsubscribe: https://groups.io/g/pcp/leave/354243/563757577/xyzzy
-=-=-
pcp mailing list
[email protected]
https://groups.io/g/pcp/messages
-=-=-=-=-=-=-=-=-=-=-=-
Add-some-metrics-about-free-pages.patch
(application/octet-stream, 12.6 KB)
From 92789063d5030d85eed7c613f7aae5a673b207de Mon Sep 17 00:00:00 2001 From: Liming <[email protected]> Date: Wed, 14 Dec 2016 17:26:52 +0800 Subject: [PATCH] Add some metrics about free pages these metrics are read from /proc/zoneinfo. --- src/pmdas/linux/GNUmakefile | 6 +- src/pmdas/linux/clusters.h | 1 + src/pmdas/linux/help | 4 ++ src/pmdas/linux/indom.h | 1 + src/pmdas/linux/pmda.c | 63 +++++++++++++++++++ src/pmdas/linux/proc_zoneinfo.c | 130 ++++++++++++++++++++++++++++++++++++++++ src/pmdas/linux/proc_zoneinfo.h | 27 +++++++++ src/pmdas/linux/root_linux | 10 +++- 8 files changed, 239 insertions(+), 3 deletions(-) create mode 100644 src/pmdas/linux/proc_zoneinfo.c create mode 100644 src/pmdas/linux/proc_zoneinfo.h diff --git a/src/pmdas/linux/GNUmakefile b/src/pmdas/linux/GNUmakefile index 7f80a40..52a4080 100644 --- a/src/pmdas/linux/GNUmakefile +++ b/src/pmdas/linux/GNUmakefile @@ -35,7 +35,8 @@ CFILES = pmda.c \ proc_slabinfo.c proc_sys_fs.c proc_vmstat.c \ sysfs_kernel.c linux_table.c numa_meminfo.c \ proc_net_netstat.c namespaces.c proc_net_softnet.c \ - proc_net_snmp6.c mem_bandwidth.c proc_buddyinfo.c + proc_net_snmp6.c mem_bandwidth.c proc_buddyinfo.c \ + proc_zoneinfo.c HFILES = clusters.h indom.h convert.h \ proc_stat.h proc_meminfo.h proc_loadavg.h \ @@ -46,7 +47,7 @@ HFILES = clusters.h indom.h convert.h \ proc_slabinfo.h proc_sys_fs.h proc_vmstat.h \ sysfs_kernel.h linux_table.h numa_meminfo.h \ proc_net_netstat.h namespaces.h proc_net_softnet.h \ - proc_net_snmp6.h proc_buddyinfo.h + proc_net_snmp6.h proc_buddyinfo.h proc_zoneinfo.h VERSION_SCRIPT = exports HELPTARGETS = help.dir help.pag @@ -134,4 +135,5 @@ pmda.o proc_vmstat.o: proc_vmstat.h pmda.o swapdev.o: swapdev.h pmda.o sysfs_kernel.o: sysfs_kernel.h pmda.o proc_buddyinfo.o: proc_buddyinfo.h +pmda.o proc_zoneinfo.o: proc_zoneinfo.h pmda.o: $(VERSION_SCRIPT) diff --git a/src/pmdas/linux/clusters.h b/src/pmdas/linux/clusters.h index 82c131f..c5fcb99 100644 --- a/src/pmdas/linux/clusters.h +++ b/src/pmdas/linux/clusters.h @@ -88,6 +88,7 @@ enum { CLUSTER_MSG_STAT, /* 65 msgctl(MSG_STAT) system call */ CLUSTER_SEM_STAT, /* 66 msgctl(SEM_STAT) system call */ CLUSTER_BUDDYINFO, /* 67 /proc/buddyinfo */ + CLUSTER_ZONEINFO, /* 68 /proc/zoneinfo */ NUM_CLUSTERS /* one more than highest numbered cluster */ }; diff --git a/src/pmdas/linux/help b/src/pmdas/linux/help index bc16153..d81ccd0 100644 --- a/src/pmdas/linux/help +++ b/src/pmdas/linux/help @@ -894,6 +894,10 @@ Count of huge TLB page buddy allocation successes, from /proc/vmstat @ mem.vmstat.balloon_inflate count of virt guest balloon page inflations @ mem.vmstat.balloon_deflate number of virt guest balloon page deflations @ mem.vmstat.balloon_migrate number of virt guest balloon page migrations +@ mem.zone.dma_free free pages of zone_dma +@ mem.zone.dma32_free free pages of zone_dma32(x86_64) +@ mem.zone.normal_free free pages of zone_normal +@ mem.zone.highmem_free free pages of zone_highmem(i386) @ swap.length total swap available metric from /proc/meminfo @ swap.used swap used metric from /proc/meminfo diff --git a/src/pmdas/linux/indom.h b/src/pmdas/linux/indom.h index 572a838..e4ad92a 100644 --- a/src/pmdas/linux/indom.h +++ b/src/pmdas/linux/indom.h @@ -50,6 +50,7 @@ enum { IPC_MSG_INDOM, /* 29 - ipc msg_stat msgid */ IPC_SEM_INDOM, /* 30 - ipc sem_stat msgid */ BUDDYINFO_INDOM, /* 31 - kernel buddys */ + ZONEINFO_INDOM, /* 32 - proc zoneinfo */ NUM_INDOMS /* one more than highest numbered cluster */ }; diff --git a/src/pmdas/linux/pmda.c b/src/pmdas/linux/pmda.c index 3c4aedf..0ad594d 100644 --- a/src/pmdas/linux/pmda.c +++ b/src/pmdas/linux/pmda.c @@ -64,6 +64,7 @@ #include "ipc.h" #include "proc_net_softnet.h" #include "proc_buddyinfo.h" +#include "proc_zoneinfo.h" static proc_stat_t proc_stat; static proc_meminfo_t proc_meminfo; @@ -335,6 +336,7 @@ static pmdaIndom indomtab[] = { { IPC_MSG_INDOM, 0, NULL }, { IPC_SEM_INDOM, 0, NULL }, { BUDDYINFO_INDOM, 0, NULL }, + { ZONEINFO_INDOM, 0, NULL }, }; @@ -3540,6 +3542,30 @@ static pmdaMetric metrictab[] = { PMDA_PMUNITS(0,0,0,0,0,0) }, }, /* + * /proc/zoneinfo cluster + */ + +/* mem.zone.dma_free */ + { NULL, + { PMDA_PMID(CLUSTER_ZONEINFO, 0), PM_TYPE_U64, ZONEINFO_INDOM, PM_SEM_INSTANT, + PMDA_PMUNITS(0,0,0,0,0,0) } }, + +/* mem.zone.dma32_free */ + { NULL, + { PMDA_PMID(CLUSTER_ZONEINFO, 1), PM_TYPE_U64, ZONEINFO_INDOM, PM_SEM_INSTANT, + PMDA_PMUNITS(0,0,0,0,0,0) } }, + +/* mem.zone.normal_free */ + { NULL, + { PMDA_PMID(CLUSTER_ZONEINFO, 2), PM_TYPE_U64, ZONEINFO_INDOM, PM_SEM_INSTANT, + PMDA_PMUNITS(0,0,0,0,0,0) } }, + +/* mem.zone.highmem_free */ + { NULL, + { PMDA_PMID(CLUSTER_ZONEINFO, 3), PM_TYPE_U64, ZONEINFO_INDOM, PM_SEM_INSTANT, + PMDA_PMUNITS(0,0,0,0,0,0) } }, + +/* * /proc/cpuinfo cluster (cpu indom) */ @@ -4917,6 +4943,9 @@ linux_refresh(pmdaExt *pmda, int *need_refresh, int context) if (need_refresh[CLUSTER_BUDDYINFO]) refresh_proc_buddyinfo(&proc_buddyinfo); + if (need_refresh[CLUSTER_ZONEINFO]) + refresh_proc_zoneinfo(INDOM(ZONEINFO_INDOM)); + done: if (need_refresh_mtab) pmdaDynamicMetricTable(pmda); @@ -4992,6 +5021,9 @@ linux_instance(pmInDom indom, int inst, char *name, __pmInResult **result, pmdaE case BUDDYINFO_INDOM: need_refresh[CLUSTER_BUDDYINFO]++; break; + case ZONEINFO_INDOM: + need_refresh[CLUSTER_ZONEINFO]++; + break; /* no default label : pmdaInstance will pick up errors */ } @@ -6258,6 +6290,37 @@ linux_fetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom) /* * Cluster added by Wu Liming <[email protected]> */ + case CLUSTER_ZONEINFO: { + zoneinfo_entry_t *zoneinfo_entry; + sts = pmdaCacheLookup(INDOM(ZONEINFO_INDOM), inst, NULL, (void **)&zoneinfo_entry); + if (sts < 0) + return sts; + if (sts == PMDA_CACHE_INACTIVE) + return PM_ERR_INST; + switch (idp->item) { + + case 0: /* mem.zone.dma_free */ + atom->ull = zoneinfo_entry->dma_free; + break; + + case 1: /* mem.zone.dma32_free */ + atom->ull = zoneinfo_entry->dma32_free; + break; + + case 2: /* mem.zone.normal_free */ + atom->ull = zoneinfo_entry->normal_free; + break; + + case 3: /* mem.zone.highmem_free */ + atom->ull = zoneinfo_entry->highmem_free; + break; + + default: + return PM_ERR_PMID; + } + break; + } + case CLUSTER_SEM_INFO: switch (idp->item) { case 0: /* ipc.sem.used_sem */ diff --git a/src/pmdas/linux/proc_zoneinfo.c b/src/pmdas/linux/proc_zoneinfo.c new file mode 100644 index 0000000..b6f0faa --- /dev/null +++ b/src/pmdas/linux/proc_zoneinfo.c @@ -0,0 +1,130 @@ +/* + * Linux zoneinfo Cluster + * + * Copyright (c) 2016 fujitsu. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "pmapi.h" +#include "impl.h" +#include "pmda.h" +#include "indom.h" +#include "proc_zoneinfo.h" +#define SYSFS_NODE_PATH "/sys/devices/system/node" + +int get_nodes(){ + DIR * dir; + struct dirent * ptr; + int nodes =0; + dir = opendir(SYSFS_NODE_PATH); + while((ptr = readdir(dir)) != NULL) + { + if (strstr(ptr->d_name, "node")) { + nodes++; + } + } + return nodes; +} + +int +refresh_proc_zoneinfo(pmInDom indom) +{ + int sts; + zoneinfo_entry_t *ze; + int nodeid = 0; + char node_id[20]; + int i = 0; + char *sp; + int nodes = get_nodes(); + zoneinfo_entry_t *info; + char type[20]; + int page_free = 0; + FILE *fp; + char buf[1024]; + + pmdaCacheOp(indom, PMDA_CACHE_INACTIVE); + if ((fp = linux_statsfile("/proc/zoneinfo", buf, sizeof(buf))) == NULL) + return -oserror(); + for (i=0; i < nodes; i++) { + info = (zoneinfo_entry_t *)malloc(sizeof(zoneinfo_entry_t)); + info->dma32_free = 0; + info->dma_free = 0; + info->normal_free = 0; + info->highmem_free = 0; + while(fgets(buf, sizeof(buf), fp) != NULL){ + if (strncmp(buf, "Node", 4) != 0) + continue; + + if (sscanf(buf, "Node %d, zone %s", &nodeid, type) != 2) + continue; + if (i == nodeid) { + snprintf(node_id, sizeof(node_id), "node%d", nodeid); + node_id[sizeof(node_id)-1] = '\0'; + while(fgets(buf, sizeof(buf), fp) != NULL){ + if ((sp = strstr(buf, "pages free")) != (char *)NULL) { + if (sscanf(sp, "pages free %d", &page_free) == 1) { + + if (strncmp(type, "Normal", 6) ==0) { + info->normal_free = page_free; + } +#ifdef __x86_64__ + else if (strncmp(type, "DMA32", 5) == 0) { + info->dma32_free = page_free; + } +#elif __i386__ + else if (strncmp(type, "HighMem", 7) ==0) { + info->highmem_free = page_free; + } +#endif + else if(strncmp(type, "DMA", 3) == 0) { + info->dma_free = page_free; + } + break; + } + } + } + } + } + fseek(fp, 0L, 0); + sts = pmdaCacheLookupName(indom, node_id, NULL, (void **)&ze); + if (sts == PMDA_CACHE_ACTIVE) + continue; + if (sts == PMDA_CACHE_INACTIVE) { + ze = info; + sts = pmdaCacheStore(indom, PMDA_CACHE_ADD, node_id, (void *)ze); + } + else { + if ((ze = (zoneinfo_entry_t *)malloc(sizeof(zoneinfo_entry_t))) == NULL) { + continue; + } + memset(ze, 0, sizeof(zoneinfo_entry_t)); + + ze = info; + sts = pmdaCacheStore(indom, PMDA_CACHE_ADD, node_id, (void *)ze); + if (sts < 0) { + fprintf(stderr, "Warning: refresh_proc_zoneinfo: pmdaCacheOp(%s, ADD, \"%s\"): %s\n", + pmInDomStr(indom), node_id, pmErrStr(sts)); + free(ze); + } +#if PCP_DEBUG + else { + if (pmDebug & DBG_TRACE_LIBPMDA) + fprintf(stderr, "refresh_proc_zoneinfo: instance \"%s\" = \"\n", + node_id); + } +#endif + } + } + pmdaCacheOp(indom, PMDA_CACHE_SAVE); + fclose(fp); + return 0; +} diff --git a/src/pmdas/linux/proc_zoneinfo.h b/src/pmdas/linux/proc_zoneinfo.h new file mode 100644 index 0000000..5fdfaa6 --- /dev/null +++ b/src/pmdas/linux/proc_zoneinfo.h @@ -0,0 +1,27 @@ +/* + * Linux /proc/zoneinfo metrics cluster + * + * Copyright (c) 2016 fujitsu. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +typedef struct { + unsigned long long dma_free; + unsigned long long dma32_free; + unsigned long long normal_free; + unsigned long long highmem_free; +} zoneinfo_entry_t; + +extern int refresh_proc_zoneinfo(pmInDom indom); diff --git a/src/pmdas/linux/root_linux b/src/pmdas/linux/root_linux index 0f8fbd9..2a019f9 100644 --- a/src/pmdas/linux/root_linux +++ b/src/pmdas/linux/root_linux @@ -378,6 +378,7 @@ mem { numa slabinfo vmstat + zone } mem.util { @@ -483,7 +484,14 @@ mem.numa.alloc { interleave_hit 60:36:35 local_node 60:36:36 other_node 60:36:37 -} +} + +mem.zone { + dma_free 60:68:0 + dma32_free 60:68:1 + normal_free 60:68:2 + highmem_free 60:68:3 +} swap { pagesin 60:0:8 -- 1.8.3.1