FD.io VPP  v21.06-3-gbb25fbf28
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  */
clib_valloc_main_t
Definition: valloc.h:39
bitmap.h
clib.h
clib_valloc_init
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:128
clib_valloc_chunk_t::baseva
uword baseva
base VA for this chunk
Definition: valloc.h:32
clib_valloc_chunk_t::size
uword size
size in bytes of this chunk
Definition: valloc.h:33
clib_valloc_chunk_t::prev
u32 prev
previous chunk pool index
Definition: valloc.h:31
lock.h
clib_spinlock_s
Definition: lock.h:51
clib_valloc_chunk_t::next
u32 next
next chunk pool index
Definition: valloc.h:30
uword
u64 uword
Definition: types.h:112
pool.h
Fixed length block allocator. Pools are built from clib vectors and bitmaps. Use pools when repeatedl...
clib_valloc_main_t::first_index
u32 first_index
pool index of first chunk in list
Definition: valloc.h:45
clib_valloc_add_chunk
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
format_function_t
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
clib_valloc_alloc
uword clib_valloc_alloc(clib_valloc_main_t *vam, uword size, int os_out_of_memory_on_failure)
Allocate virtual space.
Definition: valloc.c:150
size
u32 size
Definition: vhost_user.h:125
format_valloc
format_function_t format_valloc
Definition: valloc.h:57
u32
unsigned int u32
Definition: types.h:88
clib_valloc_chunk_t::flags
uword flags
flags (free/busy)
Definition: valloc.h:34
clib_valloc_chunk_t
Definition: valloc.h:28
clib_valloc_main_t::flags
uword flags
flags
Definition: valloc.h:44
clib_valloc_free
uword clib_valloc_free(clib_valloc_main_t *vam, uword baseva)
Free virtual space.
Definition: valloc.c:227
hash.h
clib_valloc_main_t::chunks
clib_valloc_chunk_t * chunks
pool of virtual chunks
Definition: valloc.h:41
clib_valloc_main_t::chunk_index_by_baseva
uword * chunk_index_by_baseva
chunk by baseva hash
Definition: valloc.h:42
clib_valloc_main_t::lock
clib_spinlock_t lock
spinlock
Definition: valloc.h:43