/*
* mte_set_parent() - Set the parent node and encode the slot.
- * @node: The encoded maple node.
- * @parent: The encoded maple node that is the parent of @node.
- * @slot: The slot that @node resides in @parent.
+ * @enode: The encoded maple node.
+ * @parent: The encoded maple node that is the parent of @enode.
+ * @slot: The slot that @enode resides in @parent.
*
- * Type is encoded in the node->parent
+ * Type is encoded in the enode->parent
* bit 0: 1 = root, 0 otherwise
* bit 1: Reserved.
* bit 2: 0 = range 32, 1 = [a]range 64 | lowest bit of range_16's slot.
*
- * Slot number is encoded in the node->parent
+ * Slot number is encoded in the enode->parent
* range_32, slot number is encoded in bits 3-6
* [a]range_64, slot number is encoded in bits 3-6
*/
-static inline void mte_set_parent(struct maple_enode *node,
+static inline void mte_set_parent(struct maple_enode *enode,
const struct maple_enode *parent,
unsigned char slot)
{
val &= ~bitmask; // Remove any old slot number.
val |= (slot << slot_shift); // Set the slot.
val |= type;
- mte_to_node(node)->parent = ma_parent_ptr(val);
+ mte_to_node(enode)->parent = ma_parent_ptr(val);
}
-static inline unsigned int mte_parent_slot(const struct maple_enode *node)
+/*
+ * mte_parent_slot() - get the parent slot of @enode.
+ * @enode: The encoded maple node.
+ *
+ * Returns: The slot in the parent node where @enode resides.
+ */
+static inline unsigned int mte_parent_slot(const struct maple_enode *enode)
{
unsigned long bitmask = 0x7C;
- unsigned long val = (unsigned long) mte_to_node(node)->parent;
+ unsigned long val = (unsigned long) mte_to_node(enode)->parent;
unsigned long slot_shift = mte_parent_shift(val);
if (val & 1)
return (val & bitmask) >> slot_shift;
}
-
-static inline struct maple_node *mte_parent(const struct maple_enode *node)
+/*
+ * mte_parent() - Get the parent of @node.
+ * @node: The encoded maple node.
+ *
+ * Returns: The parent maple node.
+ */
+static inline struct maple_node *mte_parent(const struct maple_enode *enode)
{
unsigned long bitmask = 0x7F;
- return (void *)((unsigned long)(mte_to_node(node)->parent) & ~bitmask);
+ return (void *)((unsigned long)(mte_to_node(enode)->parent) & ~bitmask);
}
+/*
+ * mte_dead_node() - check if the @enode is dead.
+ * Returns: true if dead, false otherwise.
+ */
static inline bool mte_dead_node(const struct maple_enode *enode)
{
struct maple_node *parent, *node = mte_to_node(enode);
return (parent == node);
}
-static inline struct maple_node *mas_get_alloc(const struct ma_state *ms)
+/*
+ * mas_get_alloc() - Get the first allocated node.
+ * @mas: The maple state.
+ *
+ * The first allocated node may be used for accounting of many other nodes.
+ * Please see mas_alloc_cnt() and mas_next_alloc() for complete use.
+ *
+ * Returns: The first allocated node.
+ *
+ */
+static inline struct maple_node *mas_get_alloc(const struct ma_state *mas)
{
- return (struct maple_node *)((unsigned long)ms->alloc & ~0x7F);
+ return (struct maple_node *)((unsigned long)mas->alloc & ~0x7F);
}
+/*
+ * ma_get_node_alloc_cnt() - Get the number of allocations stored in this node.
+ * @node: The maple node
+ *
+ * Used to calculate the total allocated nodes in a maple state. See
+ * mas_alloc_cnt().
+ *
+ * Returns: The count of the allocated nodes stored in this nodes slots.
+ *
+ */
static inline int ma_get_node_alloc_cnt(const struct maple_node *node)
{
int ret = 1;
return ret;
}
-static inline int mas_get_alloc_cnt(const struct ma_state *mas)
+/*
+ * mas_alloc_cnt() - Get the number of nodes allocated in a maple state.
+ * @mas: The maple state
+ *
+ * Walks through the allocated nodes and returns the number allocated.
+ *
+ * Returns: The total number of nodes allocated
+ *
+ */
+static inline int mas_alloc_cnt(const struct ma_state *mas)
{
struct maple_node *node = mas_get_alloc(mas);
return ma_get_node_alloc_cnt(node);
}
+/*
+ * mas_set_alloc_req() - Set the requested number of allocations.
+ * @mas - the maple state
+ * @count - the number of allocations.
+ */
static inline void mas_set_alloc_req(struct ma_state *mas, int count)
{
mas->alloc = (struct maple_node *)((unsigned long)mas->alloc & ~0x7F);
mas->alloc = (struct maple_node *)((unsigned long)mas->alloc | count);
}
-static inline int mas_get_alloc_req(const struct ma_state *mas)
+/*
+ * mas_alloc_req() - get the requested number of allocations.
+ * Returns: The allocation request count.
+ */
+static inline int mas_alloc_req(const struct ma_state *mas)
{
return (int)(((unsigned long)mas->alloc & 0x7F));
}
+/*
+ * mas_offset() - get the offset into a given node (slot/pivot number)
+ * @mas: The maple state
+ *
+ * Returns: The offset into the @mas node of interest.
+ */
static inline int mas_offset(const struct ma_state *mas)
{
- return mas_get_alloc_req(mas);
+ return mas_alloc_req(mas);
}
static inline void mas_set_offset(struct ma_state *mas, int slot)
if (!ms->alloc)
return NULL;
- cnt = mas_get_alloc_cnt(ms);
+ cnt = mas_alloc_cnt(ms);
mn = mas_get_alloc(ms);
if (cnt == 1) {
ms->alloc = NULL;
int cnt;
memset(reuse, 0, sizeof(*reuse));
- cnt = mas_get_alloc_cnt(mas);
+ cnt = mas_alloc_cnt(mas);
if (cnt == 0) {
mas->alloc = reuse;
} else if (cnt <= MAPLE_NODE_SLOTS) {
smn = node->slot[(cnt/MAPLE_NODE_SLOTS) - 1];
smn->slot[cnt % MAPLE_NODE_SLOTS] = reuse;
}
- cnt = mas_get_alloc_cnt(mas);
+ cnt = mas_alloc_cnt(mas);
- BUG_ON(!mas_get_alloc_cnt(mas));
+ BUG_ON(!mas_alloc_cnt(mas));
}
static inline void mas_node_node(struct ma_state *ms, gfp_t gfp)
{
struct maple_node *mn, *smn;
- int req = mas_get_alloc_req(ms);
- int allocated = mas_get_alloc_cnt(ms);
+ int req = mas_alloc_req(ms);
+ int allocated = mas_alloc_cnt(ms);
int slot;
if (!req)
static inline struct maple_node *mas_node_cnt(struct ma_state *mas, int count)
{
- int allocated = mas_get_alloc_cnt(mas);
+ int allocated = mas_alloc_cnt(mas);
BUG_ON(count > 127);
if (allocated < count) {
struct maple_node *child;
struct maple_enode *oldchild, *echild;
unsigned char slot, end = mt_slot_count(mas->node);
- int allocated = mas_get_alloc_cnt(mas);
+ int allocated = mas_alloc_cnt(mas);
if (allocated < end) {
mas->span_enode = mas->node;
// request 3 nodes to be allocated.
mas_node_cnt(&mas, 3);
// Allocation request of 3.
- MT_BUG_ON(mt, mas_get_alloc_req(&mas) != 3);
+ MT_BUG_ON(mt, mas_alloc_req(&mas) != 3);
// Allocate failed.
MT_BUG_ON(mt, mas.node != MA_ERROR(-ENOMEM));
MT_BUG_ON(mt, !mas_nomem(&mas, GFP_KERNEL));
- MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 3);
+ MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 3);
mn = mas_get_alloc(&mas);
MT_BUG_ON(mt, mn == NULL);
MT_BUG_ON(mt, mn->slot[0] == NULL);
// Set allocation request to 1.
mas_set_alloc_req(&mas, 1);
// Check Allocation request of 1.
- MT_BUG_ON(mt, mas_get_alloc_req(&mas) != 1);
+ MT_BUG_ON(mt, mas_alloc_req(&mas) != 1);
mas_set_err(&mas, -ENOMEM);
// Validate allocation request.
MT_BUG_ON(mt, !mas_nomem(&mas, GFP_KERNEL));
MT_BUG_ON(mt, mn == NULL);
MT_BUG_ON(mt, mn->slot[0] != NULL);
MT_BUG_ON(mt, mn->slot[1] != NULL);
- MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 0);
+ MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 0);
ma_free_rcu(mn);
mas.node = MAS_START;
// Drop the lock and allocate 3 nodes.
mas_nomem(&mas, GFP_KERNEL);
// Ensure 3 are allocated.
- MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 3);
+ MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 3);
// Allocation request of 0.
- MT_BUG_ON(mt, mas_get_alloc_req(&mas) != 0);
+ MT_BUG_ON(mt, mas_alloc_req(&mas) != 0);
mn = mas.alloc;
MT_BUG_ON(mt, mn == NULL);
MT_BUG_ON(mt, mn->slot[0] == NULL);
MT_BUG_ON(mt, mn->slot[1] == NULL);
// Ensure we counted 3.
- MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 3);
+ MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 3);
// Free.
mas_nomem(&mas, GFP_KERNEL);
j++;
}
}
- MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 127);
+ MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 127);
mas_nomem(&mas, GFP_KERNEL); // Free.
- MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 0);
+ MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 0);
for (i = 1; i < 128; i++) {
mas_node_cnt(&mas, i); // Request
mas_nomem(&mas, GFP_KERNEL); // Fill request
- MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != i); // check request filled
+ MT_BUG_ON(mt, mas_alloc_cnt(&mas) != i); // check request filled
for (j = i; j > 0; j--) { //Free the requests
mn = mas_next_alloc(&mas); // get the next node.
MT_BUG_ON(mt, mn == NULL);
ma_free_rcu(mn);
}
- MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 0);
+ MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 0);
}
for (i = 1; i < 128; i++) {
MA_STATE(mas2, mt, 0, 0);
mas_node_cnt(&mas, i); // Request
mas_nomem(&mas, GFP_KERNEL); // Fill request
- MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != i); // check request filled
+ MT_BUG_ON(mt, mas_alloc_cnt(&mas) != i); // check request filled
for (j = 1; j <= i; j++) { // Move the allocations to mas2
mn = mas_next_alloc(&mas); // get the next node.
MT_BUG_ON(mt, mn == NULL);
mas_push_node(&mas2, (struct maple_enode *)mn);
- MT_BUG_ON(mt, mas_get_alloc_cnt(&mas2) != j);
+ MT_BUG_ON(mt, mas_alloc_cnt(&mas2) != j);
}
- MT_BUG_ON(mt, mas_get_alloc_cnt(&mas) != 0);
- MT_BUG_ON(mt, mas_get_alloc_cnt(&mas2) != i);
+ MT_BUG_ON(mt, mas_alloc_cnt(&mas) != 0);
+ MT_BUG_ON(mt, mas_alloc_cnt(&mas2) != i);
for (j = i; j > 0; j--) { //Free the requests
- MT_BUG_ON(mt, mas_get_alloc_cnt(&mas2) != j);
+ MT_BUG_ON(mt, mas_alloc_cnt(&mas2) != j);
mn = mas_next_alloc(&mas2); // get the next node.
MT_BUG_ON(mt, mn == NULL);
ma_free_rcu(mn);
}
- MT_BUG_ON(mt, mas_get_alloc_cnt(&mas2) != 0);
+ MT_BUG_ON(mt, mas_alloc_cnt(&mas2) != 0);
}
mtree_unlock(mt);