diff options
author | alc <alc@FreeBSD.org> | 2012-12-09 00:32:38 +0000 |
---|---|---|
committer | alc <alc@FreeBSD.org> | 2012-12-09 00:32:38 +0000 |
commit | 02094caa2c2fce94821d84bde50b9373b47f97e7 (patch) | |
tree | aed54f82a0f3ede6ae38c3c71be27832f9a87d0a /sys/vm/vm_object.c | |
parent | c82d89183db93c8a4a4a1db712fa5464d28ff9a3 (diff) | |
download | FreeBSD-src-02094caa2c2fce94821d84bde50b9373b47f97e7.zip FreeBSD-src-02094caa2c2fce94821d84bde50b9373b47f97e7.tar.gz |
In the past four years, we've added two new vm object types. Each time,
similar changes had to be made in various places throughout the machine-
independent virtual memory layer to support the new vm object type.
However, in most of these places, it's actually not the type of the vm
object that matters to us but instead certain attributes of its pages.
For example, OBJT_DEVICE, OBJT_MGTDEVICE, and OBJT_SG objects contain
fictitious pages. In other words, in most of these places, we were
testing the vm object's type to determine if it contained fictitious (or
unmanaged) pages.
To both simplify the code in these places and make the addition of future
vm object types easier, this change introduces two new vm object flags
that describe attributes of the vm object's pages, specifically, whether
they are fictitious or unmanaged.
Reviewed and tested by: kib
Diffstat (limited to 'sys/vm/vm_object.c')
-rw-r--r-- | sys/vm/vm_object.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c index f95ab54..32b0779 100644 --- a/sys/vm/vm_object.c +++ b/sys/vm/vm_object.c @@ -212,15 +212,35 @@ _vm_object_allocate(objtype_t type, vm_pindex_t size, vm_object_t object) object->root = NULL; object->type = type; + switch (type) { + case OBJT_DEAD: + panic("_vm_object_allocate: can't create OBJT_DEAD"); + case OBJT_DEFAULT: + case OBJT_SWAP: + object->flags = OBJ_ONEMAPPING; + break; + case OBJT_DEVICE: + case OBJT_SG: + object->flags = OBJ_FICTITIOUS | OBJ_UNMANAGED; + break; + case OBJT_MGTDEVICE: + object->flags = OBJ_FICTITIOUS; + break; + case OBJT_PHYS: + object->flags = OBJ_UNMANAGED; + break; + case OBJT_VNODE: + object->flags = 0; + break; + default: + panic("_vm_object_allocate: type %d is undefined", type); + } object->size = size; object->generation = 1; object->ref_count = 1; object->memattr = VM_MEMATTR_DEFAULT; - object->flags = 0; object->cred = NULL; object->charge = 0; - if ((object->type == OBJT_DEFAULT) || (object->type == OBJT_SWAP)) - object->flags = OBJ_ONEMAPPING; object->pg_color = 0; object->handle = NULL; object->backing_object = NULL; @@ -1064,7 +1084,7 @@ shadowlookup: (tobject->flags & OBJ_ONEMAPPING) == 0) { goto unlock_tobject; } - } else if (tobject->type == OBJT_PHYS) + } else if ((tobject->flags & OBJ_UNMANAGED) != 0) goto unlock_tobject; m = vm_page_lookup(tobject, tpindex); if (m == NULL && advise == MADV_WILLNEED) { @@ -1834,7 +1854,7 @@ vm_object_page_remove(vm_object_t object, vm_pindex_t start, vm_pindex_t end, int wirings; VM_OBJECT_LOCK_ASSERT(object, MA_OWNED); - KASSERT((object->type != OBJT_DEVICE && object->type != OBJT_PHYS) || + KASSERT((object->flags & OBJ_UNMANAGED) == 0 || (options & (OBJPR_CLEANONLY | OBJPR_NOTMAPPED)) == OBJPR_NOTMAPPED, ("vm_object_page_remove: illegal options for object %p", object)); if (object->resident_page_count == 0) @@ -1918,7 +1938,7 @@ skipmemq: * pages are moved to the cache queue. * * This operation should only be performed on objects that - * contain managed pages. + * contain non-fictitious, managed pages. * * The object must be locked. */ @@ -1929,8 +1949,7 @@ vm_object_page_cache(vm_object_t object, vm_pindex_t start, vm_pindex_t end) vm_page_t p, next; VM_OBJECT_LOCK_ASSERT(object, MA_OWNED); - KASSERT((object->type != OBJT_DEVICE && object->type != OBJT_SG && - object->type != OBJT_PHYS), + KASSERT((object->flags & (OBJ_FICTITIOUS | OBJ_UNMANAGED)) == 0, ("vm_object_page_cache: illegal object %p", object)); if (object->resident_page_count == 0) return; |