The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/vm/vm_meter.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * SPDX-License-Identifier: BSD-3-Clause
    3  *
    4  * Copyright (c) 1982, 1986, 1989, 1993
    5  *      The Regents of the University of California.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. Neither the name of the University nor the names of its contributors
   16  *    may be used to endorse or promote products derived from this software
   17  *    without specific prior written permission.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  *
   31  *      @(#)vm_meter.c  8.4 (Berkeley) 1/4/94
   32  */
   33 
   34 #include <sys/cdefs.h>
   35 __FBSDID("$FreeBSD$");
   36 
   37 #include <sys/param.h>
   38 #include <sys/systm.h>
   39 #include <sys/kernel.h>
   40 #include <sys/lock.h>
   41 #include <sys/malloc.h>
   42 #include <sys/mutex.h>
   43 #include <sys/proc.h>
   44 #include <sys/resource.h>
   45 #include <sys/rwlock.h>
   46 #include <sys/sx.h>
   47 #include <sys/vmmeter.h>
   48 #include <sys/smp.h>
   49 
   50 #include <vm/vm.h>
   51 #include <vm/vm_page.h>
   52 #include <vm/vm_extern.h>
   53 #include <vm/vm_param.h>
   54 #include <vm/vm_phys.h>
   55 #include <vm/vm_pagequeue.h>
   56 #include <vm/pmap.h>
   57 #include <vm/vm_map.h>
   58 #include <vm/vm_object.h>
   59 #include <sys/sysctl.h>
   60 
   61 struct vmmeter __read_mostly vm_cnt = {
   62         .v_swtch = EARLY_COUNTER,
   63         .v_trap = EARLY_COUNTER,
   64         .v_syscall = EARLY_COUNTER,
   65         .v_intr = EARLY_COUNTER,
   66         .v_soft = EARLY_COUNTER,
   67         .v_vm_faults = EARLY_COUNTER,
   68         .v_io_faults = EARLY_COUNTER,
   69         .v_cow_faults = EARLY_COUNTER,
   70         .v_cow_optim = EARLY_COUNTER,
   71         .v_zfod = EARLY_COUNTER,
   72         .v_ozfod = EARLY_COUNTER,
   73         .v_swapin = EARLY_COUNTER,
   74         .v_swapout = EARLY_COUNTER,
   75         .v_swappgsin = EARLY_COUNTER,
   76         .v_swappgsout = EARLY_COUNTER,
   77         .v_vnodein = EARLY_COUNTER,
   78         .v_vnodeout = EARLY_COUNTER,
   79         .v_vnodepgsin = EARLY_COUNTER,
   80         .v_vnodepgsout = EARLY_COUNTER,
   81         .v_intrans = EARLY_COUNTER,
   82         .v_reactivated = EARLY_COUNTER,
   83         .v_pdwakeups = EARLY_COUNTER,
   84         .v_pdpages = EARLY_COUNTER,
   85         .v_pdshortfalls = EARLY_COUNTER,
   86         .v_dfree = EARLY_COUNTER,
   87         .v_pfree = EARLY_COUNTER,
   88         .v_tfree = EARLY_COUNTER,
   89         .v_forks = EARLY_COUNTER,
   90         .v_vforks = EARLY_COUNTER,
   91         .v_rforks = EARLY_COUNTER,
   92         .v_kthreads = EARLY_COUNTER,
   93         .v_forkpages = EARLY_COUNTER,
   94         .v_vforkpages = EARLY_COUNTER,
   95         .v_rforkpages = EARLY_COUNTER,
   96         .v_kthreadpages = EARLY_COUNTER,
   97         .v_wire_count = EARLY_COUNTER,
   98 };
   99 
  100 u_long __exclusive_cache_line vm_user_wire_count;
  101 
  102 static void
  103 vmcounter_startup(void)
  104 {
  105         counter_u64_t *cnt = (counter_u64_t *)&vm_cnt;
  106 
  107         COUNTER_ARRAY_ALLOC(cnt, VM_METER_NCOUNTERS, M_WAITOK);
  108 }
  109 SYSINIT(counter, SI_SUB_KMEM, SI_ORDER_FIRST, vmcounter_startup, NULL);
  110 
  111 SYSCTL_UINT(_vm, VM_V_FREE_MIN, v_free_min,
  112         CTLFLAG_RW, &vm_cnt.v_free_min, 0, "Minimum low-free-pages threshold");
  113 SYSCTL_UINT(_vm, VM_V_FREE_TARGET, v_free_target,
  114         CTLFLAG_RW, &vm_cnt.v_free_target, 0, "Desired free pages");
  115 SYSCTL_UINT(_vm, VM_V_FREE_RESERVED, v_free_reserved,
  116         CTLFLAG_RW, &vm_cnt.v_free_reserved, 0, "Pages reserved for deadlock");
  117 SYSCTL_UINT(_vm, VM_V_INACTIVE_TARGET, v_inactive_target,
  118         CTLFLAG_RW, &vm_cnt.v_inactive_target, 0, "Pages desired inactive");
  119 SYSCTL_UINT(_vm, VM_V_PAGEOUT_FREE_MIN, v_pageout_free_min,
  120         CTLFLAG_RW, &vm_cnt.v_pageout_free_min, 0, "Min pages reserved for kernel");
  121 SYSCTL_UINT(_vm, OID_AUTO, v_free_severe,
  122         CTLFLAG_RW, &vm_cnt.v_free_severe, 0, "Severe page depletion point");
  123 
  124 static int
  125 sysctl_vm_loadavg(SYSCTL_HANDLER_ARGS)
  126 {
  127         
  128 #ifdef SCTL_MASK32
  129         u_int32_t la[4];
  130 
  131         if (req->flags & SCTL_MASK32) {
  132                 la[0] = averunnable.ldavg[0];
  133                 la[1] = averunnable.ldavg[1];
  134                 la[2] = averunnable.ldavg[2];
  135                 la[3] = averunnable.fscale;
  136                 return SYSCTL_OUT(req, la, sizeof(la));
  137         } else
  138 #endif
  139                 return SYSCTL_OUT(req, &averunnable, sizeof(averunnable));
  140 }
  141 SYSCTL_PROC(_vm, VM_LOADAVG, loadavg, CTLTYPE_STRUCT | CTLFLAG_RD |
  142     CTLFLAG_MPSAFE, NULL, 0, sysctl_vm_loadavg, "S,loadavg",
  143     "Machine loadaverage history");
  144 
  145 /*
  146  * This function aims to determine if the object is mapped,
  147  * specifically, if it is referenced by a vm_map_entry.  Because
  148  * objects occasionally acquire transient references that do not
  149  * represent a mapping, the method used here is inexact.  However, it
  150  * has very low overhead and is good enough for the advisory
  151  * vm.vmtotal sysctl.
  152  */
  153 static bool
  154 is_object_active(vm_object_t obj)
  155 {
  156 
  157         return (obj->ref_count > obj->shadow_count);
  158 }
  159 
  160 #if defined(COMPAT_FREEBSD11)
  161 struct vmtotal11 {
  162         int16_t t_rq;
  163         int16_t t_dw;
  164         int16_t t_pw;
  165         int16_t t_sl;
  166         int16_t t_sw;
  167         int32_t t_vm;
  168         int32_t t_avm;
  169         int32_t t_rm;
  170         int32_t t_arm;
  171         int32_t t_vmshr;
  172         int32_t t_avmshr;
  173         int32_t t_rmshr;
  174         int32_t t_armshr;
  175         int32_t t_free;
  176 };
  177 #endif
  178 
  179 static int
  180 vmtotal(SYSCTL_HANDLER_ARGS)
  181 {
  182         struct vmtotal total;
  183 #if defined(COMPAT_FREEBSD11)
  184         struct vmtotal11 total11;
  185 #endif
  186         vm_object_t object;
  187         struct proc *p;
  188         struct thread *td;
  189 
  190         if (req->oldptr == NULL) {
  191 #if defined(COMPAT_FREEBSD11)
  192                 if (curproc->p_osrel < P_OSREL_VMTOTAL64)
  193                         return (SYSCTL_OUT(req, NULL, sizeof(total11)));
  194 #endif
  195                 return (SYSCTL_OUT(req, NULL, sizeof(total)));
  196         }
  197         bzero(&total, sizeof(total));
  198 
  199         /*
  200          * Calculate process statistics.
  201          */
  202         sx_slock(&allproc_lock);
  203         FOREACH_PROC_IN_SYSTEM(p) {
  204                 if ((p->p_flag & P_SYSTEM) != 0)
  205                         continue;
  206                 PROC_LOCK(p);
  207                 if (p->p_state != PRS_NEW) {
  208                         FOREACH_THREAD_IN_PROC(p, td) {
  209                                 thread_lock(td);
  210                                 switch (td->td_state) {
  211                                 case TDS_INHIBITED:
  212                                         if (TD_IS_SWAPPED(td))
  213                                                 total.t_sw++;
  214                                         else if (TD_IS_SLEEPING(td)) {
  215                                                 if (td->td_priority <= PZERO)
  216                                                         total.t_dw++;
  217                                                 else
  218                                                         total.t_sl++;
  219                                         }
  220                                         break;
  221                                 case TDS_CAN_RUN:
  222                                         total.t_sw++;
  223                                         break;
  224                                 case TDS_RUNQ:
  225                                 case TDS_RUNNING:
  226                                         total.t_rq++;
  227                                         break;
  228                                 default:
  229                                         break;
  230                                 }
  231                                 thread_unlock(td);
  232                         }
  233                 }
  234                 PROC_UNLOCK(p);
  235         }
  236         sx_sunlock(&allproc_lock);
  237         /*
  238          * Calculate object memory usage statistics.
  239          */
  240         mtx_lock(&vm_object_list_mtx);
  241         TAILQ_FOREACH(object, &vm_object_list, object_list) {
  242                 /*
  243                  * Perform unsynchronized reads on the object.  In
  244                  * this case, the lack of synchronization should not
  245                  * impair the accuracy of the reported statistics.
  246                  */
  247                 if ((object->flags & OBJ_FICTITIOUS) != 0) {
  248                         /*
  249                          * Devices, like /dev/mem, will badly skew our totals.
  250                          */
  251                         continue;
  252                 }
  253                 if (object->ref_count == 0) {
  254                         /*
  255                          * Also skip unreferenced objects, including
  256                          * vnodes representing mounted file systems.
  257                          */
  258                         continue;
  259                 }
  260                 if (object->ref_count == 1 &&
  261                     (object->flags & OBJ_NOSPLIT) != 0) {
  262                         /*
  263                          * Also skip otherwise unreferenced swap
  264                          * objects backing tmpfs vnodes, and POSIX or
  265                          * SysV shared memory.
  266                          */
  267                         continue;
  268                 }
  269                 total.t_vm += object->size;
  270                 total.t_rm += object->resident_page_count;
  271                 if (is_object_active(object)) {
  272                         total.t_avm += object->size;
  273                         total.t_arm += object->resident_page_count;
  274                 }
  275                 if (object->shadow_count > 1) {
  276                         /* shared object */
  277                         total.t_vmshr += object->size;
  278                         total.t_rmshr += object->resident_page_count;
  279                         if (is_object_active(object)) {
  280                                 total.t_avmshr += object->size;
  281                                 total.t_armshr += object->resident_page_count;
  282                         }
  283                 }
  284         }
  285         mtx_unlock(&vm_object_list_mtx);
  286         total.t_pw = vm_wait_count();
  287         total.t_free = vm_free_count();
  288 #if defined(COMPAT_FREEBSD11)
  289         /* sysctl(8) allocates twice as much memory as reported by sysctl(3) */
  290         if (curproc->p_osrel < P_OSREL_VMTOTAL64 && (req->oldlen ==
  291             sizeof(total11) || req->oldlen == 2 * sizeof(total11))) {
  292                 bzero(&total11, sizeof(total11));
  293                 total11.t_rq = total.t_rq;
  294                 total11.t_dw = total.t_dw;
  295                 total11.t_pw = total.t_pw;
  296                 total11.t_sl = total.t_sl;
  297                 total11.t_sw = total.t_sw;
  298                 total11.t_vm = total.t_vm;      /* truncate */
  299                 total11.t_avm = total.t_avm;    /* truncate */
  300                 total11.t_rm = total.t_rm;      /* truncate */
  301                 total11.t_arm = total.t_arm;    /* truncate */
  302                 total11.t_vmshr = total.t_vmshr;        /* truncate */
  303                 total11.t_avmshr = total.t_avmshr;      /* truncate */
  304                 total11.t_rmshr = total.t_rmshr;        /* truncate */
  305                 total11.t_armshr = total.t_armshr;      /* truncate */
  306                 total11.t_free = total.t_free;          /* truncate */
  307                 return (SYSCTL_OUT(req, &total11, sizeof(total11)));
  308         }
  309 #endif
  310         return (SYSCTL_OUT(req, &total, sizeof(total)));
  311 }
  312 
  313 SYSCTL_PROC(_vm, VM_TOTAL, vmtotal, CTLTYPE_OPAQUE | CTLFLAG_RD |
  314     CTLFLAG_MPSAFE, NULL, 0, vmtotal, "S,vmtotal",
  315     "System virtual memory statistics");
  316 SYSCTL_NODE(_vm, OID_AUTO, stats, CTLFLAG_RW, 0, "VM meter stats");
  317 static SYSCTL_NODE(_vm_stats, OID_AUTO, sys, CTLFLAG_RW, 0,
  318         "VM meter sys stats");
  319 static SYSCTL_NODE(_vm_stats, OID_AUTO, vm, CTLFLAG_RW, 0,
  320         "VM meter vm stats");
  321 SYSCTL_NODE(_vm_stats, OID_AUTO, misc, CTLFLAG_RW, 0, "VM meter misc stats");
  322 
  323 static int
  324 sysctl_handle_vmstat(SYSCTL_HANDLER_ARGS)
  325 {
  326         uint64_t val;
  327 #ifdef COMPAT_FREEBSD11
  328         uint32_t val32;
  329 #endif
  330 
  331         val = counter_u64_fetch(*(counter_u64_t *)arg1);
  332 #ifdef COMPAT_FREEBSD11
  333         if (req->oldlen == sizeof(val32)) {
  334                 val32 = val;            /* truncate */
  335                 return (SYSCTL_OUT(req, &val32, sizeof(val32)));
  336         }
  337 #endif
  338         return (SYSCTL_OUT(req, &val, sizeof(val)));
  339 }
  340 
  341 #define VM_STATS(parent, var, descr) \
  342     SYSCTL_OID(parent, OID_AUTO, var, CTLTYPE_U64 | CTLFLAG_MPSAFE | \
  343     CTLFLAG_RD, &vm_cnt.var, 0, sysctl_handle_vmstat, "QU", descr)
  344 #define VM_STATS_VM(var, descr)         VM_STATS(_vm_stats_vm, var, descr)
  345 #define VM_STATS_SYS(var, descr)        VM_STATS(_vm_stats_sys, var, descr)
  346 
  347 VM_STATS_SYS(v_swtch, "Context switches");
  348 VM_STATS_SYS(v_trap, "Traps");
  349 VM_STATS_SYS(v_syscall, "System calls");
  350 VM_STATS_SYS(v_intr, "Device interrupts");
  351 VM_STATS_SYS(v_soft, "Software interrupts");
  352 VM_STATS_VM(v_vm_faults, "Address memory faults");
  353 VM_STATS_VM(v_io_faults, "Page faults requiring I/O");
  354 VM_STATS_VM(v_cow_faults, "Copy-on-write faults");
  355 VM_STATS_VM(v_cow_optim, "Optimized COW faults");
  356 VM_STATS_VM(v_zfod, "Pages zero-filled on demand");
  357 VM_STATS_VM(v_ozfod, "Optimized zero fill pages");
  358 VM_STATS_VM(v_swapin, "Swap pager pageins");
  359 VM_STATS_VM(v_swapout, "Swap pager pageouts");
  360 VM_STATS_VM(v_swappgsin, "Swap pages swapped in");
  361 VM_STATS_VM(v_swappgsout, "Swap pages swapped out");
  362 VM_STATS_VM(v_vnodein, "Vnode pager pageins");
  363 VM_STATS_VM(v_vnodeout, "Vnode pager pageouts");
  364 VM_STATS_VM(v_vnodepgsin, "Vnode pages paged in");
  365 VM_STATS_VM(v_vnodepgsout, "Vnode pages paged out");
  366 VM_STATS_VM(v_intrans, "In transit page faults");
  367 VM_STATS_VM(v_reactivated, "Pages reactivated by pagedaemon");
  368 VM_STATS_VM(v_pdwakeups, "Pagedaemon wakeups");
  369 VM_STATS_VM(v_pdshortfalls, "Page reclamation shortfalls");
  370 VM_STATS_VM(v_dfree, "Pages freed by pagedaemon");
  371 VM_STATS_VM(v_pfree, "Pages freed by exiting processes");
  372 VM_STATS_VM(v_tfree, "Total pages freed");
  373 VM_STATS_VM(v_forks, "Number of fork() calls");
  374 VM_STATS_VM(v_vforks, "Number of vfork() calls");
  375 VM_STATS_VM(v_rforks, "Number of rfork() calls");
  376 VM_STATS_VM(v_kthreads, "Number of fork() calls by kernel");
  377 VM_STATS_VM(v_forkpages, "VM pages affected by fork()");
  378 VM_STATS_VM(v_vforkpages, "VM pages affected by vfork()");
  379 VM_STATS_VM(v_rforkpages, "VM pages affected by rfork()");
  380 VM_STATS_VM(v_kthreadpages, "VM pages affected by fork() by kernel");
  381 
  382 static int
  383 sysctl_handle_vmstat_proc(SYSCTL_HANDLER_ARGS)
  384 {
  385         u_int (*fn)(void);
  386         uint32_t val;
  387 
  388         fn = arg1;
  389         val = fn();
  390         return (SYSCTL_OUT(req, &val, sizeof(val)));
  391 }
  392 
  393 #define VM_STATS_PROC(var, descr, fn) \
  394     SYSCTL_OID(_vm_stats_vm, OID_AUTO, var, CTLTYPE_U32 | CTLFLAG_MPSAFE | \
  395     CTLFLAG_RD, fn, 0, sysctl_handle_vmstat_proc, "IU", descr)
  396 
  397 #define VM_STATS_UINT(var, descr)       \
  398     SYSCTL_UINT(_vm_stats_vm, OID_AUTO, var, CTLFLAG_RD, &vm_cnt.var, 0, descr)
  399 #define VM_STATS_ULONG(var, descr)      \
  400     SYSCTL_ULONG(_vm_stats_vm, OID_AUTO, var, CTLFLAG_RD, &vm_cnt.var, 0, descr)
  401 
  402 VM_STATS_UINT(v_page_size, "Page size in bytes");
  403 VM_STATS_UINT(v_page_count, "Total number of pages in system");
  404 VM_STATS_UINT(v_free_reserved, "Pages reserved for deadlock");
  405 VM_STATS_UINT(v_free_target, "Pages desired free");
  406 VM_STATS_UINT(v_free_min, "Minimum low-free-pages threshold");
  407 VM_STATS_PROC(v_free_count, "Free pages", vm_free_count);
  408 VM_STATS_PROC(v_wire_count, "Wired pages", vm_wire_count);
  409 VM_STATS_PROC(v_active_count, "Active pages", vm_active_count);
  410 VM_STATS_UINT(v_inactive_target, "Desired inactive pages");
  411 VM_STATS_PROC(v_inactive_count, "Inactive pages", vm_inactive_count);
  412 VM_STATS_PROC(v_laundry_count, "Pages eligible for laundering",
  413     vm_laundry_count);
  414 VM_STATS_UINT(v_pageout_free_min, "Min pages reserved for kernel");
  415 VM_STATS_UINT(v_interrupt_free_min, "Reserved pages for interrupt code");
  416 VM_STATS_UINT(v_free_severe, "Severe page depletion point");
  417 
  418 SYSCTL_ULONG(_vm_stats_vm, OID_AUTO, v_user_wire_count, CTLFLAG_RD,
  419     &vm_user_wire_count, 0, "User-wired virtual memory");
  420 
  421 #ifdef COMPAT_FREEBSD11
  422 /*
  423  * Provide compatibility sysctls for the benefit of old utilities which exit
  424  * with an error if they cannot be found.
  425  */
  426 SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_cache_count, CTLFLAG_RD,
  427     SYSCTL_NULL_UINT_PTR, 0, "Dummy for compatibility");
  428 SYSCTL_UINT(_vm_stats_vm, OID_AUTO, v_tcached, CTLFLAG_RD,
  429     SYSCTL_NULL_UINT_PTR, 0, "Dummy for compatibility");
  430 #endif
  431 
  432 u_int
  433 vm_free_count(void)
  434 {
  435         u_int v;
  436         int i;
  437 
  438         v = 0;
  439         for (i = 0; i < vm_ndomains; i++)
  440                 v += vm_dom[i].vmd_free_count;
  441 
  442         return (v);
  443 }
  444 
  445 static u_int
  446 vm_pagequeue_count(int pq)
  447 {
  448         u_int v;
  449         int i;
  450 
  451         v = 0;
  452         for (i = 0; i < vm_ndomains; i++)
  453                 v += vm_dom[i].vmd_pagequeues[pq].pq_cnt;
  454 
  455         return (v);
  456 }
  457 
  458 u_int
  459 vm_active_count(void)
  460 {
  461 
  462         return (vm_pagequeue_count(PQ_ACTIVE));
  463 }
  464 
  465 u_int
  466 vm_inactive_count(void)
  467 {
  468 
  469         return (vm_pagequeue_count(PQ_INACTIVE));
  470 }
  471 
  472 u_int
  473 vm_laundry_count(void)
  474 {
  475 
  476         return (vm_pagequeue_count(PQ_LAUNDRY));
  477 }
  478 
  479 static int
  480 sysctl_vm_pdpages(SYSCTL_HANDLER_ARGS)
  481 {
  482         struct vm_pagequeue *pq;
  483         uint64_t ret;
  484         int dom, i;
  485 
  486         ret = counter_u64_fetch(vm_cnt.v_pdpages);
  487         for (dom = 0; dom < vm_ndomains; dom++)
  488                 for (i = 0; i < PQ_COUNT; i++) {
  489                         pq = &VM_DOMAIN(dom)->vmd_pagequeues[i];
  490                         ret += pq->pq_pdpages;
  491                 }
  492         return (SYSCTL_OUT(req, &ret, sizeof(ret)));
  493 }
  494 SYSCTL_PROC(_vm_stats_vm, OID_AUTO, v_pdpages,
  495     CTLTYPE_U64 | CTLFLAG_MPSAFE | CTLFLAG_RD, NULL, 0, sysctl_vm_pdpages, "QU",
  496     "Pages analyzed by pagedaemon");
  497 
  498 static void
  499 vm_domain_stats_init(struct vm_domain *vmd, struct sysctl_oid *parent)
  500 {
  501         struct sysctl_oid *oid;
  502 
  503         vmd->vmd_oid = SYSCTL_ADD_NODE(NULL, SYSCTL_CHILDREN(parent), OID_AUTO,
  504             vmd->vmd_name, CTLFLAG_RD, NULL, "");
  505         oid = SYSCTL_ADD_NODE(NULL, SYSCTL_CHILDREN(vmd->vmd_oid), OID_AUTO,
  506             "stats", CTLFLAG_RD, NULL, "");
  507         SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
  508             "free_count", CTLFLAG_RD, &vmd->vmd_free_count, 0,
  509             "Free pages");
  510         SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
  511             "active", CTLFLAG_RD, &vmd->vmd_pagequeues[PQ_ACTIVE].pq_cnt, 0,
  512             "Active pages");
  513         SYSCTL_ADD_U64(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
  514             "actpdpgs", CTLFLAG_RD,
  515             &vmd->vmd_pagequeues[PQ_ACTIVE].pq_pdpages, 0,
  516             "Active pages scanned by the page daemon");
  517         SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
  518             "inactive", CTLFLAG_RD, &vmd->vmd_pagequeues[PQ_INACTIVE].pq_cnt, 0,
  519             "Inactive pages");
  520         SYSCTL_ADD_U64(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
  521             "inactpdpgs", CTLFLAG_RD,
  522             &vmd->vmd_pagequeues[PQ_INACTIVE].pq_pdpages, 0,
  523             "Inactive pages scanned by the page daemon");
  524         SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
  525             "laundry", CTLFLAG_RD, &vmd->vmd_pagequeues[PQ_LAUNDRY].pq_cnt, 0,
  526             "laundry pages");
  527         SYSCTL_ADD_U64(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
  528             "laundpdpgs", CTLFLAG_RD,
  529             &vmd->vmd_pagequeues[PQ_LAUNDRY].pq_pdpages, 0,
  530             "Laundry pages scanned by the page daemon");
  531         SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO, "unswappable",
  532             CTLFLAG_RD, &vmd->vmd_pagequeues[PQ_UNSWAPPABLE].pq_cnt, 0,
  533             "Unswappable pages");
  534         SYSCTL_ADD_U64(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
  535             "unswppdpgs", CTLFLAG_RD,
  536             &vmd->vmd_pagequeues[PQ_UNSWAPPABLE].pq_pdpages, 0,
  537             "Unswappable pages scanned by the page daemon");
  538         SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
  539             "inactive_target", CTLFLAG_RD, &vmd->vmd_inactive_target, 0,
  540             "Target inactive pages");
  541         SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
  542             "free_target", CTLFLAG_RD, &vmd->vmd_free_target, 0,
  543             "Target free pages");
  544         SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
  545             "free_reserved", CTLFLAG_RD, &vmd->vmd_free_reserved, 0,
  546             "Reserved free pages");
  547         SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
  548             "free_min", CTLFLAG_RD, &vmd->vmd_free_min, 0,
  549             "Minimum free pages");
  550         SYSCTL_ADD_UINT(NULL, SYSCTL_CHILDREN(oid), OID_AUTO,
  551             "free_severe", CTLFLAG_RD, &vmd->vmd_free_severe, 0,
  552             "Severe free pages");
  553 
  554 }
  555 
  556 static void
  557 vm_stats_init(void *arg __unused)
  558 {
  559         struct sysctl_oid *oid;
  560         int i;
  561 
  562         oid = SYSCTL_ADD_NODE(NULL, SYSCTL_STATIC_CHILDREN(_vm), OID_AUTO,
  563             "domain", CTLFLAG_RD, NULL, "");
  564         for (i = 0; i < vm_ndomains; i++)
  565                 vm_domain_stats_init(VM_DOMAIN(i), oid);
  566 }
  567 
  568 SYSINIT(vmstats_init, SI_SUB_VM_CONF, SI_ORDER_FIRST, vm_stats_init, NULL);

Cache object: 9ea3b5d18a93103d589be5afce2e6853


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.