xref: /freebsd/share/man/man9/vm_page_busy.9 (revision 1e9469d188355e00de1c3811dd2f983d2f5a47d9)
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$
27c7aebda8SAttilio Rao.Dd August 07, 2013
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_sleep_if_busy ,
37c7aebda8SAttilio Rao.Nm vm_page_sunbusy ,
38c7aebda8SAttilio Rao.Nm vm_page_trysbusy ,
39c7aebda8SAttilio Rao.Nm vm_page_tryxbusy ,
40c7aebda8SAttilio Rao.Nm vm_page_xbusied ,
41c7aebda8SAttilio Rao.Nm vm_page_xbusy ,
42c7aebda8SAttilio Rao.Nm vm_page_xunbusy ,
43c7aebda8SAttilio Rao.Nm vm_page_assert_sbusied ,
44c7aebda8SAttilio Rao.Nm vm_page_assert_unbusied ,
45c7aebda8SAttilio Rao.Nm vm_page_assert_xbusied
46c7aebda8SAttilio Rao.Nd protect page identity changes and page content references
47c7aebda8SAttilio Rao.Sh SYNOPSIS
48c7aebda8SAttilio Rao.In sys/param.h
49c7aebda8SAttilio Rao.In vm/vm.h
50c7aebda8SAttilio Rao.In vm/vm_page.h
51c7aebda8SAttilio Rao.Ft int
52c7aebda8SAttilio Rao.Fn vm_page_busied "vm_page_t m"
53c7aebda8SAttilio Rao.Ft void
54c7aebda8SAttilio Rao.Fn vm_page_busy_downgrade "vm_page_t m"
55c7aebda8SAttilio Rao.Ft void
56c7aebda8SAttilio Rao.Fn vm_page_busy_sleep "vm_page_t m" "const char *msg"
57c7aebda8SAttilio Rao.Ft int
58c7aebda8SAttilio Rao.Fn vm_page_sbusied "vm_page_t m"
59c7aebda8SAttilio Rao.Ft void
60c7aebda8SAttilio Rao.Fn vm_page_sbusy "vm_page_t m"
61c7aebda8SAttilio Rao.Ft int
62c7aebda8SAttilio Rao.Fn vm_page_sleep_if_busy "vm_page_t m" "const char *msg"
63c7aebda8SAttilio Rao.Ft void
64c7aebda8SAttilio Rao.Fn vm_page_sunbusy "vm_page_t m"
65c7aebda8SAttilio Rao.Ft int
66c7aebda8SAttilio Rao.Fn vm_page_trysbusy "vm_page_t m"
67c7aebda8SAttilio Rao.Ft int
68c7aebda8SAttilio Rao.Fn vm_page_tryxbusy "vm_page_t m"
69c7aebda8SAttilio Rao.Ft int
70c7aebda8SAttilio Rao.Fn vm_page_xbusied "vm_page_t m"
71c7aebda8SAttilio Rao.Ft void
72c7aebda8SAttilio Rao.Fn vm_page_xbusy "vm_page_t m"
73c7aebda8SAttilio Rao.Ft void
74c7aebda8SAttilio Rao.Fn vm_page_xunbusy "vm_page_t m"
75c7aebda8SAttilio Rao.Pp
76c7aebda8SAttilio Rao.Cd "options INVARIANTS"
77c7aebda8SAttilio Rao.Cd "options INVARIANT_SUPPORT"
78c7aebda8SAttilio Rao.Ft void
79c7aebda8SAttilio Rao.Fn vm_page_assert_sbusied "vm_page_t m"
80c7aebda8SAttilio Rao.Ft void
81c7aebda8SAttilio Rao.Fn vm_page_assert_unbusied "vm_page_t m"
82c7aebda8SAttilio Rao.Ft void
83c7aebda8SAttilio Rao.Fn vm_page_assert_xbusied "vm_page_t m"
84c7aebda8SAttilio Rao.Sh DESCRIPTION
85c7aebda8SAttilio RaoPage identity is usually protected by higher level locks like vm_object
86c7aebda8SAttilio Raolocks and vm page locks.
87c7aebda8SAttilio RaoHowever, sometimes it is not possible to hold such locks for the time
88c7aebda8SAttilio Raonecessary to complete the identity change.
89c7aebda8SAttilio RaoIn such case the page can be exclusively busied by a thread which needs
90c7aebda8SAttilio Raoto own the identity for a certain amount of time.
91c7aebda8SAttilio Rao.Pp
92c7aebda8SAttilio RaoIn other situations, threads do not need to change the identity of the
93c7aebda8SAttilio Raopage but they want to prevent other threads from changing the identity
94c7aebda8SAttilio Raothemselves.
95c7aebda8SAttilio RaoFor example, when a thread wants to access or update page contents
96c7aebda8SAttilio Raowithout a lock held the page is shared busied.
97c7aebda8SAttilio Rao.Pp
98ebd88e49SJohn BaldwinBefore busying a page the vm_object lock must be held.
99c7aebda8SAttilio RaoThe same rule applies when a page is unbusied.
100c7aebda8SAttilio RaoThis makes the vm_object lock a real busy interlock.
101c7aebda8SAttilio Rao.Pp
102c7aebda8SAttilio RaoThe
103c7aebda8SAttilio Rao.Fn vm_page_busied
104c7aebda8SAttilio Raofunction returns non-zero if the current thread busied
105c7aebda8SAttilio Rao.Fa m
106c7aebda8SAttilio Raoin either exclusive or shared mode.
107c7aebda8SAttilio RaoReturns zero otherwise.
108c7aebda8SAttilio Rao.Pp
109c7aebda8SAttilio RaoThe
110c7aebda8SAttilio Rao.Fn vm_page_busy_downgrade
111c7aebda8SAttilio Raofunction must be used to downgrade
112c7aebda8SAttilio Rao.Fa m
113c7aebda8SAttilio Raofrom an exclusive busy state to a shared busy state.
114c7aebda8SAttilio Rao.Pp
115c7aebda8SAttilio RaoThe
116c7aebda8SAttilio Rao.Fn vm_page_busy_sleep
117c7aebda8SAttilio Raofunction puts the invoking thread to sleep using the appropriate
118c7aebda8SAttilio Raowaitchannels for the busy mechanism.
119c7aebda8SAttilio RaoThe parameter
120c7aebda8SAttilio Rao.Fa msg
121c7aebda8SAttilio Raois a string describing the sleep condition for userland tools.
122c7aebda8SAttilio Rao.Pp
123c7aebda8SAttilio RaoThe
124c7aebda8SAttilio Rao.Fn vm_page_busied
125c7aebda8SAttilio Raofunction returns non-zero if the current thread busied
126c7aebda8SAttilio Rao.Fa m
127c7aebda8SAttilio Raoin shared mode.
128c7aebda8SAttilio RaoReturns zero otherwise.
129c7aebda8SAttilio Rao.Pp
130c7aebda8SAttilio RaoThe
131c7aebda8SAttilio Rao.Fn vm_page_sbusy
132c7aebda8SAttilio Raofunction shared busies
133c7aebda8SAttilio Rao.Fa m .
134c7aebda8SAttilio Rao.Pp
135c7aebda8SAttilio RaoThe
136c7aebda8SAttilio Rao.Fn vm_page_sleep_if_busy
137c7aebda8SAttilio Raofunction puts the invoking thread to sleep, using the appropriate
138c7aebda8SAttilio Raowaitchannels for the busy mechanism, if
139c7aebda8SAttilio Rao.Fa m .
140c7aebda8SAttilio Raois busied in either exclusive or shared mode.
141c7aebda8SAttilio RaoIf the invoking thread slept a non-zero value is returned, otherwise
142c7aebda8SAttilio Rao0 is returned.
143c7aebda8SAttilio RaoThe parameter
144c7aebda8SAttilio Rao.Fa msg
145c7aebda8SAttilio Raois a string describing the sleep condition for userland tools.
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 ,
215*1e9469d1SChristian Brueffer.Xr vm_page_rename 9 ,
216*1e9469d1SChristian Brueffer.Xr VOP_GETPAGES 9
217