xref: /netbsd-src/sys/uvm/uvm_object.h (revision b757af438b42b93f8c6571f026d8b8ef3eaf5fc9)
1 /*	$NetBSD: uvm_object.h,v 1.32 2012/01/28 14:37:35 rmind Exp $	*/
2 
3 /*
4  * Copyright (c) 1997 Charles D. Cranor and Washington University.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * from: Id: uvm_object.h,v 1.1.2.2 1998/01/04 22:44:51 chuck Exp
28  */
29 
30 #ifndef _UVM_UVM_OBJECT_H_
31 #define _UVM_UVM_OBJECT_H_
32 
33 #include <sys/queue.h>
34 #include <sys/rbtree.h>
35 #include <uvm/uvm_pglist.h>
36 
37 /*
38  * The UVM memory object interface.  Notes:
39  *
40  * A UVM memory object represents a list of pages, which are managed by
41  * the object's pager operations (uvm_object::pgops).  All pages belonging
42  * to an object are owned by it and thus protected by the object lock.
43  *
44  * The lock (uvm_object::vmobjlock) may be shared amongst the UVM objects.
45  * By default, the lock is allocated dynamically using mutex_obj(9) cache.
46  * Lock sharing is normally used when there is an underlying object.  For
47  * example, vnode representing a file may have an underlying node, which
48  * is the case for tmpfs and layered file systems.  In such case, vnode's
49  * UVM object and the underlying UVM object shares the lock (note that the
50  * vnode_t::v_interlock points to uvm_object::vmobjlock).
51  */
52 
53 struct uvm_object {
54 	kmutex_t *		vmobjlock;	/* lock on memq */
55 	const struct uvm_pagerops *pgops;	/* pager ops */
56 	struct pglist		memq;		/* pages in this object */
57 	int			uo_npages;	/* # of pages in memq */
58 	unsigned		uo_refs;	/* reference count */
59 	struct rb_tree		rb_tree;	/* tree of pages */
60 	LIST_HEAD(,ubc_map)	uo_ubc;		/* ubc mappings */
61 };
62 
63 /*
64  * UVM_OBJ_KERN is a 'special' uo_refs value which indicates that the
65  * object is a kernel memory object rather than a normal one (kernel
66  * memory objects don't have reference counts -- they never die).
67  *
68  * this value is used to detected kernel object mappings at uvm_unmap()
69  * time.   normally when an object is unmapped its pages eventaully become
70  * deactivated and then paged out and/or freed.    this is not useful
71  * for kernel objects... when a kernel object is unmapped we always want
72  * to free the resources associated with the mapping.   UVM_OBJ_KERN
73  * allows us to decide which type of unmapping we want to do.
74  */
75 #define UVM_OBJ_KERN		(-2)
76 
77 #define	UVM_OBJ_IS_KERN_OBJECT(uobj)					\
78 	((uobj)->uo_refs == UVM_OBJ_KERN)
79 
80 #ifdef _KERNEL
81 
82 extern const struct uvm_pagerops uvm_vnodeops;
83 extern const struct uvm_pagerops uvm_deviceops;
84 extern const struct uvm_pagerops ubc_pager;
85 extern const struct uvm_pagerops aobj_pager;
86 
87 #define	UVM_OBJ_IS_VNODE(uobj)						\
88 	((uobj)->pgops == &uvm_vnodeops)
89 
90 #define	UVM_OBJ_IS_DEVICE(uobj)						\
91 	((uobj)->pgops == &uvm_deviceops)
92 
93 #define	UVM_OBJ_IS_VTEXT(uobj)						\
94 	(UVM_OBJ_IS_VNODE(uobj) && uvn_text_p(uobj))
95 
96 #define	UVM_OBJ_IS_CLEAN(uobj)						\
97 	(UVM_OBJ_IS_VNODE(uobj) && uvn_clean_p(uobj))
98 
99 /*
100  * UVM_OBJ_NEEDS_WRITEFAULT: true if the uobj needs to detect modification.
101  * (ie. wants to avoid writable user mappings.)
102  *
103  * XXX bad name
104  */
105 
106 #define	UVM_OBJ_NEEDS_WRITEFAULT(uobj)					\
107 	(UVM_OBJ_IS_VNODE(uobj) && uvn_needs_writefault_p(uobj))
108 
109 #define	UVM_OBJ_IS_AOBJ(uobj)						\
110 	((uobj)->pgops == &aobj_pager)
111 
112 extern const rb_tree_ops_t uvm_page_tree_ops;
113 
114 #endif /* _KERNEL */
115 
116 #endif /* _UVM_UVM_OBJECT_H_ */
117