From 7dc51496b094bf268be8bef1af34a49384487961 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 25 Mar 2011 14:38:35 -0700 Subject: [PATCH] kernel - Fix MP race in vmspace_president_count() (2) * Fix bug in last commit related to buildworld also wanting to use the inline functions in vm_map.h Reported-by: Magliano Andrea --- sys/vm/vm_map.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sys/vm/vm_map.h b/sys/vm/vm_map.h index 180dadf28c..615b106266 100644 --- a/sys/vm/vm_map.h +++ b/sys/vm/vm_map.h @@ -75,8 +75,10 @@ #ifndef _SYS_TYPES_H_ #include #endif +#ifdef _KERNEL #ifndef _SYS_KERNEL_H_ -#include +#include /* ticks */ +#endif #endif #ifndef _SYS_TREE_H_ #include @@ -426,6 +428,8 @@ vmspace_resident_count(struct vmspace *vmspace) * accrued result. This is a loose value for statistics/display * purposes only and will only be updated if we can acquire * a non-blocking map lock. + * + * (used by userland or the kernel) */ static __inline u_int vmspace_president_count(struct vmspace *vmspace) @@ -435,8 +439,10 @@ vmspace_president_count(struct vmspace *vmspace) vm_object_t object; u_int count = 0; +#ifdef _KERNEL if (map->president_ticks == ticks / hz || vm_map_lock_read_try(map)) return(map->president_cache); +#endif for (cur = map->header.next; cur != &map->header; cur = cur->next) { switch(cur->maptype) { @@ -457,9 +463,11 @@ vmspace_president_count(struct vmspace *vmspace) break; } } +#ifdef _KERNEL map->president_cache = count; map->president_ticks = ticks / hz; vm_map_unlock_read(map); +#endif return(count); } -- 2.41.0