xref: /freebsd/lib/libc/db/man/mpool.3 (revision 4b9d605768acabc460aa6dcfe8a1f8db35b16794)
1.\" Copyright (c) 1990, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd June 17, 2011
29.Dt MPOOL 3
30.Os
31.Sh NAME
32.Nm mpool
33.Nd "shared memory buffer pool"
34.Sh SYNOPSIS
35.In db.h
36.In mpool.h
37.Ft MPOOL *
38.Fn mpool_open "void *key" "int fd" "pgno_t pagesize" "pgno_t maxcache"
39.Ft void
40.Fo mpool_filter
41.Fa "MPOOL *mp"
42.Fa "void (*pgin)(void *, pgno_t, void *)"
43.Fa "void (*pgout)(void *, pgno_t, void *)"
44.Fa "void *pgcookie"
45.Fc
46.Ft void *
47.Fn mpool_new "MPOOL *mp" "pgno_t *pgnoaddr" "u_int flags"
48.Ft int
49.Fn mpool_delete "MPOOL *mp" "void *page"
50.Ft void *
51.Fn mpool_get "MPOOL *mp" "pgno_t pgno" "u_int flags"
52.Ft int
53.Fn mpool_put "MPOOL *mp" "void *pgaddr" "u_int flags"
54.Ft int
55.Fn mpool_sync "MPOOL *mp"
56.Ft int
57.Fn mpool_close "MPOOL *mp"
58.Sh DESCRIPTION
59The
60.Nm mpool
61library interface is intended to provide page oriented buffer management
62of files.
63.Pp
64The
65.Fn mpool_open
66function initializes a memory pool.
67The
68.Fa key
69argument is currently ignored.
70The
71.Fa fd
72argument is a file descriptor for the underlying file, which must be seekable.
73.Pp
74The
75.Fa pagesize
76argument is the size, in bytes, of the pages into which the file is broken up.
77The
78.Fa maxcache
79argument is the maximum number of pages from the underlying file to cache
80at any one time.
81This value is not relative to the number of processes which share a file's
82buffers, but will be the largest value specified by any of the processes
83sharing the file.
84.Pp
85The
86.Fn mpool_filter
87function is intended to make transparent input and output processing of the
88pages possible.
89If the
90.Fa pgin
91function is specified, it is called each time a buffer is read into the memory
92pool from the backing file.
93If the
94.Fa pgout
95function is specified, it is called each time a buffer is written into the
96backing file.
97Both functions are called with the
98.Fa pgcookie
99pointer, the page number and a pointer to the page to being read or written.
100.Pp
101The function
102.Fn mpool_new
103takes an
104.Dv MPOOL
105pointer, an address, and a set of flags as arguments.
106If a new page can be allocated, a pointer to the page is returned and
107the page number is stored into the
108.Fa pgnoaddr
109address.
110Otherwise,
111.Dv NULL
112is returned and
113.Va errno
114is set.
115The flags value is formed by
116.Tn OR Ns 'ing
117the following values:
118.Bl -tag -width Ds
119.It Dv MPOOL_PAGE_REQUEST
120Allocate a new page with a specific page number.
121.It Dv MPOOL_PAGE_NEXT
122Allocate a new page with the next page number.
123.El
124.Pp
125The function
126.Fn mpool_delete
127deletes the specified page from a pool and frees the page.
128It takes an
129.Dv MPOOL
130pointer and a page as arguments.
131The page must have been generated by
132.Fn mpool_new .
133.Pp
134The
135.Fn mpool_get
136function takes a
137.Ft MPOOL
138pointer and a page number as arguments.
139If the page exists, a pointer to the page is returned.
140Otherwise,
141.Dv NULL
142is returned and
143.Va errno
144is set.
145The
146.Fa flags
147argument is specified by
148.Em or Ns 'ing
149any of the following values:
150.Bl -tag -width indent
151.It Dv MPOOL_IGNOREPIN
152The page returned is not pinned;
153page will otherwise be pinned on return.
154.El
155.Pp
156The
157.Fn mpool_put
158function unpins the page referenced by
159.Fa pgaddr .
160The
161.Fa pgaddr
162argument
163must be an address previously returned by
164.Fn mpool_get
165or
166.Fn mpool_new .
167The
168.Fa flags
169argument is specified by
170.Em or Ns 'ing
171any of the following values:
172.Bl -tag -width indent
173.It Dv MPOOL_DIRTY
174The page has been modified and needs to be written to the backing file.
175.El
176.Pp
177The
178.Fn mpool_put
179function
180returns 0 on success and -1 if an error occurs.
181.Pp
182The
183.Fn mpool_sync
184function writes all modified pages associated with the
185.Ft MPOOL
186pointer to the
187backing file.
188The
189.Fn mpool_sync
190function
191returns 0 on success and -1 if an error occurs.
192.Pp
193The
194.Fn mpool_close
195function free's up any allocated memory associated with the memory pool
196cookie.
197Modified pages are
198.Em not
199written to the backing file.
200The
201.Fn mpool_close
202function
203returns 0 on success and -1 if an error occurs.
204.Sh ERRORS
205The
206.Fn mpool_open
207function may fail and set
208.Va errno
209for any of the errors specified for the library routine
210.Xr malloc 3 .
211.Pp
212The
213.Fn mpool_get
214function may fail and set
215.Va errno
216for the following:
217.Bl -tag -width Er
218.It Bq Er EINVAL
219The requested record does not exist.
220.El
221.Pp
222The
223.Fn mpool_new
224and
225.Fn mpool_get
226functions may fail and set
227.Va errno
228for any of the errors specified for the library routines
229.Xr read 2 ,
230.Xr write 2 ,
231and
232.Xr malloc 3 .
233.Pp
234The
235.Fn mpool_sync
236function may fail and set
237.Va errno
238for any of the errors specified for the library routine
239.Xr write 2 .
240.Pp
241The
242.Fn mpool_close
243function may fail and set
244.Va errno
245for any of the errors specified for the library routine
246.Xr free 3 .
247.Sh SEE ALSO
248.Xr btree 3 ,
249.Xr dbopen 3 ,
250.Xr hash 3 ,
251.Xr recno 3
252