]> git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/libpmemobj/alloc_class.h
import ceph 16.2.7
[ceph.git] / ceph / src / pmdk / src / libpmemobj / alloc_class.h
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright 2016-2020, Intel Corporation */
3
4 /*
5 * alloc_class.h -- internal definitions for allocation classes
6 */
7
8 #ifndef LIBPMEMOBJ_ALLOC_CLASS_H
9 #define LIBPMEMOBJ_ALLOC_CLASS_H 1
10
11 #include <stddef.h>
12 #include <stdint.h>
13 #include <sys/types.h>
14 #include "heap_layout.h"
15 #include "memblock.h"
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 #define MAX_ALLOCATION_CLASSES (UINT8_MAX)
22 #define DEFAULT_ALLOC_CLASS_ID (0)
23 #define RUN_UNIT_MAX RUN_BITS_PER_VALUE
24
25 struct alloc_class_collection;
26
27 enum alloc_class_type {
28 CLASS_UNKNOWN,
29 CLASS_HUGE,
30 CLASS_RUN,
31
32 MAX_ALLOC_CLASS_TYPES
33 };
34
35 struct alloc_class {
36 uint8_t id;
37 uint16_t flags;
38
39 size_t unit_size;
40
41 enum header_type header_type;
42 enum alloc_class_type type;
43
44 /* run-specific data */
45 struct run_descriptor rdsc;
46 };
47
48 struct alloc_class_collection *alloc_class_collection_new(void);
49 void alloc_class_collection_delete(struct alloc_class_collection *ac);
50
51 struct alloc_class *alloc_class_by_run(
52 struct alloc_class_collection *ac,
53 size_t unit_size, uint16_t flags, uint32_t size_idx);
54 struct alloc_class *alloc_class_by_alloc_size(
55 struct alloc_class_collection *ac, size_t size);
56 struct alloc_class *alloc_class_by_id(
57 struct alloc_class_collection *ac, uint8_t id);
58
59 int alloc_class_reserve(struct alloc_class_collection *ac, uint8_t id);
60 int alloc_class_find_first_free_slot(struct alloc_class_collection *ac,
61 uint8_t *slot);
62
63 ssize_t
64 alloc_class_calc_size_idx(struct alloc_class *c, size_t size);
65
66 struct alloc_class *
67 alloc_class_new(int id, struct alloc_class_collection *ac,
68 enum alloc_class_type type, enum header_type htype,
69 size_t unit_size, size_t alignment,
70 uint32_t size_idx);
71
72 void alloc_class_delete(struct alloc_class_collection *ac,
73 struct alloc_class *c);
74
75 #ifdef __cplusplus
76 }
77 #endif
78
79 #endif