xref: /netbsd-src/sys/uvm/uvm_object.h (revision 82bba4e936dd1e9880e4f07ab0ecd4335b2b46ea)
1*82bba4e9Sandvar /*	$NetBSD: uvm_object.h,v 1.40 2024/02/05 21:46:07 andvar Exp $	*/
2f2caacc7Smrg 
3f2caacc7Smrg /*
4f2caacc7Smrg  * Copyright (c) 1997 Charles D. Cranor and Washington University.
5f2caacc7Smrg  * All rights reserved.
6f2caacc7Smrg  *
7f2caacc7Smrg  * Redistribution and use in source and binary forms, with or without
8f2caacc7Smrg  * modification, are permitted provided that the following conditions
9f2caacc7Smrg  * are met:
10f2caacc7Smrg  * 1. Redistributions of source code must retain the above copyright
11f2caacc7Smrg  *    notice, this list of conditions and the following disclaimer.
12f2caacc7Smrg  * 2. Redistributions in binary form must reproduce the above copyright
13f2caacc7Smrg  *    notice, this list of conditions and the following disclaimer in the
14f2caacc7Smrg  *    documentation and/or other materials provided with the distribution.
15f2caacc7Smrg  *
16f2caacc7Smrg  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17f2caacc7Smrg  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18f2caacc7Smrg  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19f2caacc7Smrg  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20f2caacc7Smrg  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21f2caacc7Smrg  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22f2caacc7Smrg  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23f2caacc7Smrg  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24f2caacc7Smrg  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25f2caacc7Smrg  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
261f6b921cSmrg  *
271f6b921cSmrg  * from: Id: uvm_object.h,v 1.1.2.2 1998/01/04 22:44:51 chuck Exp
28f2caacc7Smrg  */
29f2caacc7Smrg 
30021fdb64Sperry #ifndef _UVM_UVM_OBJECT_H_
31021fdb64Sperry #define _UVM_UVM_OBJECT_H_
32021fdb64Sperry 
33e225b7bdSrmind #include <sys/queue.h>
3468575131Sad #include <sys/radixtree.h>
35b73ba829Suebayasi #include <uvm/uvm_pglist.h>
367a34cb95Sad 
37f2caacc7Smrg /*
38247885b6Srmind  * The UVM memory object interface.  Notes:
39247885b6Srmind  *
40247885b6Srmind  * A UVM memory object represents a list of pages, which are managed by
41247885b6Srmind  * the object's pager operations (uvm_object::pgops).  All pages belonging
42247885b6Srmind  * to an object are owned by it and thus protected by the object lock.
43247885b6Srmind  *
44247885b6Srmind  * The lock (uvm_object::vmobjlock) may be shared amongst the UVM objects.
45247885b6Srmind  * By default, the lock is allocated dynamically using mutex_obj(9) cache.
46247885b6Srmind  * Lock sharing is normally used when there is an underlying object.  For
47247885b6Srmind  * example, vnode representing a file may have an underlying node, which
48247885b6Srmind  * is the case for tmpfs and layered file systems.  In such case, vnode's
49247885b6Srmind  * UVM object and the underlying UVM object shares the lock (note that the
50247885b6Srmind  * vnode_t::v_interlock points to uvm_object::vmobjlock).
511e840676Srmind  *
521e840676Srmind  * The reference count is managed atomically for the anonymous UVM objects.
531e840676Srmind  * For other objects, it is arbitrary (may use the lock or atomics).
54f2caacc7Smrg  */
55f2caacc7Smrg 
56d2a0ebb6Sad struct krwlock;
57f2caacc7Smrg struct uvm_object {
58d2a0ebb6Sad 	struct krwlock *	vmobjlock;	/* lock on object */
59e8abff70Syamt 	const struct uvm_pagerops *pgops;	/* pager ops */
6068575131Sad 	int			uo_npages;	/* # of pages in uo_pages */
613a8db315Sad 	unsigned		uo_refs;	/* reference count */
6268575131Sad 	struct radix_tree	uo_pages;	/* tree of pages */
63e225b7bdSrmind 	LIST_HEAD(,ubc_map)	uo_ubc;		/* ubc mappings */
64f2caacc7Smrg };
65f2caacc7Smrg 
66f2caacc7Smrg /*
6705a3457eSad  * tags for uo_pages
6805a3457eSad  */
6905a3457eSad 
7005a3457eSad #define	UVM_PAGE_DIRTY_TAG	1	/* might be dirty (!PG_CLEAN) */
7105a3457eSad #define	UVM_PAGE_WRITEBACK_TAG	2	/* being written back */
7205a3457eSad 
7305a3457eSad /*
74f2caacc7Smrg  * UVM_OBJ_KERN is a 'special' uo_refs value which indicates that the
75f2caacc7Smrg  * object is a kernel memory object rather than a normal one (kernel
76f2caacc7Smrg  * memory objects don't have reference counts -- they never die).
77f2caacc7Smrg  *
78f2caacc7Smrg  * this value is used to detected kernel object mappings at uvm_unmap()
79*82bba4e9Sandvar  * time.   normally when an object is unmapped its pages eventually become
80f2caacc7Smrg  * deactivated and then paged out and/or freed.    this is not useful
81f2caacc7Smrg  * for kernel objects... when a kernel object is unmapped we always want
82f2caacc7Smrg  * to free the resources associated with the mapping.   UVM_OBJ_KERN
83f2caacc7Smrg  * allows us to decide which type of unmapping we want to do.
84f2caacc7Smrg  */
85f2caacc7Smrg #define UVM_OBJ_KERN		(-2)
86f2caacc7Smrg 
870ff8d3acSthorpej #define	UVM_OBJ_IS_KERN_OBJECT(uobj)					\
8864c6d1d2Schs 	((uobj)->uo_refs == UVM_OBJ_KERN)
8985f8d134Sthorpej 
901cdff486Sthorpej #ifdef _KERNEL
911cdff486Sthorpej 
92e8abff70Syamt extern const struct uvm_pagerops uvm_vnodeops;
93e8abff70Syamt extern const struct uvm_pagerops uvm_deviceops;
94e8abff70Syamt extern const struct uvm_pagerops ubc_pager;
95e8abff70Syamt extern const struct uvm_pagerops aobj_pager;
961cdff486Sthorpej 
97d1c3f6baSthorpej #define	UVM_OBJ_IS_VNODE(uobj)						\
98d1c3f6baSthorpej 	((uobj)->pgops == &uvm_vnodeops)
99d1c3f6baSthorpej 
100f7d48e35Syamt #define	UVM_OBJ_IS_DEVICE(uobj)						\
101f7d48e35Syamt 	((uobj)->pgops == &uvm_deviceops)
102f7d48e35Syamt 
10383d071a3Schs #define	UVM_OBJ_IS_VTEXT(uobj)						\
1049de1cdc8Syamt 	(UVM_OBJ_IS_VNODE(uobj) && uvn_text_p(uobj))
10583d071a3Schs 
1068af42d8dSyamt #define	UVM_OBJ_IS_CLEAN(uobj)						\
10719303cecSchs 	(UVM_OBJ_IS_VNODE(uobj) && uvm_obj_clean_p(uobj))
1088af42d8dSyamt 
109b7bfe828Syamt /*
110b7bfe828Syamt  * UVM_OBJ_NEEDS_WRITEFAULT: true if the uobj needs to detect modification.
111b7bfe828Syamt  * (ie. wants to avoid writable user mappings.)
112b7bfe828Syamt  *
113b7bfe828Syamt  * XXX bad name
114b7bfe828Syamt  */
115b7bfe828Syamt 
116b7bfe828Syamt #define	UVM_OBJ_NEEDS_WRITEFAULT(uobj)					\
11719303cecSchs 	(UVM_OBJ_IS_VNODE(uobj) && uvm_obj_clean_p(uobj))
118b7bfe828Syamt 
119faab7dbbSchs #define	UVM_OBJ_IS_AOBJ(uobj)						\
120faab7dbbSchs 	((uobj)->pgops == &aobj_pager)
12183d071a3Schs 
1221cdff486Sthorpej #endif /* _KERNEL */
1231cdff486Sthorpej 
124021fdb64Sperry #endif /* _UVM_UVM_OBJECT_H_ */
125