Changeset View
Changeset View
Standalone View
Standalone View
sys/vm/vm_meter.c
Show First 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
static bool | static bool | ||||
is_object_active(vm_object_t obj) | is_object_active(vm_object_t obj) | ||||
{ | { | ||||
return (obj->ref_count > obj->shadow_count); | return (obj->ref_count > obj->shadow_count); | ||||
} | } | ||||
#if defined(COMPAT_FREEBSD11) | |||||
struct vmtotal11 { | |||||
int16_t t_rq; | |||||
int16_t t_dw; | |||||
int16_t t_pw; | |||||
int16_t t_sl; | |||||
int16_t t_sw; | |||||
int32_t t_vm; | |||||
int32_t t_avm; | |||||
int32_t t_rm; | |||||
int32_t t_arm; | |||||
int32_t t_vmshr; | |||||
int32_t t_avmshr; | |||||
int32_t t_rmshr; | |||||
int32_t t_armshr; | |||||
int32_t t_free; | |||||
}; | |||||
#endif | |||||
static int | static int | ||||
vmtotal(SYSCTL_HANDLER_ARGS) | vmtotal(SYSCTL_HANDLER_ARGS) | ||||
{ | { | ||||
struct vmtotal total; | struct vmtotal total; | ||||
#if defined(COMPAT_FREEBSD11) | |||||
struct vmtotal11 total11; | |||||
#endif | |||||
vm_object_t object; | vm_object_t object; | ||||
struct proc *p; | struct proc *p; | ||||
struct thread *td; | struct thread *td; | ||||
#if defined(COMPAT_FREEBSD11) | |||||
p = curproc; | |||||
if (p->p_osrel < P_OSREL_VMTOTAL64 && req->oldptr == NULL) | |||||
kib: Why do you need the assignment to p ? It is only used once.
Case of req->oldptr == NULL makes… | |||||
return (SYSCTL_OUT(req, NULL, sizeof(total11))); | |||||
#endif | |||||
bzero(&total, sizeof(total)); | bzero(&total, sizeof(total)); | ||||
/* | /* | ||||
* Calculate process statistics. | * Calculate process statistics. | ||||
*/ | */ | ||||
sx_slock(&allproc_lock); | sx_slock(&allproc_lock); | ||||
FOREACH_PROC_IN_SYSTEM(p) { | FOREACH_PROC_IN_SYSTEM(p) { | ||||
if ((p->p_flag & P_SYSTEM) != 0) | if ((p->p_flag & P_SYSTEM) != 0) | ||||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | if (object->shadow_count > 1) { | ||||
if (is_object_active(object)) { | if (is_object_active(object)) { | ||||
total.t_avmshr += object->size; | total.t_avmshr += object->size; | ||||
total.t_armshr += object->resident_page_count; | total.t_armshr += object->resident_page_count; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
mtx_unlock(&vm_object_list_mtx); | mtx_unlock(&vm_object_list_mtx); | ||||
total.t_free = vm_cnt.v_free_count; | total.t_free = vm_cnt.v_free_count; | ||||
#if defined(COMPAT_FREEBSD11) | |||||
/* sysctl(8) allocates twice as much memory as repoted by sysctl(3) */ | |||||
kibUnsubmitted Not Done Inline ActionsrepoRted kib: repoRted | |||||
if (req->oldlen == sizeof(total11) || req->oldlen == | |||||
kaktusAuthorUnsubmitted Not Done Inline ActionsShould I account for sizeof(vmtotal) == 2*sizeof(vmtotal11) here and enclose it in p->p_osrel check? kaktus: Should I account for sizeof(vmtotal) == 2*sizeof(vmtotal11) here and enclose it in p->p_osrel… | |||||
(2 * sizeof(total11))) { | |||||
Not Done Inline ActionsNo need for () around 2 * sizeof. kib: No need for () around 2 * sizeof. | |||||
bzero(&total11, sizeof(total11)); | |||||
kibUnsubmitted Not Done Inline ActionsUnneeded blank line. kib: Unneeded blank line. | |||||
total11.t_rq = total.t_rq; | |||||
total11.t_dw = total.t_dw; | |||||
total11.t_pw = total.t_pw; | |||||
total11.t_sl = total.t_sl; | |||||
total11.t_sw = total.t_sw; | |||||
total11.t_vm = total.t_vm; /* truncate */ | |||||
total11.t_avm = total.t_avm; /* truncate */ | |||||
total11.t_rm = total.t_rm; /* truncate */ | |||||
total11.t_arm = total.t_arm; /* truncate */ | |||||
total11.t_vmshr = total.t_vmshr; /* truncate */ | |||||
total11.t_avmshr = total.t_avmshr; /* truncate */ | |||||
total11.t_rmshr = total.t_rmshr; /* truncate */ | |||||
total11.t_armshr = total.t_armshr; /* truncate */ | |||||
total11.t_free = total.t_free; /* truncate */ | |||||
kibUnsubmitted Not Done Inline ActionsAgain unneeded blank line. kib: Again unneeded blank line. | |||||
return (SYSCTL_OUT(req, &total11, sizeof(total11))); | |||||
} | |||||
#endif | |||||
return (sysctl_handle_opaque(oidp, &total, sizeof(total), req)); | return (sysctl_handle_opaque(oidp, &total, sizeof(total), req)); | ||||
} | } | ||||
Not Done Inline ActionsLook at the old style of the SYSCTL_PROC() split: put the description on the new line. Also, while there, fix style on the previous line, put spaces around binary '|' operator. kib: Look at the old style of the SYSCTL_PROC() split: put the description on the new line.
Also… | |||||
#if defined(COMPAT_FREEBSD11) | |||||
SYSCTL_PROC(_vm, VM_TOTAL, vmtotal, CTLTYPE_OPAQUE|CTLFLAG_RD|CTLFLAG_MPSAFE, | SYSCTL_PROC(_vm, VM_TOTAL, vmtotal, CTLTYPE_OPAQUE|CTLFLAG_RD|CTLFLAG_MPSAFE, | ||||
NULL, 0, vmtotal, "S,vmtotal", "System virtual memory statistics"); | |||||
#else | |||||
SYSCTL_PROC(_vm, VM_TOTAL, vmtotal, CTLTYPE_OPAQUE|CTLFLAG_RD|CTLFLAG_MPSAFE, | |||||
kibUnsubmitted Not Done Inline ActionsWhy do you want to keep this case declared as before ? I do not see the point. kib: Why do you want to keep this case declared as before ? I do not see the point. | |||||
0, sizeof(struct vmtotal), vmtotal, "S,vmtotal", | 0, sizeof(struct vmtotal), vmtotal, "S,vmtotal", | ||||
"System virtual memory statistics"); | "System virtual memory statistics"); | ||||
#endif | |||||
SYSCTL_NODE(_vm, OID_AUTO, stats, CTLFLAG_RW, 0, "VM meter stats"); | SYSCTL_NODE(_vm, OID_AUTO, stats, CTLFLAG_RW, 0, "VM meter stats"); | ||||
static SYSCTL_NODE(_vm_stats, OID_AUTO, sys, CTLFLAG_RW, 0, | static SYSCTL_NODE(_vm_stats, OID_AUTO, sys, CTLFLAG_RW, 0, | ||||
"VM meter sys stats"); | "VM meter sys stats"); | ||||
static SYSCTL_NODE(_vm_stats, OID_AUTO, vm, CTLFLAG_RW, 0, | static SYSCTL_NODE(_vm_stats, OID_AUTO, vm, CTLFLAG_RW, 0, | ||||
"VM meter vm stats"); | "VM meter vm stats"); | ||||
SYSCTL_NODE(_vm_stats, OID_AUTO, misc, CTLFLAG_RW, 0, "VM meter misc stats"); | SYSCTL_NODE(_vm_stats, OID_AUTO, misc, CTLFLAG_RW, 0, "VM meter misc stats"); | ||||
static int | static int | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |
Why do you need the assignment to p ? It is only used once.
Case of req->oldptr == NULL makes the useful optimization for non-compat case as well: there is no need to iterate over all processes just to return sizeof(struct vmtotal).