From 1a587ef2a548f69d40ee88ca9b9a4fe6c32c5345 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Thu, 21 Oct 2010 17:29:32 +0000 Subject: [PATCH] - Make 'vm_refcnt' volatile so that compilers won't be tempted to treat its value as a loop invariant. Currently this is a no-op because 'atomic_cmpset_int()' clobbers all memory on current architectures. - Use atomic_fetchadd_int() instead of an atomic_cmpset_int() loop to drop a reference in vmspace_free(). Reviewed by: alc MFC after: 1 month --- sys/vm/vm_map.c | 6 +----- sys/vm/vm_map.h | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 2e0f0012a853..40c317d93a62 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -339,15 +339,11 @@ vmspace_dofree(struct vmspace *vm) void vmspace_free(struct vmspace *vm) { - int refcnt; if (vm->vm_refcnt == 0) panic("vmspace_free: attempt to free already freed vmspace"); - do - refcnt = vm->vm_refcnt; - while (!atomic_cmpset_int(&vm->vm_refcnt, refcnt, refcnt - 1)); - if (refcnt == 1) + if (atomic_fetchadd_int(&vm->vm_refcnt, -1) == 1) vmspace_dofree(vm); } diff --git a/sys/vm/vm_map.h b/sys/vm/vm_map.h index 18a1edf809a1..8715b41dc7f3 100644 --- a/sys/vm/vm_map.h +++ b/sys/vm/vm_map.h @@ -236,7 +236,7 @@ struct vmspace { caddr_t vm_taddr; /* (c) user virtual address of text */ caddr_t vm_daddr; /* (c) user virtual address of data */ caddr_t vm_maxsaddr; /* user VA at max stack growth */ - int vm_refcnt; /* number of references */ + volatile int vm_refcnt; /* number of references */ /* * Keep the PMAP last, so that CPU-specific variations of that * structure on a single architecture don't result in offset