Hi,

It would be useful to have system wide major and minor page faults counters. Attached patch makes this possible.

Are there any objections to have it?

--
Andrey Zonov

Index: usr.bin/vmstat/vmstat.c
===================================================================
--- usr.bin/vmstat/vmstat.c     (revision 238738)
+++ usr.bin/vmstat/vmstat.c     (working copy)
@@ -473,6 +473,8 @@ fill_vmmeter(struct vmmeter *vmmp)
                        ADD_FROM_PCPU(i, v_cow_optim);
                        ADD_FROM_PCPU(i, v_zfod);
                        ADD_FROM_PCPU(i, v_ozfod);
+                       ADD_FROM_PCPU(i, v_majflt);
+                       ADD_FROM_PCPU(i, v_minflt);
                        ADD_FROM_PCPU(i, v_swapin);
                        ADD_FROM_PCPU(i, v_swapout);
                        ADD_FROM_PCPU(i, v_swappgsin);
@@ -511,6 +513,8 @@ fill_vmmeter(struct vmmeter *vmmp)
                GET_VM_STATS(vm, v_cow_optim);
                GET_VM_STATS(vm, v_zfod);
                GET_VM_STATS(vm, v_ozfod);
+               GET_VM_STATS(vm, v_majflt);
+               GET_VM_STATS(vm, v_minflt);
                GET_VM_STATS(vm, v_swapin);
                GET_VM_STATS(vm, v_swapout);
                GET_VM_STATS(vm, v_swappgsin);
@@ -966,6 +970,8 @@ dosum(void)
        (void)printf("%9u copy-on-write optimized faults\n", sum.v_cow_optim);
        (void)printf("%9u zero fill pages zeroed\n", sum.v_zfod);
        (void)printf("%9u zero fill pages prezeroed\n", sum.v_ozfod);
+       (void)printf("%9u page faults\n", sum.v_majflt);
+       (void)printf("%9u page reclaims\n", sum.v_minflt);
        (void)printf("%9u intransit blocking page faults\n", sum.v_intrans);
        (void)printf("%9u total VM faults taken\n", sum.v_vm_faults);
        (void)printf("%9u pages affected by kernel thread creation\n", 
sum.v_kthreadpages);
Index: usr.bin/systat/vmstat.c
===================================================================
--- usr.bin/systat/vmstat.c     (revision 238738)
+++ usr.bin/systat/vmstat.c     (working copy)
@@ -82,6 +82,8 @@ static struct Info {
        u_int v_cow_faults;     /* number of copy-on-writes */
        u_int v_zfod;           /* pages zero filled on demand */
        u_int v_ozfod;          /* optimized zero fill pages */
+       u_int v_majflt;         /* page faults */
+       u_int v_minflt;         /* page reclaims */
        u_int v_swapin;         /* swap pager pageins */
        u_int v_swapout;        /* swap pager pageouts */
        u_int v_swappgsin;      /* swap pager pages paged in */
@@ -328,20 +330,22 @@ labelkre(void)
        mvprintw(VMSTATROW + 1, VMSTATCOL + 9, "zfod");
        mvprintw(VMSTATROW + 2, VMSTATCOL + 9, "ozfod");
        mvprintw(VMSTATROW + 3, VMSTATCOL + 9 - 1, "%%ozfod");
-       mvprintw(VMSTATROW + 4, VMSTATCOL + 9, "daefr");
-       mvprintw(VMSTATROW + 5, VMSTATCOL + 9, "prcfr");
-       mvprintw(VMSTATROW + 6, VMSTATCOL + 9, "totfr");
-       mvprintw(VMSTATROW + 7, VMSTATCOL + 9, "react");
-       mvprintw(VMSTATROW + 8, VMSTATCOL + 9, "pdwak");
-       mvprintw(VMSTATROW + 9, VMSTATCOL + 9, "pdpgs");
-       mvprintw(VMSTATROW + 10, VMSTATCOL + 9, "intrn");
-       mvprintw(VMSTATROW + 11, VMSTATCOL + 9, "wire");
-       mvprintw(VMSTATROW + 12, VMSTATCOL + 9, "act");
-       mvprintw(VMSTATROW + 13, VMSTATCOL + 9, "inact");
-       mvprintw(VMSTATROW + 14, VMSTATCOL + 9, "cache");
-       mvprintw(VMSTATROW + 15, VMSTATCOL + 9, "free");
-       if (LINES - 1 > VMSTATROW + 16)
-               mvprintw(VMSTATROW + 16, VMSTATCOL + 9, "buf");
+       mvprintw(VMSTATROW + 4, VMSTATCOL + 9, "majflt");
+       mvprintw(VMSTATROW + 5, VMSTATCOL + 9, "minflt");
+       mvprintw(VMSTATROW + 6, VMSTATCOL + 9, "daefr");
+       mvprintw(VMSTATROW + 7, VMSTATCOL + 9, "prcfr");
+       mvprintw(VMSTATROW + 8, VMSTATCOL + 9, "totfr");
+       mvprintw(VMSTATROW + 9, VMSTATCOL + 9, "react");
+       mvprintw(VMSTATROW + 10, VMSTATCOL + 9, "pdwak");
+       mvprintw(VMSTATROW + 11, VMSTATCOL + 9, "pdpgs");
+       mvprintw(VMSTATROW + 12, VMSTATCOL + 9, "intrn");
+       mvprintw(VMSTATROW + 13, VMSTATCOL + 9, "wire");
+       mvprintw(VMSTATROW + 14, VMSTATCOL + 9, "act");
+       mvprintw(VMSTATROW + 15, VMSTATCOL + 9, "inact");
+       mvprintw(VMSTATROW + 16, VMSTATCOL + 9, "cache");
+       mvprintw(VMSTATROW + 17, VMSTATCOL + 9, "free");
+       if (LINES - 1 > VMSTATROW + 18)
+               mvprintw(VMSTATROW + 18, VMSTATCOL + 9, "buf");
 
        mvprintw(GENSTATROW, GENSTATCOL, " Csw  Trp  Sys  Int  Sof  Flt");
 
@@ -498,20 +502,22 @@ showkre(void)
        PUTRATE(v_ozfod, VMSTATROW + 2, VMSTATCOL, 8);
        putint(s.v_zfod != 0 ? (int)(s.v_ozfod * 100.0 / s.v_zfod) : 0,
            VMSTATROW + 3, VMSTATCOL + 1, 8 - 1);
-       PUTRATE(v_dfree, VMSTATROW + 4, VMSTATCOL + 2, 8 - 2);
-       PUTRATE(v_pfree, VMSTATROW + 5, VMSTATCOL + 2, 8 - 2);
-       PUTRATE(v_tfree, VMSTATROW + 6, VMSTATCOL, 8);
-       PUTRATE(v_reactivated, VMSTATROW + 7, VMSTATCOL, 8);
-       PUTRATE(v_pdwakeups, VMSTATROW + 8, VMSTATCOL, 8);
-       PUTRATE(v_pdpages, VMSTATROW + 9, VMSTATCOL, 8);
-       PUTRATE(v_intrans, VMSTATROW + 10, VMSTATCOL, 8);
-       putint(pgtokb(s.v_wire_count), VMSTATROW + 11, VMSTATCOL, 8);
-       putint(pgtokb(s.v_active_count), VMSTATROW + 12, VMSTATCOL, 8);
-       putint(pgtokb(s.v_inactive_count), VMSTATROW + 13, VMSTATCOL, 8);
-       putint(pgtokb(s.v_cache_count), VMSTATROW + 14, VMSTATCOL, 8);
-       putint(pgtokb(s.v_free_count), VMSTATROW + 15, VMSTATCOL, 8);
-       if (LINES - 1 > VMSTATROW + 16)
-               putint(s.bufspace / 1024, VMSTATROW + 16, VMSTATCOL, 8);
+       PUTRATE(v_majflt, VMSTATROW + 4, VMSTATCOL + 2, 8 - 2);
+       PUTRATE(v_minflt, VMSTATROW + 5, VMSTATCOL + 2, 8 - 2);
+       PUTRATE(v_dfree, VMSTATROW + 6, VMSTATCOL + 2, 8 - 2);
+       PUTRATE(v_pfree, VMSTATROW + 7, VMSTATCOL + 2, 8 - 2);
+       PUTRATE(v_tfree, VMSTATROW + 8, VMSTATCOL, 8);
+       PUTRATE(v_reactivated, VMSTATROW + 9, VMSTATCOL, 8);
+       PUTRATE(v_pdwakeups, VMSTATROW + 10, VMSTATCOL, 8);
+       PUTRATE(v_pdpages, VMSTATROW + 11, VMSTATCOL, 8);
+       PUTRATE(v_intrans, VMSTATROW + 12, VMSTATCOL, 8);
+       putint(pgtokb(s.v_wire_count), VMSTATROW + 13, VMSTATCOL, 8);
+       putint(pgtokb(s.v_active_count), VMSTATROW + 14, VMSTATCOL, 8);
+       putint(pgtokb(s.v_inactive_count), VMSTATROW + 15, VMSTATCOL, 8);
+       putint(pgtokb(s.v_cache_count), VMSTATROW + 16, VMSTATCOL, 8);
+       putint(pgtokb(s.v_free_count), VMSTATROW + 17, VMSTATCOL, 8);
+       if (LINES - 1 > VMSTATROW + 18)
+               putint(s.bufspace / 1024, VMSTATROW + 18, VMSTATCOL, 8);
        PUTRATE(v_vnodein, PAGEROW + 2, PAGECOL + 6, 5);
        PUTRATE(v_vnodeout, PAGEROW + 2, PAGECOL + 12, 5);
        PUTRATE(v_swapin, PAGEROW + 2, PAGECOL + 19, 5);
@@ -754,6 +760,8 @@ getinfo(struct Info *ls)
        GETSYSCTL("vm.stats.vm.v_cow_faults", ls->v_cow_faults);
        GETSYSCTL("vm.stats.vm.v_zfod", ls->v_zfod);
        GETSYSCTL("vm.stats.vm.v_ozfod", ls->v_ozfod);
+       GETSYSCTL("vm.stats.vm.v_majflt", ls->v_majflt);
+       GETSYSCTL("vm.stats.vm.v_minflt", ls->v_minflt);
        GETSYSCTL("vm.stats.vm.v_swapin", ls->v_swapin);
        GETSYSCTL("vm.stats.vm.v_swapout", ls->v_swapout);
        GETSYSCTL("vm.stats.vm.v_swappgsin", ls->v_swappgsin);
Index: sys/vm/vm_fault.c
===================================================================
--- sys/vm/vm_fault.c   (revision 238738)
+++ sys/vm/vm_fault.c   (working copy)
@@ -960,10 +960,13 @@ vnode_locked:
         * Unlock everything, and return
         */
        unlock_and_deallocate(&fs);
-       if (hardfault)
+       if (hardfault) {
+               PCPU_INC(cnt.v_majflt);
                curthread->td_ru.ru_majflt++;
-       else
+       } else {
+               PCPU_INC(cnt.v_minflt);
                curthread->td_ru.ru_minflt++;
+       }
 
        return (KERN_SUCCESS);
 }
Index: sys/vm/vm_meter.c
===================================================================
--- sys/vm/vm_meter.c   (revision 238738)
+++ sys/vm/vm_meter.c   (working copy)
@@ -286,6 +286,8 @@ VM_STATS_VM(v_vm_faults, "Address memory faults");
 VM_STATS_VM(v_cow_faults, "Copy-on-write faults");
 VM_STATS_VM(v_cow_optim, "Optimized COW faults");
 VM_STATS_VM(v_zfod, "Pages zero-filled on demand");
+VM_STATS_VM(v_majflt, "Pages fault");
+VM_STATS_VM(v_minflt, "Pages reclaim");
 VM_STATS_VM(v_ozfod, "Optimized zero fill pages");
 VM_STATS_VM(v_swapin, "Swap pager pageins");
 VM_STATS_VM(v_swapout, "Swap pager pageouts");
Index: sys/sys/vmmeter.h
===================================================================
--- sys/sys/vmmeter.h   (revision 238738)
+++ sys/sys/vmmeter.h   (working copy)
@@ -65,6 +65,8 @@ struct vmmeter {
        u_int v_cow_optim;      /* (p) optimized copy-on-writes faults */
        u_int v_zfod;           /* (p) pages zero filled on demand */
        u_int v_ozfod;          /* (p) optimized zero fill pages */
+       u_int v_majflt;         /* (p) page faults */
+       u_int v_minflt;         /* (p) page reclaims */
        u_int v_swapin;         /* (p) swap pager pageins */
        u_int v_swapout;        /* (p) swap pager pageouts */
        u_int v_swappgsin;      /* (p) swap pager pages paged in */

_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"

Reply via email to