FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
valloc.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef included_valloc_h
17 #define included_valloc_h
18 #include <vppinfra/clib.h>
19 #include <vppinfra/pool.h>
20 #include <vppinfra/bitmap.h>
21 #include <vppinfra/lock.h>
22 #include <vppinfra/hash.h>
23 
24 /** @file
25  @brief Simple first-fit virtual space allocator
26 */
27 
28 typedef struct
29 {
30  u32 next; /**< next chunk pool index */
31  u32 prev; /**< previous chunk pool index */
32  uword baseva; /**< base VA for this chunk */
33  uword size; /**< size in bytes of this chunk */
34  uword flags; /**< flags (free/busy) */
36 
37 #define CLIB_VALLOC_BUSY (1<<0) /**< chunk is in use */
38 
39 typedef struct
40 {
41  clib_valloc_chunk_t *chunks; /**< pool of virtual chunks */
42  uword *chunk_index_by_baseva; /**< chunk by baseva hash */
43  clib_spinlock_t lock; /**< spinlock */
44  uword flags; /**< flags */
45  u32 first_index; /**< pool index of first chunk in list */
47 
48 #define CLIB_VALLOC_INITIALIZED (1<<0) /**< object has been initialized */
49 
50 /* doxygen tags in valloc.c */
52  clib_valloc_chunk_t * template, int need_lock);
53 void
55  clib_valloc_chunk_t * template);
56 
58 
61  int os_out_of_memory_on_failure);
62 
63 #endif /* included_valloc_h */
64 
65 /*
66  * fd.io coding-style-patch-verification: ON
67  *
68  * Local Variables:
69  * eval: (c-set-style "gnu")
70  * End:
71  */
void clib_valloc_add_chunk(clib_valloc_main_t *vam, clib_valloc_chunk_t *template)
Add a chunk of memory to a virtual allocation arena.
Definition: valloc.c:33
uword clib_valloc_free(clib_valloc_main_t *vam, uword baseva)
Free virtual space.
Definition: valloc.c:228
uword clib_valloc_alloc(clib_valloc_main_t *vam, uword size, int os_out_of_memory_on_failure)
Allocate virtual space.
Definition: valloc.c:151
Fixed length block allocator.
uword flags
flags
Definition: valloc.h:44
clib_valloc_chunk_t * chunks
pool of virtual chunks
Definition: valloc.h:41
u32 first_index
pool index of first chunk in list
Definition: valloc.h:45
uword * chunk_index_by_baseva
chunk by baseva hash
Definition: valloc.h:42
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
unsigned int u32
Definition: types.h:88
uword size
uword flags
flags (free/busy)
Definition: valloc.h:34
void clib_valloc_init(clib_valloc_main_t *vam, clib_valloc_chunk_t *template, int need_lock)
Initialize a virtual memory allocation arena.
Definition: valloc.c:129
uword size
size in bytes of this chunk
Definition: valloc.h:33
u32 prev
previous chunk pool index
Definition: valloc.h:31
uword baseva
base VA for this chunk
Definition: valloc.h:32
clib_spinlock_t lock
spinlock
Definition: valloc.h:43
u32 next
next chunk pool index
Definition: valloc.h:30
Bitmaps built as vectors of machine words.
u64 uword
Definition: types.h:112
format_function_t format_valloc
Definition: valloc.h:57