dpdk中有两种pool 来有限分配用户内存。分别是mbuf_user_pool_ops和mbuf_platform_pool_ops
当用户调用rte_mbuf_best_mempool_ops 来从pool中分配内存是,优先从mbuf_user_pool_ops 中分配,然后才是从
mbuf_platform_pool_ops 中分配。
具体分析如下:
const char * __rte_experimental
rte_mbuf_best_mempool_ops(void)
{
/* User defined mempool ops takes the priority */
#首先查找mbuf_user_pool_ops
const char *best_ops = rte_mbuf_user_mempool_ops();
if (best_ops)
return best_ops;
/* Next choice is platform configured mempool ops */
#其次查找mbuf_user_pool_ops
best_ops = rte_mbuf_platform_mempool_ops();
if (best_ops)
return best_ops;
/* Last choice is to use the compile time config pool */
最后才是使用 ring buffer #define RTE_MBUF_DEFAULT_MEMPOOL_OPS "ring_mp_mc"
return RTE_MBUF_DEFAULT_MEMPOOL_OPS;
}
我们以mbuf_user_pool_ops 为例看看
const char * __rte_experimental
rte_mbuf_user_mempool_ops(void)
{
const struct rte_memzone *mz;
#查找mbuf_user_pool_ops
mz = rte_memzone_lookup("mbuf_user_pool_ops");
if (mz == NULL)
#如果没有查找到,则直接返回internal_config.user_mbuf_pool_ops_name;
return rte_eal_mbuf_user_pool_ops();
#查找到后,返回这个pool的name
return mz->addr;
}
const struct rte_memzone *
rte_memzone_lookup(const char *name)
{
struct rte_mem_config *mcfg;
const struct rte_memzone *memzone = NULL;
#得到全局变量
mcfg = rte_eal_get_configuration()->mem_config;
锁保护
rte_rwlock_read_lock(&mcfg->mlock);
#开始查找这个mempool
memzone = memzone_lookup_thread_unsafe(name);
rte_rwlock_read_unlock(&mcfg->mlock);
return memzone;
}
static inline const struct rte_memzone *
memzone_lookup_thread_unsafe(const char *name)
{
const struct rte_mem_config *mcfg;
const struct rte_memzone *mz;
unsigned i = 0;
/* get pointer to global configuration */
#得到全局变量
mcfg = rte_eal_get_configuration()->mem_config;
/*
* the algorithm is not optimal (linear), but there are few
* zones and this function should be called at init only
*/
#遍历全局变量mcfg中的memzone,以本例中及时查找name为mbuf_user_pool_ops的memzone
for (i = 0; i < RTE_MAX_MEMZONE; i++) {
mz = &mcfg->memzone[i];
if (mz->addr != NULL && !strncmp(name, mz->name, RTE_MEMZONE_NAMESIZE))
return &mcfg->memzone[i];
}
return NULL;
}
mbuf_user_pool_ops和mbuf_platform_pool_ops
猜你喜欢
转载自blog.csdn.net/tiantao2012/article/details/80694504
今日推荐
周排行