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