linux kernel struct 之 idr

linux-4.9.37/include/linux/idr.h

映射唯一标识符(UID)到指针的数据结构。‌

/*
 * We want shallower trees and thus more bits covered at each layer.  8
 * bits gives us large enough first layer for most use cases and maximum
 * tree depth of 4.  Each idr_layer is slightly larger than 2k on 64bit and
 * 1k on 32bit.
 */
#define IDR_BITS 8
#define IDR_SIZE (1 << IDR_BITS)
#define IDR_MASK ((1 << IDR_BITS)-1)

struct idr_layer {
    int            prefix;    /* the ID prefix of this idr_layer */
    int            layer;    /* distance from leaf */
    struct idr_layer __rcu    *ary[1<<IDR_BITS];
    int            count;    /* When zero, we can release it */
    union {
        /* A zero bit means "space here" */
        DECLARE_BITMAP(bitmap, IDR_SIZE);
        struct rcu_head        rcu_head;
    };
};

struct idr {
    struct idr_layer __rcu    *hint;    /* the last layer allocated from */
    struct idr_layer __rcu    *top;
    int            layers;    /* only valid w/o concurrent changes */
    int            cur;    /* current pos for cyclic allocation */
    spinlock_t        lock;
    int            id_free_cnt;
    struct idr_layer    *id_free;
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值