4 * cc -I/usr/src/sys vmpagequeues.c -o ~/bin/vmpagequeues -lkvm
8 * Outputs statistics on PQ_FREE (-f, default), or -c, -i, -a for
9 * PQ_CACHE, PQ_INACTIVE, and PQ_ACTIVE.
11 * Copyright (c) 2016 The DragonFly Project. All rights reserved.
13 * This code is derived from software contributed to The DragonFly Project
14 * by Matthew Dillon <dillon@backplane.com>
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in
24 * the documentation and/or other materials provided with the
26 * 3. Neither the name of The DragonFly Project nor the names of its
27 * contributors may be used to endorse or promote products derived
28 * from this software without specific, prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
34 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
35 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
36 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
38 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
39 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
40 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 #define _KERNEL_STRUCTURES_
45 #include <sys/param.h>
47 #include <sys/malloc.h>
48 #include <sys/signalvar.h>
49 #include <sys/vnode.h>
50 #include <sys/namecache.h>
51 #include <sys/slaballoc.h>
54 #include <vm/vm_page.h>
55 #include <vm/vm_kern.h>
56 #include <vm/vm_object.h>
57 #include <vm/swap_pager.h>
58 #include <vm/vnode_pager.h>
70 { "_vm_page_buckets" },
71 { "_vm_page_hash_mask" },
73 { "_vm_page_queues" },
80 static void kkread_vmpage(kvm_t
*kd
, u_long addr
, vm_page_t m
);
81 static void kkread(kvm_t
*kd
, u_long addr
, void *buf
, size_t nbytes
);
82 static int kkread_err(kvm_t
*kd
, u_long addr
, void *buf
, size_t nbytes
);
85 main(int ac
, char **av
)
87 const char *corefile
= NULL
;
88 const char *sysfile
= NULL
;
93 struct vpgqueues queues
[PQ_COUNT
];
95 while ((ch
= getopt(ac
, av
, "M:N:dviacf")) != -1) {
122 fprintf(stderr
, "%s [-M core] [-N system]\n", av
[0]);
129 if ((kd
= kvm_open(sysfile
, corefile
, NULL
, O_RDONLY
, "kvm:")) == NULL
) {
133 if (kvm_nlist(kd
, Nl
) != 0) {
139 kkread(kd
, Nl
[0].n_value
, queues
, sizeof(queues
));
140 for (i
= 0; i
< PQ_L2_SIZE
; ++i
) {
141 struct vpgqueues
*vpq
= &queues
[q
+i
];
144 printf("\t%6d", vpq
->lcnt
);
157 kkread(kvm_t
*kd
, u_long addr
, void *buf
, size_t nbytes
)
159 if (kvm_read(kd
, addr
, buf
, nbytes
) != nbytes
) {
166 kkread_err(kvm_t
*kd
, u_long addr
, void *buf
, size_t nbytes
)
168 if (kvm_read(kd
, addr
, buf
, nbytes
) != nbytes
) {