xref: /freebsd/share/man/man9/vm_page_busy.9 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
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.
25*87b64663SMark Johnston.Dd November 11, 2021
265b63fb79SJoel Dahl.Dt VM_PAGE_BUSY 9
27c7aebda8SAttilio Rao.Os
28c7aebda8SAttilio Rao.Sh NAME
29c7aebda8SAttilio Rao.Nm vm_page_busied ,
30c7aebda8SAttilio Rao.Nm vm_page_busy_downgrade ,
31c7aebda8SAttilio Rao.Nm vm_page_busy_sleep ,
32c7aebda8SAttilio Rao.Nm vm_page_sbusied ,
33c7aebda8SAttilio Rao.Nm vm_page_sunbusy ,
34c7aebda8SAttilio Rao.Nm vm_page_trysbusy ,
35c7aebda8SAttilio Rao.Nm vm_page_tryxbusy ,
36c7aebda8SAttilio Rao.Nm vm_page_xbusied ,
37c7aebda8SAttilio Rao.Nm vm_page_xunbusy ,
38c7aebda8SAttilio Rao.Nm vm_page_assert_sbusied ,
39c7aebda8SAttilio Rao.Nm vm_page_assert_unbusied ,
40c7aebda8SAttilio Rao.Nm vm_page_assert_xbusied
41c7aebda8SAttilio Rao.Nd protect page identity changes and page content references
42c7aebda8SAttilio Rao.Sh SYNOPSIS
43c7aebda8SAttilio Rao.In sys/param.h
44c7aebda8SAttilio Rao.In vm/vm.h
45c7aebda8SAttilio Rao.In vm/vm_page.h
46c7aebda8SAttilio Rao.Ft int
47c7aebda8SAttilio Rao.Fn vm_page_busied "vm_page_t m"
48c7aebda8SAttilio Rao.Ft void
49c7aebda8SAttilio Rao.Fn vm_page_busy_downgrade "vm_page_t m"
50*87b64663SMark Johnston.Ft bool
51*87b64663SMark Johnston.Fn vm_page_busy_sleep "vm_page_t m" "const char *msg" "int allocflags"
52c7aebda8SAttilio Rao.Ft int
53c7aebda8SAttilio Rao.Fn vm_page_sbusied "vm_page_t m"
54c7aebda8SAttilio Rao.Ft void
55c7aebda8SAttilio Rao.Fn vm_page_sunbusy "vm_page_t m"
56c7aebda8SAttilio Rao.Ft int
57c7aebda8SAttilio Rao.Fn vm_page_trysbusy "vm_page_t m"
58c7aebda8SAttilio Rao.Ft int
59c7aebda8SAttilio Rao.Fn vm_page_tryxbusy "vm_page_t m"
60c7aebda8SAttilio Rao.Ft int
61c7aebda8SAttilio Rao.Fn vm_page_xbusied "vm_page_t m"
62c7aebda8SAttilio Rao.Ft void
63c7aebda8SAttilio Rao.Fn vm_page_xunbusy "vm_page_t m"
64c7aebda8SAttilio Rao.Pp
65c7aebda8SAttilio Rao.Cd "options INVARIANTS"
66c7aebda8SAttilio Rao.Cd "options INVARIANT_SUPPORT"
67c7aebda8SAttilio Rao.Ft void
68c7aebda8SAttilio Rao.Fn vm_page_assert_sbusied "vm_page_t m"
69c7aebda8SAttilio Rao.Ft void
70c7aebda8SAttilio Rao.Fn vm_page_assert_unbusied "vm_page_t m"
71c7aebda8SAttilio Rao.Ft void
72c7aebda8SAttilio Rao.Fn vm_page_assert_xbusied "vm_page_t m"
73c7aebda8SAttilio Rao.Sh DESCRIPTION
74c7aebda8SAttilio RaoPage identity is usually protected by higher level locks like vm_object
75c7aebda8SAttilio Raolocks and vm page locks.
76c7aebda8SAttilio RaoHowever, sometimes it is not possible to hold such locks for the time
77c7aebda8SAttilio Raonecessary to complete the identity change.
78c7aebda8SAttilio RaoIn such case the page can be exclusively busied by a thread which needs
79c7aebda8SAttilio Raoto own the identity for a certain amount of time.
80c7aebda8SAttilio Rao.Pp
81c7aebda8SAttilio RaoIn other situations, threads do not need to change the identity of the
82c7aebda8SAttilio Raopage but they want to prevent other threads from changing the identity
83c7aebda8SAttilio Raothemselves.
84c7aebda8SAttilio RaoFor example, when a thread wants to access or update page contents
85c7aebda8SAttilio Raowithout a lock held the page is shared busied.
86c7aebda8SAttilio Rao.Pp
87ebd88e49SJohn BaldwinBefore busying a page the vm_object lock must be held.
88c7aebda8SAttilio RaoThe same rule applies when a page is unbusied.
89c7aebda8SAttilio RaoThis makes the vm_object lock a real busy interlock.
90c7aebda8SAttilio Rao.Pp
91c7aebda8SAttilio RaoThe
92c7aebda8SAttilio Rao.Fn vm_page_busied
93c7aebda8SAttilio Raofunction returns non-zero if the current thread busied
94c7aebda8SAttilio Rao.Fa m
95c7aebda8SAttilio Raoin either exclusive or shared mode.
96c7aebda8SAttilio RaoReturns zero otherwise.
97c7aebda8SAttilio Rao.Pp
98c7aebda8SAttilio RaoThe
99c7aebda8SAttilio Rao.Fn vm_page_busy_downgrade
100c7aebda8SAttilio Raofunction must be used to downgrade
101c7aebda8SAttilio Rao.Fa m
102c7aebda8SAttilio Raofrom an exclusive busy state to a shared busy state.
103c7aebda8SAttilio Rao.Pp
104c7aebda8SAttilio RaoThe
105c7aebda8SAttilio Rao.Fn vm_page_busy_sleep
106*87b64663SMark Johnstonchecks the busy state of the page
107*87b64663SMark Johnston.Fa m
108*87b64663SMark Johnstonand puts the invoking thread to sleep if the page is busy.
109*87b64663SMark JohnstonThe VM object for the page must be locked.
110*87b64663SMark JohnstonThe
111*87b64663SMark Johnston.Fa allocflags
112*87b64663SMark Johnstonparameter must be either
113*87b64663SMark Johnston.Dv 0 ,
114*87b64663SMark Johnstonin which case the function will sleep if the page is busied,
115*87b64663SMark Johnstonor
116*87b64663SMark Johnston.Dv VM_ALLOC_IGN_SBUSY ,
117*87b64663SMark Johnstonin which case the function will sleep only if the page is exclusively
118*87b64663SMark Johnstonbusied.
119*87b64663SMark JohnstonA return value of true indicates that the invoking thread was put to
120*87b64663SMark Johnstonsleep and that the object was unlocked.
121*87b64663SMark JohnstonA return value of false indicates that the invoking thread did not sleep
122*87b64663SMark Johnstonand the object remains locked.
123c7aebda8SAttilio RaoThe parameter
124c7aebda8SAttilio Rao.Fa msg
125c7aebda8SAttilio Raois a string describing the sleep condition for userland tools.
126c7aebda8SAttilio Rao.Pp
127c7aebda8SAttilio RaoThe
128c7aebda8SAttilio Rao.Fn vm_page_busied
129c7aebda8SAttilio Raofunction returns non-zero if the current thread busied
130c7aebda8SAttilio Rao.Fa m
131c7aebda8SAttilio Raoin shared mode.
132c7aebda8SAttilio RaoReturns zero otherwise.
133c7aebda8SAttilio Rao.Pp
134c7aebda8SAttilio RaoThe
135c7aebda8SAttilio Rao.Fn vm_page_sunbusy
136c7aebda8SAttilio Raofunction shared unbusies
137c7aebda8SAttilio Rao.Fa m .
138c7aebda8SAttilio Rao.Pp
139c7aebda8SAttilio RaoThe
140c7aebda8SAttilio Rao.Fn vm_page_trysbusy
141c7aebda8SAttilio Raoattempts to shared busy
142c7aebda8SAttilio Rao.Fa m .
143c7aebda8SAttilio RaoIf the operation cannot immediately succeed
144c7aebda8SAttilio Rao.Fn vm_page_trysbusy
145c7aebda8SAttilio Raoreturns 0, otherwise a non-zero value is returned.
146c7aebda8SAttilio Rao.Pp
147c7aebda8SAttilio RaoThe
148c7aebda8SAttilio Rao.Fn vm_page_tryxbusy
149c7aebda8SAttilio Raoattempts to exclusive busy
150c7aebda8SAttilio Rao.Fa m .
151c7aebda8SAttilio RaoIf the operation cannot immediately succeed
152c7aebda8SAttilio Rao.Fn vm_page_tryxbusy
153c7aebda8SAttilio Raoreturns 0, otherwise a non-zero value is returned.
154c7aebda8SAttilio Rao.Pp
155c7aebda8SAttilio RaoThe
156c7aebda8SAttilio Rao.Fn vm_page_xbusied
157c7aebda8SAttilio Raofunction returns non-zero if the current thread busied
158c7aebda8SAttilio Rao.Fa m
159c7aebda8SAttilio Raoin exclusive mode.
160c7aebda8SAttilio RaoReturns zero otherwise.
161c7aebda8SAttilio Rao.Pp
162c7aebda8SAttilio RaoThe
163c7aebda8SAttilio Rao.Fn vm_page_xunbusy
164c7aebda8SAttilio Raofunction exclusive unbusies
165c7aebda8SAttilio Rao.Fa m .
166c7aebda8SAttilio RaoAssertions on the busy state allow kernels compiled with
167c7aebda8SAttilio Rao.Cd "options INVARIANTS"
168c7aebda8SAttilio Raoand
169c7aebda8SAttilio Rao.Cd "options INVARIANT_SUPPORT"
170c7aebda8SAttilio Raoto panic if they are not respected.
171c7aebda8SAttilio Rao.Pp
172c7aebda8SAttilio RaoThe
173c7aebda8SAttilio Rao.Fn vm_page_assert_sbusied
174c7aebda8SAttilio Raofunction panics if
175c7aebda8SAttilio Rao.Fa m
176c7aebda8SAttilio Raois not shared busied.
177c7aebda8SAttilio Rao.Pp
178c7aebda8SAttilio RaoThe
179c7aebda8SAttilio Rao.Fn vm_page_assert_unbusied
180c7aebda8SAttilio Raofunction panics if
181c7aebda8SAttilio Rao.Fa m
182c7aebda8SAttilio Raois not unbusied.
183c7aebda8SAttilio Rao.Pp
184c7aebda8SAttilio RaoThe
185c7aebda8SAttilio Rao.Fn vm_page_assert_xbusied
186c7aebda8SAttilio Raofunction panics if
187c7aebda8SAttilio Rao.Fa m
188c7aebda8SAttilio Raois not exclusive busied.
189c7aebda8SAttilio Rao.Sh SEE ALSO
190c7aebda8SAttilio Rao.Xr vm_page_aflag 9 ,
191c7aebda8SAttilio Rao.Xr vm_page_alloc 9 ,
192c7aebda8SAttilio Rao.Xr vm_page_deactivate 9 ,
193c7aebda8SAttilio Rao.Xr vm_page_free 9 ,
194c7aebda8SAttilio Rao.Xr vm_page_grab 9 ,
195c7aebda8SAttilio Rao.Xr vm_page_insert 9 ,
196c7aebda8SAttilio Rao.Xr vm_page_lookup 9 ,
1971e9469d1SChristian Brueffer.Xr vm_page_rename 9 ,
1981e9469d1SChristian Brueffer.Xr VOP_GETPAGES 9
199