Motr
M0
|
Data Structures | |
struct | m0_varr_path_element |
struct | m0_varr_cursor |
struct | m0_varr |
Macros | |
#define | m0_varr_iter(arr, type, idx, obj, start, end, inc) |
#define | m0_varr_enditer } } ) |
#define | m0_varr_for(arr, type, idx, obj) |
#define | m0_varr_endfor m0_varr_enditer; }) |
Enumerations | |
enum | m0_varr_tree_char { M0_VA_TNODE_NR = 64, M0_VA_TNODEPTR_SIZE = sizeof(void *), M0_VA_TNODE_NR_SHIFT = 6, M0_VA_DEPTH_MAX = 16 } |
Functions | |
M0_BASSERT (M0_VA_TNODE_NR==M0_BITS(M0_VA_TNODE_NR_SHIFT)) | |
M0_INTERNAL int | m0_varr_init (struct m0_varr *arr, uint64_t nr, size_t size, size_t bufsize) |
M0_INTERNAL void | m0_varr_fini (struct m0_varr *arr) |
M0_INTERNAL void * | m0_varr_ele_get (struct m0_varr *arr, uint64_t index) |
M0_INTERNAL uint64_t | m0_varr_size (const struct m0_varr *arr) |
M0_INTERNAL int | m0_varr_cursor_init (struct m0_varr_cursor *cursor, const struct m0_varr *arr, uint32_t depth) |
M0_INTERNAL void * | m0_varr_cursor_get (struct m0_varr_cursor *cursor) |
M0_INTERNAL int | m0_varr_cursor_next (struct m0_varr_cursor *cursor) |
M0_INTERNAL int | m0_varr_cursor_move (struct m0_varr_cursor *cursor, uint64_t inc) |
A virtual array represents a data structure which can be used at places where big contiguous memory allocations are not possible.
Virtual array can be used for big arrays or pointers which would potentially hold large memory areas. Virtual array library provides interface for read, write, and iterate over an array.
Using such structures can be especially helpful in kernel where contiguity of pages is not guaranteed, and any memory allocation growing beyond page size can essentially fail. Current implementation supports both user-space as well as kernel versions.
The structure of virtual array is kept something similar to a block map from an on-disk inode with multiple indirections.
Using pointer arithmetic on virtual array is strongly discouraged since it does not guarantee contiguity of buffers.
A virtual array uses a radix-tree like structure whose height is dependent on number of objects to be accommodated in the array.
Following example illustrates the usage of various interfaces that are provided by virtual array library.
Consider an array consisting of OBJ_NR number of objects, of the type unsigned long. Library leaves it to its user what shall be the size of a buffer holding objects. Following example uses M0_0VEC_ALIGN as buffer size.
#define m0_varr_endfor m0_varr_enditer; }) |
Iterates over whole virtual array.
Iterates over an arbitrary arithmetic progression of indices over the range [start, end).
enum m0_varr_tree_char |
M0_BASSERT | ( | M0_VA_TNODE_NR | = =M0_BITS(M0_VA_TNODE_NR_SHIFT) | ) |
M0_INTERNAL void* m0_varr_cursor_get | ( | struct m0_varr_cursor * | cursor | ) |
Returns a pointer corresponding to the current location of a cursor.
Definition at line 316 of file varr.c.
M0_INTERNAL int m0_varr_cursor_init | ( | struct m0_varr_cursor * | cursor, |
const struct m0_varr * | arr, | ||
uint32_t | depth | ||
) |
Initializes a cursor to the address of the first node at given depth.
arr | [in] An array to which a cursor gets associated. |
depth | [in] Depth to which cursor is initialized. |
cursor | [out] |
0 | On success. |
-EINVAL | On failure. |
Definition at line 263 of file varr.c.
M0_INTERNAL int m0_varr_cursor_move | ( | struct m0_varr_cursor * | cursor, |
uint64_t | inc | ||
) |
Moves the cursor location by 'inc', along the same level as m0_varr_cursor::vc_depth.
1 | On success. |
0 | On completion of all nodes at level m0_varr_cursor::vc_depth. |
Definition at line 327 of file varr.c.
M0_INTERNAL int m0_varr_cursor_next | ( | struct m0_varr_cursor * | cursor | ) |
Moves cursor to the next node at the same level as m0_varr_cursor::vc_depth.
1 | On success. |
0 | On completion of all nodes at level m0_varr_cursor::vc_depth. |
Definition at line 322 of file varr.c.
M0_INTERNAL void* m0_varr_ele_get | ( | struct m0_varr * | arr, |
uint64_t | index | ||
) |
Returns address of an object having index as 'index'. Updates an internal cache if required. Since concurrent access to the cache may result in spurious outcome, calls to m0_varr_ele_get() should be protected under a lock.
Definition at line 505 of file varr.c.
M0_INTERNAL void m0_varr_fini | ( | struct m0_varr * | arr | ) |
M0_INTERNAL int m0_varr_init | ( | struct m0_varr * | arr, |
uint64_t | nr, | ||
size_t | size, | ||
size_t | bufsize | ||
) |
Initialises a virtual array.
nr[in] | Length of array. |
size[in] | Size of object to be stored in array. |
bufsize[in] | Size of each buffer which stores the objects. |
0 | On success. |
-ENOMEM | On failure. |
Definition at line 114 of file varr.c.