No empty .Rs/.Re
[netbsd-mini2440.git] / sys / fs / tmpfs / tmpfs_pool.h
blobbd8be3c52b9e51aa9bde25c182009fb92f9b0f01
1 /* $NetBSD: tmpfs_pool.h,v 1.6 2006/11/09 16:20:56 jmmv Exp $ */
3 /*
4 * Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Julio M. Merino Vidal, developed as part of Google's Summer of Code
9 * 2005 program.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
33 #ifndef _FS_TMPFS_TMPFS_POOL_H_
34 #define _FS_TMPFS_TMPFS_POOL_H_
37 /* --------------------------------------------------------------------- */
40 * tmpfs_pool is an extension of regular system pools to also hold data
41 * specific to tmpfs. More specifically, we want a pointer to the
42 * tmpfs_mount structure using the pool so that we can update its memory
43 * usage statistics.
45 struct tmpfs_pool {
46 struct pool tp_pool;
48 /* Reference to the mount point that holds the pool. This is used
49 * by the tmpfs_pool_allocator to access and modify the memory
50 * accounting variables for the mount point. */
51 struct tmpfs_mount * tp_mount;
53 /* The pool's name. Used as the wait channel. */
54 char tp_name[64];
57 /* --------------------------------------------------------------------- */
60 * tmpfs uses variable-length strings to store file names and to store
61 * link targets. Reserving a fixed-size buffer for each of them is
62 * inefficient because it will consume a lot more memory than is really
63 * necessary. However, managing variable-sized buffers is difficult as
64 * regards memory allocation and very inefficient in computation time.
65 * This is why tmpfs provides an hybrid scheme to store strings: string
66 * pools.
68 * A string pool is a collection of memory pools, each one with elements
69 * of a fixed size. In tmpfs's case, a string pool contains independent
70 * memory pools for 16-byte, 32-byte, 64-byte, 128-byte, 256-byte,
71 * 512-byte and 1024-byte long objects. Whenever an object is requested
72 * from the pool, the new object's size is rounded to the closest upper
73 * match and an item from the corresponding pool is returned.
75 struct tmpfs_str_pool {
76 struct tmpfs_pool tsp_pool_16;
77 struct tmpfs_pool tsp_pool_32;
78 struct tmpfs_pool tsp_pool_64;
79 struct tmpfs_pool tsp_pool_128;
80 struct tmpfs_pool tsp_pool_256;
81 struct tmpfs_pool tsp_pool_512;
82 struct tmpfs_pool tsp_pool_1024;
85 /* --------------------------------------------------------------------- */
86 #ifdef _KERNEL
89 * Convenience functions and macros to manipulate a tmpfs_pool.
92 void tmpfs_pool_init(struct tmpfs_pool *tpp, size_t size,
93 const char *what, struct tmpfs_mount *tmp);
94 void tmpfs_pool_destroy(struct tmpfs_pool *tpp);
96 #define TMPFS_POOL_GET(tpp, flags) pool_get((struct pool *)(tpp), flags)
97 #define TMPFS_POOL_PUT(tpp, v) pool_put((struct pool *)(tpp), v)
99 /* --------------------------------------------------------------------- */
102 * Functions to manipulate a tmpfs_str_pool.
105 void tmpfs_str_pool_init(struct tmpfs_str_pool *, struct tmpfs_mount *);
106 void tmpfs_str_pool_destroy(struct tmpfs_str_pool *);
107 char * tmpfs_str_pool_get(struct tmpfs_str_pool *, size_t, int);
108 void tmpfs_str_pool_put(struct tmpfs_str_pool *, char *, size_t);
110 #endif
112 #endif /* _FS_TMPFS_TMPFS_POOL_H_ */