2 * top - a top users display for Unix
4 * SYNOPSIS: For DragonFly 2.x and later
7 * Originally written for BSD4.4 system by Christos Zoulas.
8 * Ported to FreeBSD 2.x by Steven Wallace && Wolfram Schneider
9 * Order support hacked in from top-3.5beta6/machine/m_aix41.c
10 * by Monte Mitzelfelt (for latest top see http://www.groupsys.com/topinfo/)
12 * This is the machine-dependent module for DragonFly 2.5.1
14 * DragonFly 2.x and above
18 * AUTHOR: Jan Lentfer <Jan.Lentfer@web.de>
19 * This module has been put together from different sources and is based on the
20 * work of many other people, e.g. Matthew Dillon, Simon Schubert, Jordan Gordeev.
22 * $FreeBSD: src/usr.bin/top/machine.c,v 1.29.2.2 2001/07/31 20:27:05 tmm Exp $
23 * $DragonFly: src/usr.bin/top/machine.c,v 1.26 2008/10/16 01:52:33 swildner Exp $
27 #include <sys/types.h>
28 #include <sys/signal.h>
29 #include <sys/param.h>
38 #include <sys/errno.h>
39 #include <sys/sysctl.h>
43 #include <sys/vmmeter.h>
44 #include <sys/resource.h>
45 #include <sys/rtprio.h>
52 #include <osreldate.h> /* for changes in kernel structures */
54 #include <sys/kinfo.h>
62 int swapmode(int *retavail
, int *retfree
);
64 static int namelength
;
70 * needs to be a global symbol, so wrapper can be modified accordingly.
72 static int show_threads
= 0;
74 /* get_process_info passes back a handle. This is what it looks like: */
77 struct kinfo_proc
**next_proc
; /* points to next valid proc pointer */
78 int remaining
; /* number of pointers remaining */
81 /* declarations for load_avg */
84 #define PP(pp, field) ((pp)->kp_ ## field)
85 #define LP(pp, field) ((pp)->kp_lwp.kl_ ## field)
86 #define VP(pp, field) ((pp)->kp_vm_ ## field)
88 /* define what weighted cpu is. */
89 #define weighted_cpu(pct, pp) (PP((pp), swtime) == 0 ? 0.0 : \
90 ((pct) / (1.0 - exp(PP((pp), swtime) * logcpu))))
92 /* what we consider to be process size: */
93 #define PROCSIZE(pp) (VP((pp), map_size) / 1024)
96 * These definitions control the format of the per-process area
99 static char smp_header
[] =
100 " PID %-*.*s PRI NICE SIZE RES STATE C TIME WCPU CPU COMMAND";
102 #define smp_Proc_format \
103 "%5d %-*.*s %3d %3d%7s %6s %-6.6s %1x%7s %5.2f%% %5.2f%% %.*s"
105 static char up_header
[] =
106 " PID %-*.*s PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND";
108 #define up_Proc_format \
109 "%5d %-*.*s %3d %3d%7s %6s %-6.6s%.0d%7s %5.2f%% %5.2f%% %.*s"
113 /* process state names for the "STATE" column of the display */
115 * the extra nulls in the string "run" are for adding a slash and the
116 * processor number when needed
119 const char *state_abbrev
[] = {
120 "", "RUN\0\0\0", "STOP", "SLEEP",
126 /* values that we stash away in _init and use in later routines */
128 static double logcpu
;
133 /* these are for calculating cpu state percentages */
135 static struct kinfo_cputime
*cp_time
, *cp_old
;
137 /* these are for detailing the process states */
139 int process_states
[6];
140 char *procstatenames
[] = {
141 "", " starting, ", " running, ", " sleeping, ", " stopped, ",
146 /* these are for detailing the cpu states */
149 char *cpustatenames
[CPU_STATES
+ 1] = {
150 "user", "nice", "system", "interrupt", "idle", NULL
153 /* these are for detailing the memory statistics */
155 long memory_stats
[7];
156 char *memorynames
[] = {
157 "K Active, ", "K Inact, ", "K Wired, ", "K Cache, ", "K Buf, ", "K Free",
162 char *swapnames
[] = {
164 "K Total, ", "K Used, ", "K Free, ", "% Inuse, ", "K In, ", "K Out",
169 /* these are for keeping track of the proc array */
172 static int onproc
= -1;
174 static struct kinfo_proc
*pbase
;
175 static struct kinfo_proc
**pref
;
177 /* these are for getting the memory statistics */
179 static int pageshift
; /* log base 2 of the pagesize */
181 /* define pagetok in terms of pageshift */
183 #define pagetok(size) ((size) << pageshift)
185 /* sorting orders. first is default */
186 char *ordernames
[] = {
187 "cpu", "size", "res", "time", "pri", "thr", NULL
190 /* compare routines */
191 int proc_compare(), compare_size(), compare_res(), compare_time(), compare_prio(), compare_thr();
193 int (*proc_compares
[]) () = {
203 cputime_percentages(int out
[CPU_STATES
], struct kinfo_cputime
*new,
204 struct kinfo_cputime
*old
)
206 struct kinfo_cputime diffs
;
207 uint64_t total_change
, half_total
;
212 diffs
.cp_user
= new->cp_user
- old
->cp_user
;
213 diffs
.cp_nice
= new->cp_nice
- old
->cp_nice
;
214 diffs
.cp_sys
= new->cp_sys
- old
->cp_sys
;
215 diffs
.cp_intr
= new->cp_intr
- old
->cp_intr
;
216 diffs
.cp_idle
= new->cp_idle
- old
->cp_idle
;
217 total_change
= diffs
.cp_user
+ diffs
.cp_nice
+ diffs
.cp_sys
+
218 diffs
.cp_intr
+ diffs
.cp_idle
;
219 old
->cp_user
= new->cp_user
;
220 old
->cp_nice
= new->cp_nice
;
221 old
->cp_sys
= new->cp_sys
;
222 old
->cp_intr
= new->cp_intr
;
223 old
->cp_idle
= new->cp_idle
;
225 /* avoid divide by zero potential */
226 if (total_change
== 0)
229 /* calculate percentages based on overall change, rounding up */
230 half_total
= total_change
>> 1;
232 out
[0] = ((diffs
.cp_user
* 1000LL + half_total
) / total_change
);
233 out
[1] = ((diffs
.cp_nice
* 1000LL + half_total
) / total_change
);
234 out
[2] = ((diffs
.cp_sys
* 1000LL + half_total
) / total_change
);
235 out
[3] = ((diffs
.cp_intr
* 1000LL + half_total
) / total_change
);
236 out
[4] = ((diffs
.cp_idle
* 1000LL + half_total
) / total_change
);
240 machine_init(struct statics
*statics
)
245 struct timeval boottime
;
248 if (kinfo_get_cpus(&n_cpus
))
249 err(1, "kinfo_get_cpus failed");
252 modelen
= sizeof(boottime
);
253 if (sysctlbyname("kern.boottime", &boottime
, &modelen
, NULL
, 0) == -1) {
254 /* we have no boottime to report */
255 boottime
.tv_sec
= -1;
257 modelen
= sizeof(smpmode
);
258 if ((sysctlbyname("machdep.smp_active", &smpmode
, &modelen
, NULL
, 0) < 0 &&
259 sysctlbyname("smp.smp_active", &smpmode
, &modelen
, NULL
, 0) < 0) ||
260 modelen
!= sizeof(smpmode
))
263 while ((pw
= getpwent()) != NULL
) {
264 if ((int)strlen(pw
->pw_name
) > namelength
)
265 namelength
= strlen(pw
->pw_name
);
269 if (smpmode
&& namelength
> 13)
271 else if (namelength
> 15)
274 if ((kd
= kvm_open(NULL
, NULL
, NULL
, O_RDONLY
, "kvm_open")) == NULL
)
277 if (kinfo_get_sched_ccpu(&ccpu
)) {
278 fprintf(stderr
, "top: kinfo_get_sched_ccpu failed\n");
281 /* this is used in calculating WCPU -- calculate it ahead of time */
282 logcpu
= log(loaddouble(ccpu
));
289 * get the page size with "getpagesize" and calculate pageshift from
292 pagesize
= getpagesize();
294 while (pagesize
> 1) {
299 /* we only need the amount of log(2)1024 for our conversion */
300 pageshift
-= LOG1024
;
302 /* fill in the statics information */
303 statics
->procstate_names
= procstatenames
;
304 statics
->cpustate_names
= cpustatenames
;
305 statics
->memory_names
= memorynames
;
306 statics
->boottime
= boottime
.tv_sec
;
307 statics
->swap_names
= swapnames
;
308 statics
->order_names
= ordernames
;
315 format_header(char *uname_field
)
317 static char Header
[128];
319 snprintf(Header
, sizeof(Header
), smpmode
? smp_header
: up_header
,
320 namelength
, namelength
, uname_field
);
322 if (screen_width
<= 79)
327 cmdlength
= cmdlength
- strlen(Header
) + 6;
332 static int swappgsin
= -1;
333 static int swappgsout
= -1;
334 extern struct timeval timeout
;
337 get_system_info(struct system_info
*si
)
342 if (cpu_states
== NULL
) {
343 cpu_states
= malloc(sizeof(*cpu_states
) * CPU_STATES
* n_cpus
);
344 if (cpu_states
== NULL
)
346 bzero(cpu_states
, sizeof(*cpu_states
) * CPU_STATES
* n_cpus
);
348 if (cp_time
== NULL
) {
349 cp_time
= malloc(2 * n_cpus
* sizeof(cp_time
[0]));
352 cp_old
= cp_time
+ n_cpus
;
354 len
= n_cpus
* sizeof(cp_old
[0]);
356 if (sysctlbyname("kern.cputime", cp_old
, &len
, NULL
, 0))
357 err(1, "kern.cputime");
359 len
= n_cpus
* sizeof(cp_time
[0]);
361 if (sysctlbyname("kern.cputime", cp_time
, &len
, NULL
, 0))
362 err(1, "kern.cputime");
364 getloadavg(si
->load_avg
, 3);
368 /* convert cp_time counts to percentages */
369 for (cpu
= 0; cpu
< n_cpus
; ++cpu
) {
370 cputime_percentages(cpu_states
+ cpu
* CPU_STATES
,
371 &cp_time
[cpu
], &cp_old
[cpu
]);
374 /* sum memory & swap statistics */
378 size_t vms_size
= sizeof(vms
);
379 size_t vmm_size
= sizeof(vmm
);
380 static unsigned int swap_delay
= 0;
381 static int swapavail
= 0;
382 static int swapfree
= 0;
383 static int bufspace
= 0;
385 if (sysctlbyname("vm.vmstats", &vms
, &vms_size
, NULL
, 0))
386 err(1, "sysctlbyname: vm.vmstats");
388 if (sysctlbyname("vm.vmmeter", &vmm
, &vmm_size
, NULL
, 0))
389 err(1, "sysctlbyname: vm.vmmeter");
391 if (kinfo_get_vfs_bufspace(&bufspace
))
392 err(1, "kinfo_get_vfs_bufspace");
394 /* convert memory stats to Kbytes */
395 memory_stats
[0] = pagetok(vms
.v_active_count
);
396 memory_stats
[1] = pagetok(vms
.v_inactive_count
);
397 memory_stats
[2] = pagetok(vms
.v_wire_count
);
398 memory_stats
[3] = pagetok(vms
.v_cache_count
);
399 memory_stats
[4] = bufspace
/ 1024;
400 memory_stats
[5] = pagetok(vms
.v_free_count
);
401 memory_stats
[6] = -1;
408 /* compute differences between old and new swap statistic */
410 swap_stats
[4] = pagetok(((vmm
.v_swappgsin
- swappgsin
)));
411 swap_stats
[5] = pagetok(((vmm
.v_swappgsout
- swappgsout
)));
414 swappgsin
= vmm
.v_swappgsin
;
415 swappgsout
= vmm
.v_swappgsout
;
417 /* call CPU heavy swapmode() only for changes */
418 if (swap_stats
[4] > 0 || swap_stats
[5] > 0 || swap_delay
== 0) {
419 swap_stats
[3] = swapmode(&swapavail
, &swapfree
);
420 swap_stats
[0] = swapavail
;
421 swap_stats
[1] = swapavail
- swapfree
;
422 swap_stats
[2] = swapfree
;
428 /* set arrays and strings */
429 si
->cpustates
= cpu_states
;
430 si
->memory
= memory_stats
;
431 si
->swap
= swap_stats
;
435 si
->last_pid
= lastpid
;
442 static struct handle handle
;
445 get_process_info(struct system_info
*si
, struct process_select
*sel
,
451 struct kinfo_proc
**prefp
;
452 struct kinfo_proc
*pp
;
454 /* these are copied out of sel for speed */
460 pbase
= kvm_getprocs(kd
, KERN_PROC_ALL
, 0, &nproc
);
462 pref
= (struct kinfo_proc
**)realloc(pref
, sizeof(struct kinfo_proc
*)
464 if (pref
== NULL
|| pbase
== NULL
) {
465 (void)fprintf(stderr
, "top: Out of memory.\n");
468 /* get a pointer to the states summary array */
469 si
->procstates
= process_states
;
471 /* set up flags which define what we are going to select */
472 show_idle
= sel
->idle
;
473 show_system
= sel
->system
;
474 show_uid
= sel
->uid
!= -1;
476 /* count up process states and get pointers to interesting procs */
479 memset((char *)process_states
, 0, sizeof(process_states
));
481 for (pp
= pbase
, i
= 0; i
< nproc
; pp
++, i
++) {
483 * Place pointers to each valid proc structure in pref[].
484 * Process slots that are actually in use have a non-zero
485 * status field. Processes with P_SYSTEM set are system
486 * processes---these get ignored unless show_sysprocs is set.
488 if ((show_threads
&& (LP(pp
, pid
) == -1)) ||
489 (show_system
|| ((PP(pp
, flags
) & P_SYSTEM
) == 0))) {
491 process_states
[(unsigned char)PP(pp
, stat
)]++;
492 if ((show_threads
&& (LP(pp
, pid
) == -1)) ||
493 (show_idle
|| (LP(pp
, pctcpu
) != 0) ||
494 (LP(pp
, stat
) == LSRUN
)) &&
495 (!show_uid
|| PP(pp
, ruid
) == (uid_t
) sel
->uid
)) {
502 qsort((char *)pref
, active_procs
, sizeof(struct kinfo_proc
*),
503 proc_compares
[compare_index
]);
505 /* remember active and total counts */
506 si
->p_total
= total_procs
;
507 si
->p_active
= pref_len
= active_procs
;
509 /* pass back a handle */
510 handle
.next_proc
= pref
;
511 handle
.remaining
= active_procs
;
512 return ((caddr_t
) & handle
);
515 char fmt
[128]; /* static area where result is built */
518 format_next_process(caddr_t xhandle
, char *(*get_userid
) (int))
520 struct kinfo_proc
*pp
;
529 /* find and remember the next proc structure */
530 hp
= (struct handle
*)xhandle
;
531 pp
= *(hp
->next_proc
++);
534 /* set the wrapper for the process/thread name */
535 if ((PP(pp
, flags
) & P_SWAPPEDOUT
))
536 wrapper
= "[]"; /* swapped process [pname] */
537 else if (((PP(pp
, flags
) & P_SYSTEM
) != 0) && (LP(pp
, pid
) > 0))
538 wrapper
= "()"; /* system process (pname) */
539 else if (show_threads
&& (LP(pp
, pid
) == -1))
540 wrapper
= "<>"; /* pure kernel threads <thread> */
544 /* get the process's command name */
545 if (wrapper
!= NULL
) {
546 char *comm
= PP(pp
, comm
);
547 #define COMSIZ sizeof(PP(pp, comm))
549 (void)strncpy(buf
, comm
, COMSIZ
);
550 comm
[0] = wrapper
[0];
551 (void)strncpy(&comm
[1], buf
, COMSIZ
- 2);
552 comm
[COMSIZ
- 2] = '\0';
553 (void)strncat(comm
, &wrapper
[1], COMSIZ
- 1);
554 comm
[COMSIZ
- 1] = '\0';
557 * Convert the process's runtime from microseconds to seconds. This
558 * time includes the interrupt time although that is not wanted here.
559 * ps(1) is similarly sloppy.
561 cputime
= (LP(pp
, uticks
) + LP(pp
, sticks
)) / 1000000;
563 /* calculate the base for cpu percentages */
564 pct
= pctdouble(LP(pp
, pctcpu
));
566 /* generate "STATE" field */
567 switch (state
= LP(pp
, stat
)) {
569 if (smpmode
&& LP(pp
, tdflags
) & TDF_RUNNING
)
570 sprintf(status
, "CPU%d", LP(pp
, cpuid
));
572 strcpy(status
, "RUN");
575 if (LP(pp
, wmesg
) != NULL
) {
576 sprintf(status
, "%.6s", LP(pp
, wmesg
));
583 (unsigned)state
< sizeof(state_abbrev
) / sizeof(*state_abbrev
))
584 sprintf(status
, "%.6s", state_abbrev
[(unsigned char)state
]);
586 sprintf(status
, "?%5d", state
);
590 if (PP(pp
, stat
) == SZOMB
)
591 strcpy(status
, "ZOMB");
594 * idle time 0 - 31 -> nice value +21 - +52 normal time -> nice
595 * value -20 - +20 real time 0 - 31 -> nice value -52 - -21 thread
596 * 0 - 31 -> nice value -53 -
598 switch (LP(pp
, rtprio
.type
)) {
599 case RTP_PRIO_REALTIME
:
600 xnice
= PRIO_MIN
- 1 - RTP_PRIO_MAX
+ LP(pp
, rtprio
.prio
);
603 xnice
= PRIO_MAX
+ 1 + LP(pp
, rtprio
.prio
);
605 case RTP_PRIO_THREAD
:
606 xnice
= PRIO_MIN
- 1 - RTP_PRIO_MAX
- LP(pp
, rtprio
.prio
);
609 xnice
= PP(pp
, nice
);
613 /* format this entry */
614 snprintf(fmt
, sizeof(fmt
),
615 smpmode
? smp_Proc_format
: up_Proc_format
,
617 namelength
, namelength
,
618 get_userid(PP(pp
, ruid
)),
619 (int)((show_threads
&& (LP(pp
, pid
) == -1)) ?
620 LP(pp
, tdprio
) : LP(pp
, prio
)),
622 format_k(PROCSIZE(pp
)),
623 format_k(pagetok(VP(pp
, rssize
))),
625 (int)(smpmode
? LP(pp
, cpuid
) : 0),
626 format_time(cputime
),
627 100.0 * weighted_cpu(pct
, pp
),
630 printable(PP(pp
, comm
)));
632 /* return the result */
636 /* comparison routines for qsort */
639 * proc_compare - comparison function for "qsort"
640 * Compares the resource consumption of two processes using five
641 * distinct keys. The keys (in descending order of importance) are:
642 * percent cpu, cpu ticks, state, resident set size, total virtual
643 * memory usage. The process states are ordered as follows (from least
644 * to most important): WAIT, zombie, sleep, stop, start, run. The
645 * array declaration below maps a process state index into a number
646 * that reflects this ordering.
649 static unsigned char sorted_state
[] =
653 1, /* ABANDONED (WAIT) */
661 #define ORDERKEY_PCTCPU \
662 if (lresult = (long) LP(p2, pctcpu) - (long) LP(p1, pctcpu), \
663 (result = lresult > 0 ? 1 : lresult < 0 ? -1 : 0) == 0)
665 #define CPTICKS(p) (LP(p, uticks) + LP(p, sticks))
667 #define ORDERKEY_CPTICKS \
668 if ((result = CPTICKS(p2) > CPTICKS(p1) ? 1 : \
669 CPTICKS(p2) < CPTICKS(p1) ? -1 : 0) == 0)
671 #define ORDERKEY_STATE \
672 if ((result = sorted_state[(unsigned char) PP(p2, stat)] - \
673 sorted_state[(unsigned char) PP(p1, stat)]) == 0)
675 #define ORDERKEY_PRIO \
676 if ((result = LP(p2, prio) - LP(p1, prio)) == 0)
678 #define ORDERKEY_KTHREADS \
679 if ((result = (LP(p1, pid) == 0) - (LP(p2, pid) == 0)) == 0)
681 #define ORDERKEY_KTHREADS_PRIO \
682 if ((result = LP(p2, tdprio) - LP(p1, tdprio)) == 0)
684 #define ORDERKEY_RSSIZE \
685 if ((result = VP(p2, rssize) - VP(p1, rssize)) == 0)
687 #define ORDERKEY_MEM \
688 if ( (result = PROCSIZE(p2) - PROCSIZE(p1)) == 0 )
690 /* compare_cpu - the comparison function for sorting by cpu percentage */
693 proc_compare(const void *arg1
, const void *arg2
)
695 const struct proc
*const *pp1
= arg1
;
696 const struct proc
*const *pp2
= arg2
;
697 const struct kinfo_proc
*p1
;
698 const struct kinfo_proc
*p2
;
702 /* remove one level of indirection */
703 p1
= *(const struct kinfo_proc
*const *)pp1
;
704 p2
= *(const struct kinfo_proc
*const *)pp2
;
717 /* compare_size - the comparison function for sorting by total memory usage */
720 compare_size(const void *arg1
, const void *arg2
)
722 struct proc
*const *pp1
= arg1
;
723 struct proc
*const *pp2
= arg2
;
724 struct kinfo_proc
*p1
;
725 struct kinfo_proc
*p2
;
729 /* remove one level of indirection */
730 p1
= *(struct kinfo_proc
*const *)pp1
;
731 p2
= *(struct kinfo_proc
*const *)pp2
;
744 /* compare_res - the comparison function for sorting by resident set size */
747 compare_res(const void *arg1
, const void *arg2
)
749 struct proc
*const *pp1
= arg1
;
750 struct proc
*const *pp2
= arg2
;
751 struct kinfo_proc
*p1
;
752 struct kinfo_proc
*p2
;
756 /* remove one level of indirection */
757 p1
= *(struct kinfo_proc
*const *)pp1
;
758 p2
= *(struct kinfo_proc
*const *)pp2
;
771 /* compare_time - the comparison function for sorting by total cpu time */
774 compare_time(const void *arg1
, const void *arg2
)
776 struct proc
*const *pp1
= arg1
;
777 struct proc
*const *pp2
= arg2
;
778 const struct kinfo_proc
*p1
;
779 const struct kinfo_proc
*p2
;
783 /* remove one level of indirection */
784 p1
= *(struct kinfo_proc
*const *)pp1
;
785 p2
= *(struct kinfo_proc
*const *)pp2
;
790 ORDERKEY_KTHREADS_PRIO
800 /* compare_prio - the comparison function for sorting by cpu percentage */
803 compare_prio(const void *arg1
, const void *arg2
)
805 struct proc
*const *pp1
= arg1
;
806 struct proc
*const *pp2
= arg2
;
807 const struct kinfo_proc
*p1
;
808 const struct kinfo_proc
*p2
;
812 /* remove one level of indirection */
813 p1
= *(struct kinfo_proc
*const *)pp1
;
814 p2
= *(struct kinfo_proc
*const *)pp2
;
817 ORDERKEY_KTHREADS_PRIO
830 compare_thr(const void *arg1
, const void *arg2
)
832 struct proc
*const *pp1
= arg1
;
833 struct proc
*const *pp2
= arg2
;
834 const struct kinfo_proc
*p1
;
835 const struct kinfo_proc
*p2
;
839 /* remove one level of indirection */
840 p1
= *(struct kinfo_proc
*const *)pp1
;
841 p2
= *(struct kinfo_proc
*const *)pp2
;
844 ORDERKEY_KTHREADS_PRIO
856 * proc_owner(pid) - returns the uid that owns process "pid", or -1 if
857 * the process does not exist.
858 * It is EXTREMLY IMPORTANT that this function work correctly.
859 * If top runs setuid root (as in SVR4), then this function
860 * is the only thing that stands in the way of a serious
861 * security problem. It validates requests for the "kill"
862 * and "renice" commands.
869 struct kinfo_proc
**prefp
;
870 struct kinfo_proc
*pp
;
874 while (--xcnt
>= 0) {
876 if (PP(pp
, pid
) == (pid_t
) pid
) {
877 return ((int)PP(pp
, ruid
));
885 * swapmode is based on a program called swapinfo written
886 * by Kevin Lahey <kml@rokkaku.atl.ga.us>.
889 swapmode(int *retavail
, int *retfree
)
892 int pagesize
= getpagesize();
893 struct kvm_swap swapary
[1];
898 #define CONVERT(v) ((quad_t)(v) * pagesize / 1024)
900 n
= kvm_getswapinfo(kd
, swapary
, 1, 0);
901 if (n
< 0 || swapary
[0].ksw_total
== 0)
904 *retavail
= CONVERT(swapary
[0].ksw_total
);
905 *retfree
= CONVERT(swapary
[0].ksw_total
- swapary
[0].ksw_used
);
907 n
= (int)((double)swapary
[0].ksw_used
* 100.0 /
908 (double)swapary
[0].ksw_total
);