xref: /freebsd/share/man/man9/VOP_GETPAGES.9 (revision 4b9d6057)
1.\" -*- nroff -*-
2.\"
3.\" Copyright (c) 1996 Doug Rabson
4.\" Copyright 2003, Garrett A. Wollman
5.\"
6.\" All rights reserved.
7.\"
8.\" This program is free software.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
20.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
23.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd June 29, 2019
31.Dt VOP_GETPAGES 9
32.Os
33.Sh NAME
34.Nm VOP_GETPAGES ,
35.Nm VOP_PUTPAGES
36.Nd read or write VM pages from a file
37.Sh SYNOPSIS
38.In sys/param.h
39.In sys/vnode.h
40.In vm/vm.h
41.Ft int
42.Fo VOP_GETPAGES
43.Fa "struct vnode *vp"
44.Fa "vm_page_t *ma"
45.Fa "int count"
46.Fa "int *rbehind"
47.Fa "int *rahead"
48.Fc
49.Ft int
50.Fo VOP_PUTPAGES
51.Fa "struct vnode *vp"
52.Fa "vm_page_t *ma"
53.Fa "int bytecount"
54.Fa "int flags"
55.Fa "int *rtvals"
56.Fc
57.Sh DESCRIPTION
58The
59.Fn VOP_GETPAGES
60method is called to read in pages of virtual memory which are backed by
61ordinary files.
62If other adjacent pages are backed by adjacent regions of the same file,
63.Fn VOP_GETPAGES
64is requested to read those pages as well, although it is not required to
65do so.
66The
67.Fn VOP_PUTPAGES
68method does the converse; that is to say, it writes out adjacent dirty
69pages of virtual memory.
70.Pp
71On entry, the vnode lock is held but neither the page queue nor VM object
72locks are held.
73Both methods return in the same state on both success and error returns.
74.Pp
75The arguments are:
76.Bl -tag -width rbehind
77.It Fa vp
78The file to access.
79.It Fa ma
80Pointer to the first element of an array of pages representing a
81contiguous region of the file to be read or written.
82.It Fa count
83The length of the
84.Fa ma
85array.
86.It Fa bytecount
87The number of bytes that should be written from the pages of the array.
88.It Fa flags
89A bitfield of flags affecting the function operation.
90If
91.Dv VM_PAGER_PUT_SYNC
92is set, the write should be synchronous; control must not be returned
93to the caller until after the write is finished.
94If
95.Dv VM_PAGER_PUT_INVAL
96is set, the pages are to be invalidated after being written.
97If
98.Dv VM_PAGER_PUT_NOREUSE
99is set, the I/O performed should set the IO_NOREUSE flag, to indicate
100to the filesystem that pages should be marked for fast reuse if needed.
101This could occur via a call to
102.Xr vm_page_deactivate_noreuse 9 ,
103which puts such pages onto the head of the inactive queue.
104If
105.Dv VM_PAGER_CLUSTER_OK
106is set, writes may be delayed, so that related writes
107can be coalesced for efficiency, e.g.,
108using the clustering mechanism of the buffer cache.
109.It Fa rtvals
110An array of VM system result codes indicating the status of each
111page written by
112.Fn VOP_PUTPAGES .
113.It Fa rbehind
114Optional pointer to integer specifying number of pages to be read behind, if
115possible.
116If the filesystem supports that feature, number of actually read pages is
117reported back, otherwise zero is returned.
118.It Fa rahead
119Optional pointer to integer specifying number of pages to be read ahead, if
120possible.
121If the filesystem supports that feature, number of actually read pages is
122reported back, otherwise zero is returned.
123.El
124.Pp
125The status of the
126.Fn VOP_PUTPAGES
127method is returned on a page-by-page basis in the array
128.Fa rtvals[] .
129The possible status values are as follows:
130.Bl -tag -width VM_PAGER_ERROR
131.It Dv VM_PAGER_OK
132The page was successfully written.
133The implementation must call
134.Xr vm_page_undirty 9
135to mark the page as clean.
136.It Dv VM_PAGER_PEND
137The page was scheduled to be written asynchronously.
138When the write completes, the completion callback should
139call
140.Xr vm_object_pip_wakeup 9
141and
142.Xr vm_page_sunbusy 9
143to clear the busy flag and awaken any other threads waiting for this page,
144in addition to calling
145.Xr vm_page_undirty 9 .
146.It Dv VM_PAGER_BAD
147The page was entirely beyond the end of the backing file.
148This condition should not be possible if the vnode's file system
149is correctly implemented.
150.It Dv VM_PAGER_ERROR
151The page could not be written because of an error on the underlying storage
152medium or protocol.
153.It Dv VM_PAGER_FAIL
154Treated identically to
155.Dv VM_PAGER_ERROR .
156.It Dv VM_PAGER_AGAIN
157The page was not handled by this request.
158.El
159.Pp
160The
161.Fn VOP_GETPAGES
162method must populate and validate all requested pages in order to
163return success.
164It is expected to release any pages in
165.Fa ma
166that it does not successfully handle, by calling
167.Xr vm_page_free 9 .
168When it succeeds,
169.Fn VOP_GETPAGES
170must set the valid bits appropriately.
171Upon entry to
172.Fn VOP_GETPAGES ,
173all pages in
174.Fa ma
175are busied exclusively.
176Upon successful return, the pages must all be busied exclusively
177as well, but pages may be unbusied during processing.
178The filesystem is responsible for activating paged-out pages, but this
179does not necessarily need to be done within
180.Fn VOP_GETPAGES
181depending on the architecture of the particular filesystem.
182.Sh RETURN VALUES
183If it successfully reads all pages in
184.Fa ma ,
185.Fn VOP_GETPAGES
186returns
187.Dv VM_PAGER_OK ;
188otherwise, it returns
189.Dv VM_PAGER_ERROR .
190By convention, the return value of
191.Fn VOP_PUTPAGES
192is
193.Fa rtvals[0] .
194.Sh SEE ALSO
195.Xr vm_object_pip_wakeup 9 ,
196.Xr vm_page_free 9 ,
197.Xr vm_page_sunbusy 9 ,
198.Xr vm_page_undirty 9 ,
199.Xr vm_page_xunbusy 9 ,
200.Xr vnode 9
201.Sh AUTHORS
202This manual page was written by
203.An Doug Rabson
204and then substantially rewritten by
205.An Garrett Wollman .
206