root / lab4 / .minix-src / include / ddekit / memory.h @ 14
History | View | Annotate | Download (4.4 KB)
1 |
/*-
|
---|---|
2 |
* Copyright (c) 2006 Thomas Friebel <tf13@os.inf.tu-dresden.de>
|
3 |
* Copyright (c) 2006 Christian Helmuth <ch12@os.inf.tu-dresden.de>
|
4 |
* Copyright (c) 2010 Dirk Vogt <dvogt@few.vu.nl>.
|
5 |
* All rights reserved.
|
6 |
*
|
7 |
* Redistribution and use in source and binary forms, with or without
|
8 |
* modification, are permitted provided that the following conditions
|
9 |
* are met:
|
10 |
*
|
11 |
* 1. Redistributions of source code must retain the above copyright
|
12 |
* notice, this list of conditions and the following disclaimer.
|
13 |
* 2. Redistributions in binary form must reproduce the above copyright
|
14 |
* notice, this list of conditions and the following disclaimer in
|
15 |
* the documentation and/or other materials provided with the
|
16 |
* distribution.
|
17 |
*
|
18 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19 |
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
21 |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22 |
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
23 |
* INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
24 |
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
25 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
26 |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
27 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
28 |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
29 |
* SUCH DAMAGE.
|
30 |
*/
|
31 |
#ifndef _DDEKIT_MEMORY_H
|
32 |
#define _DDEKIT_MEMORY_H
|
33 |
|
34 |
#include <ddekit/ddekit.h> |
35 |
|
36 |
/*******************
|
37 |
** Slab facility **
|
38 |
*******************/
|
39 |
|
40 |
struct ddekit_slab;
|
41 |
|
42 |
/* Store user pointer in slab cache */
|
43 |
void ddekit_slab_set_data(struct ddekit_slab * slab, void *data); |
44 |
|
45 |
/* Read user pointer from slab cache */
|
46 |
void *ddekit_slab_get_data(struct ddekit_slab * slab); |
47 |
|
48 |
/* Allocate slab in slab cache */
|
49 |
void *ddekit_slab_alloc(struct ddekit_slab * slab); |
50 |
|
51 |
/* Allocate slab in slab cache */
|
52 |
void ddekit_slab_free(struct ddekit_slab * slab, void *objp); |
53 |
|
54 |
/*
|
55 |
* Setup page cache for all slabs
|
56 |
*
|
57 |
* pages: maximal number of memory pages
|
58 |
*
|
59 |
* If 'pages' is too low, memory pages may be given back to the memory server
|
60 |
* (dm_phys) and just to be allocated again later. This hits performance (but
|
61 |
* saves memory). Increase 'pages' to avoid this thrashing-like effect.
|
62 |
*
|
63 |
* If the maximal number of unused pages is exceeded, subsequent deallocation
|
64 |
* will be freed at the memory server. This page cache caches pages from all
|
65 |
* slabs.
|
66 |
*/
|
67 |
void ddekit_slab_setup_page_cache(unsigned pages); |
68 |
|
69 |
/*
|
70 |
* Destroy slab cache
|
71 |
*
|
72 |
* slab: pointer to slab cache structure
|
73 |
*/
|
74 |
void ddekit_slab_destroy(struct ddekit_slab * slab); |
75 |
|
76 |
/**
|
77 |
* Initialize slab cache
|
78 |
*
|
79 |
* \param size size of cache objects
|
80 |
* \param contiguous make this slab use physically contiguous memory
|
81 |
*
|
82 |
* \return pointer to new slab cache or 0 on error
|
83 |
*/
|
84 |
struct ddekit_slab * ddekit_slab_init(unsigned size, int contiguous); |
85 |
|
86 |
|
87 |
/**********************
|
88 |
** Memory allocator **
|
89 |
**********************/
|
90 |
|
91 |
/*
|
92 |
* Allocate large memory block
|
93 |
*
|
94 |
* \param size block size
|
95 |
* \return pointer to new memory block
|
96 |
*
|
97 |
* Allocations via this allocator may be slow (because memory servers are
|
98 |
* involved) and should be used only for large (i.e., > page size) blocks. If
|
99 |
* allocations/deallocations are relatively dynamic this may not be what you
|
100 |
* want.
|
101 |
*
|
102 |
* Allocated blocks have valid virt->phys mappings and are physically
|
103 |
* contiguous.
|
104 |
*/
|
105 |
void *ddekit_large_malloc(int size); |
106 |
|
107 |
/**
|
108 |
* Free large memory block
|
109 |
*
|
110 |
* \param p pointer to memory block
|
111 |
*/
|
112 |
void ddekit_large_free(void *p); |
113 |
|
114 |
/** FIXME
|
115 |
* contig_malloc() is the lowest-level allocator interface one could implement.
|
116 |
* we should consider to provide vmalloc() too. */
|
117 |
void *ddekit_contig_malloc(unsigned long size, unsigned long low, |
118 |
unsigned long high, unsigned long alignment, unsigned long boundary); |
119 |
|
120 |
|
121 |
/*****************************
|
122 |
** Simple memory allocator **
|
123 |
*****************************/
|
124 |
|
125 |
/**
|
126 |
* Allocate memory block via simple allocator
|
127 |
*
|
128 |
* \param size block size
|
129 |
* \return pointer to new memory block
|
130 |
*
|
131 |
* The blocks allocated via this allocator CANNOT be used for DMA or other
|
132 |
* device operations, i.e., there exists no virt->phys mapping.
|
133 |
*/
|
134 |
void *ddekit_simple_malloc(unsigned size); |
135 |
|
136 |
/**
|
137 |
* Free memory block via simple allocator
|
138 |
*
|
139 |
* \param p pointer to memory block
|
140 |
*/
|
141 |
void ddekit_simple_free(void *p); |
142 |
|
143 |
#endif
|