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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
25 @brief Simple first-fit virtual space allocator
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) */
35 } clib_valloc_chunk_t;
37 #define CLIB_VALLOC_BUSY (1<<0) /**< chunk is in use */
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 */
48 #define CLIB_VALLOC_INITIALIZED (1<<0) /**< object has been initialized */
50 /* doxygen tags in valloc.c */
51 void clib_valloc_init (clib_valloc_main_t * vam,
52 clib_valloc_chunk_t * template, int need_lock);
54 clib_valloc_add_chunk (clib_valloc_main_t * vam,
55 clib_valloc_chunk_t * template);
57 format_function_t format_valloc;
59 uword clib_valloc_free (clib_valloc_main_t * vam, uword baseva);
60 uword clib_valloc_alloc (clib_valloc_main_t * vam, uword size,
61 int os_out_of_memory_on_failure);
63 #endif /* included_valloc_h */
66 * fd.io coding-style-patch-verification: ON
69 * eval: (c-set-style "gnu")