]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/lib/librte_acl/tb_mem.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
8 * Memory management routines for temporary memory.
9 * That memory is used only during build phase and is released after
11 * Note, that tb_pool/tb_alloc() are not supposed to return NULL.
12 * Instead, in the case of failure to allocate memory,
13 * it would do siglongjmp(pool->fail).
14 * It is responsibility of the caller to save the proper context/environment,
15 * in the pool->fail before calling tb_alloc() for the given pool first time.
18 static struct tb_mem_block
*
19 tb_pool(struct tb_mem_pool
*pool
, size_t sz
)
21 struct tb_mem_block
*block
;
25 size
= sz
+ pool
->alignment
- 1;
26 block
= calloc(1, size
+ sizeof(*pool
->block
));
28 RTE_LOG(ERR
, MALLOC
, "%s(%zu)\n failed, currently allocated "
29 "by pool: %zu bytes\n", __func__
, sz
, pool
->alloc
);
30 siglongjmp(pool
->fail
, -ENOMEM
);
36 block
->next
= pool
->block
;
41 ptr
= (uint8_t *)(block
+ 1);
42 block
->mem
= RTE_PTR_ALIGN_CEIL(ptr
, pool
->alignment
);
43 block
->size
= size
- (block
->mem
- ptr
);
49 tb_alloc(struct tb_mem_pool
*pool
, size_t size
)
51 struct tb_mem_block
*block
;
55 size
= RTE_ALIGN_CEIL(size
, pool
->alignment
);
58 if (block
== NULL
|| block
->size
< size
) {
59 new_sz
= (size
> pool
->min_alloc
) ? size
: pool
->min_alloc
;
60 block
= tb_pool(pool
, new_sz
);
69 tb_free_pool(struct tb_mem_pool
*pool
)
71 struct tb_mem_block
*next
, *block
;
73 for (block
= pool
->block
; block
!= NULL
; block
= next
) {