xref: /freebsd/share/man/man9/vm_page_busy.9 (revision 87b646630c4892e21446cd096bea6bcaecea33ac)
1c7aebda8SAttilio Rao.\"
2c7aebda8SAttilio Rao.\" Copyright (c) 2013 EMC Corp.
3c7aebda8SAttilio Rao.\" All rights reserved.
4c7aebda8SAttilio Rao.\"
5c7aebda8SAttilio Rao.\" Redistribution and use in source and binary forms, with or without
6c7aebda8SAttilio Rao.\" modification, are permitted provided that the following conditions
7c7aebda8SAttilio Rao.\" are met:
8c7aebda8SAttilio Rao.\" 1. Redistributions of source code must retain the above copyright
9c7aebda8SAttilio Rao.\"    notice, this list of conditions and the following disclaimer.
10c7aebda8SAttilio Rao.\" 2. Redistributions in binary form must reproduce the above copyright
11c7aebda8SAttilio Rao.\"    notice, this list of conditions and the following disclaimer in the
12c7aebda8SAttilio Rao.\"    documentation and/or other materials provided with the distribution.
13c7aebda8SAttilio Rao.\"
14c7aebda8SAttilio Rao.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15c7aebda8SAttilio Rao.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16c7aebda8SAttilio Rao.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17c7aebda8SAttilio Rao.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18c7aebda8SAttilio Rao.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19c7aebda8SAttilio Rao.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20c7aebda8SAttilio Rao.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21c7aebda8SAttilio Rao.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22c7aebda8SAttilio Rao.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23c7aebda8SAttilio Rao.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
24c7aebda8SAttilio Rao.\" DAMAGE.
25c7aebda8SAttilio Rao.\"
26c7aebda8SAttilio Rao.\" $FreeBSD$
27*87b64663SMark Johnston.Dd November 11, 2021
285b63fb79SJoel Dahl.Dt VM_PAGE_BUSY 9
29c7aebda8SAttilio Rao.Os
30c7aebda8SAttilio Rao.Sh NAME
31c7aebda8SAttilio Rao.Nm vm_page_busied ,
32c7aebda8SAttilio Rao.Nm vm_page_busy_downgrade ,
33c7aebda8SAttilio Rao.Nm vm_page_busy_sleep ,
34c7aebda8SAttilio Rao.Nm vm_page_sbusied ,
35c7aebda8SAttilio Rao.Nm vm_page_sbusy ,
36c7aebda8SAttilio Rao.Nm vm_page_sunbusy ,
37c7aebda8SAttilio Rao.Nm vm_page_trysbusy ,
38c7aebda8SAttilio Rao.Nm vm_page_tryxbusy ,
39c7aebda8SAttilio Rao.Nm vm_page_xbusied ,
40c7aebda8SAttilio Rao.Nm vm_page_xbusy ,
41c7aebda8SAttilio Rao.Nm vm_page_xunbusy ,
42c7aebda8SAttilio Rao.Nm vm_page_assert_sbusied ,
43c7aebda8SAttilio Rao.Nm vm_page_assert_unbusied ,
44c7aebda8SAttilio Rao.Nm vm_page_assert_xbusied
45c7aebda8SAttilio Rao.Nd protect page identity changes and page content references
46c7aebda8SAttilio Rao.Sh SYNOPSIS
47c7aebda8SAttilio Rao.In sys/param.h
48c7aebda8SAttilio Rao.In vm/vm.h
49c7aebda8SAttilio Rao.In vm/vm_page.h
50c7aebda8SAttilio Rao.Ft int
51c7aebda8SAttilio Rao.Fn vm_page_busied "vm_page_t m"
52c7aebda8SAttilio Rao.Ft void
53c7aebda8SAttilio Rao.Fn vm_page_busy_downgrade "vm_page_t m"
54*87b64663SMark Johnston.Ft bool
55*87b64663SMark Johnston.Fn vm_page_busy_sleep "vm_page_t m" "const char *msg" "int allocflags"
56c7aebda8SAttilio Rao.Ft int
57c7aebda8SAttilio Rao.Fn vm_page_sbusied "vm_page_t m"
58c7aebda8SAttilio Rao.Ft void
59c7aebda8SAttilio Rao.Fn vm_page_sbusy "vm_page_t m"
60c7aebda8SAttilio Rao.Ft void
61c7aebda8SAttilio Rao.Fn vm_page_sunbusy "vm_page_t m"
62c7aebda8SAttilio Rao.Ft int
63c7aebda8SAttilio Rao.Fn vm_page_trysbusy "vm_page_t m"
64c7aebda8SAttilio Rao.Ft int
65c7aebda8SAttilio Rao.Fn vm_page_tryxbusy "vm_page_t m"
66c7aebda8SAttilio Rao.Ft int
67c7aebda8SAttilio Rao.Fn vm_page_xbusied "vm_page_t m"
68c7aebda8SAttilio Rao.Ft void
69c7aebda8SAttilio Rao.Fn vm_page_xbusy "vm_page_t m"
70c7aebda8SAttilio Rao.Ft void
71c7aebda8SAttilio Rao.Fn vm_page_xunbusy "vm_page_t m"
72c7aebda8SAttilio Rao.Pp
73c7aebda8SAttilio Rao.Cd "options INVARIANTS"
74c7aebda8SAttilio Rao.Cd "options INVARIANT_SUPPORT"
75c7aebda8SAttilio Rao.Ft void
76c7aebda8SAttilio Rao.Fn vm_page_assert_sbusied "vm_page_t m"
77c7aebda8SAttilio Rao.Ft void
78c7aebda8SAttilio Rao.Fn vm_page_assert_unbusied "vm_page_t m"
79c7aebda8SAttilio Rao.Ft void
80c7aebda8SAttilio Rao.Fn vm_page_assert_xbusied "vm_page_t m"
81c7aebda8SAttilio Rao.Sh DESCRIPTION
82c7aebda8SAttilio RaoPage identity is usually protected by higher level locks like vm_object
83c7aebda8SAttilio Raolocks and vm page locks.
84c7aebda8SAttilio RaoHowever, sometimes it is not possible to hold such locks for the time
85c7aebda8SAttilio Raonecessary to complete the identity change.
86c7aebda8SAttilio RaoIn such case the page can be exclusively busied by a thread which needs
87c7aebda8SAttilio Raoto own the identity for a certain amount of time.
88c7aebda8SAttilio Rao.Pp
89c7aebda8SAttilio RaoIn other situations, threads do not need to change the identity of the
90c7aebda8SAttilio Raopage but they want to prevent other threads from changing the identity
91c7aebda8SAttilio Raothemselves.
92c7aebda8SAttilio RaoFor example, when a thread wants to access or update page contents
93c7aebda8SAttilio Raowithout a lock held the page is shared busied.
94c7aebda8SAttilio Rao.Pp
95ebd88e49SJohn BaldwinBefore busying a page the vm_object lock must be held.
96c7aebda8SAttilio RaoThe same rule applies when a page is unbusied.
97c7aebda8SAttilio RaoThis makes the vm_object lock a real busy interlock.
98c7aebda8SAttilio Rao.Pp
99c7aebda8SAttilio RaoThe
100c7aebda8SAttilio Rao.Fn vm_page_busied
101c7aebda8SAttilio Raofunction returns non-zero if the current thread busied
102c7aebda8SAttilio Rao.Fa m
103c7aebda8SAttilio Raoin either exclusive or shared mode.
104c7aebda8SAttilio RaoReturns zero otherwise.
105c7aebda8SAttilio Rao.Pp
106c7aebda8SAttilio RaoThe
107c7aebda8SAttilio Rao.Fn vm_page_busy_downgrade
108c7aebda8SAttilio Raofunction must be used to downgrade
109c7aebda8SAttilio Rao.Fa m
110c7aebda8SAttilio Raofrom an exclusive busy state to a shared busy state.
111c7aebda8SAttilio Rao.Pp
112c7aebda8SAttilio RaoThe
113c7aebda8SAttilio Rao.Fn vm_page_busy_sleep
114*87b64663SMark Johnstonchecks the busy state of the page
115*87b64663SMark Johnston.Fa m
116*87b64663SMark Johnstonand puts the invoking thread to sleep if the page is busy.
117*87b64663SMark JohnstonThe VM object for the page must be locked.
118*87b64663SMark JohnstonThe
119*87b64663SMark Johnston.Fa allocflags
120*87b64663SMark Johnstonparameter must be either
121*87b64663SMark Johnston.Dv 0 ,
122*87b64663SMark Johnstonin which case the function will sleep if the page is busied,
123*87b64663SMark Johnstonor
124*87b64663SMark Johnston.Dv VM_ALLOC_IGN_SBUSY ,
125*87b64663SMark Johnstonin which case the function will sleep only if the page is exclusively
126*87b64663SMark Johnstonbusied.
127*87b64663SMark JohnstonA return value of true indicates that the invoking thread was put to
128*87b64663SMark Johnstonsleep and that the object was unlocked.
129*87b64663SMark JohnstonA return value of false indicates that the invoking thread did not sleep
130*87b64663SMark Johnstonand the object remains locked.
131c7aebda8SAttilio RaoThe parameter
132c7aebda8SAttilio Rao.Fa msg
133c7aebda8SAttilio Raois a string describing the sleep condition for userland tools.
134c7aebda8SAttilio Rao.Pp
135c7aebda8SAttilio RaoThe
136c7aebda8SAttilio Rao.Fn vm_page_busied
137c7aebda8SAttilio Raofunction returns non-zero if the current thread busied
138c7aebda8SAttilio Rao.Fa m
139c7aebda8SAttilio Raoin shared mode.
140c7aebda8SAttilio RaoReturns zero otherwise.
141c7aebda8SAttilio Rao.Pp
142c7aebda8SAttilio RaoThe
143c7aebda8SAttilio Rao.Fn vm_page_sbusy
144c7aebda8SAttilio Raofunction shared busies
145c7aebda8SAttilio Rao.Fa m .
146c7aebda8SAttilio Rao.Pp
147c7aebda8SAttilio RaoThe
148c7aebda8SAttilio Rao.Fn vm_page_sunbusy
149c7aebda8SAttilio Raofunction shared unbusies
150c7aebda8SAttilio Rao.Fa m .
151c7aebda8SAttilio Rao.Pp
152c7aebda8SAttilio RaoThe
153c7aebda8SAttilio Rao.Fn vm_page_trysbusy
154c7aebda8SAttilio Raoattempts to shared busy
155c7aebda8SAttilio Rao.Fa m .
156c7aebda8SAttilio RaoIf the operation cannot immediately succeed
157c7aebda8SAttilio Rao.Fn vm_page_trysbusy
158c7aebda8SAttilio Raoreturns 0, otherwise a non-zero value is returned.
159c7aebda8SAttilio Rao.Pp
160c7aebda8SAttilio RaoThe
161c7aebda8SAttilio Rao.Fn vm_page_tryxbusy
162c7aebda8SAttilio Raoattempts to exclusive busy
163c7aebda8SAttilio Rao.Fa m .
164c7aebda8SAttilio RaoIf the operation cannot immediately succeed
165c7aebda8SAttilio Rao.Fn vm_page_tryxbusy
166c7aebda8SAttilio Raoreturns 0, otherwise a non-zero value is returned.
167c7aebda8SAttilio Rao.Pp
168c7aebda8SAttilio RaoThe
169c7aebda8SAttilio Rao.Fn vm_page_xbusied
170c7aebda8SAttilio Raofunction returns non-zero if the current thread busied
171c7aebda8SAttilio Rao.Fa m
172c7aebda8SAttilio Raoin exclusive mode.
173c7aebda8SAttilio RaoReturns zero otherwise.
174c7aebda8SAttilio Rao.Pp
175c7aebda8SAttilio RaoThe
176c7aebda8SAttilio Rao.Fn vm_page_xbusy
177c7aebda8SAttilio Raofunction exclusive busies
178c7aebda8SAttilio Rao.Fa m .
179c7aebda8SAttilio Rao.Pp
180c7aebda8SAttilio RaoThe
181c7aebda8SAttilio Rao.Fn vm_page_xunbusy
182c7aebda8SAttilio Raofunction exclusive unbusies
183c7aebda8SAttilio Rao.Fa m .
184c7aebda8SAttilio RaoAssertions on the busy state allow kernels compiled with
185c7aebda8SAttilio Rao.Cd "options INVARIANTS"
186c7aebda8SAttilio Raoand
187c7aebda8SAttilio Rao.Cd "options INVARIANT_SUPPORT"
188c7aebda8SAttilio Raoto panic if they are not respected.
189c7aebda8SAttilio Rao.Pp
190c7aebda8SAttilio RaoThe
191c7aebda8SAttilio Rao.Fn vm_page_assert_sbusied
192c7aebda8SAttilio Raofunction panics if
193c7aebda8SAttilio Rao.Fa m
194c7aebda8SAttilio Raois not shared busied.
195c7aebda8SAttilio Rao.Pp
196c7aebda8SAttilio RaoThe
197c7aebda8SAttilio Rao.Fn vm_page_assert_unbusied
198c7aebda8SAttilio Raofunction panics if
199c7aebda8SAttilio Rao.Fa m
200c7aebda8SAttilio Raois not unbusied.
201c7aebda8SAttilio Rao.Pp
202c7aebda8SAttilio RaoThe
203c7aebda8SAttilio Rao.Fn vm_page_assert_xbusied
204c7aebda8SAttilio Raofunction panics if
205c7aebda8SAttilio Rao.Fa m
206c7aebda8SAttilio Raois not exclusive busied.
207c7aebda8SAttilio Rao.Sh SEE ALSO
208c7aebda8SAttilio Rao.Xr vm_page_aflag 9 ,
209c7aebda8SAttilio Rao.Xr vm_page_alloc 9 ,
210c7aebda8SAttilio Rao.Xr vm_page_deactivate 9 ,
211c7aebda8SAttilio Rao.Xr vm_page_free 9 ,
212c7aebda8SAttilio Rao.Xr vm_page_grab 9 ,
213c7aebda8SAttilio Rao.Xr vm_page_insert 9 ,
214c7aebda8SAttilio Rao.Xr vm_page_lookup 9 ,
2151e9469d1SChristian Brueffer.Xr vm_page_rename 9 ,
2161e9469d1SChristian Brueffer.Xr VOP_GETPAGES 9
217