summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQiuwen Lu <[email protected]>2017-04-13 14:12:50 +0800
committerQiuwen Lu <[email protected]>2017-04-13 14:12:50 +0800
commit0cb791c987cac2de9dedb6539ecaa064397c9abe (patch)
treef5809e1fa4da2f51d455758448dd1e622e473551
parentfe4ae3dfa9dc810d08e1d9599d5d6eb22b6affed (diff)
增加内存池分配方式:单一内存池,避免在特定机型上NUMA内存不均衡带来的内存分配问题。v4.1.4-20170413
-rw-r--r--service/src/mrb.c52
1 files changed, 48 insertions, 4 deletions
diff --git a/service/src/mrb.c b/service/src/mrb.c
index c15f7ea..c73f4d1 100644
--- a/service/src/mrb.c
+++ b/service/src/mrb.c
@@ -26,10 +26,11 @@
enum mrb_create_mode
{
- MRB_POOL_CREATE_MODE_PER_PHYDEV = 0,
- MRB_POOL_CREATE_MODE_PER_SOCKET = 1,
- MRB_POOL_CREATE_MODE_PER_LCORE = 2,
- MRB_POOL_CREATE_MODE_USER = 3,
+ MRB_POOL_CREATE_MODE_PER_PHYDEV,
+ MRB_POOL_CREATE_MODE_PER_SOCKET,
+ MRB_POOL_CREATE_MODE_PER_LCORE,
+ MRB_POOL_CREATE_MODE_SINGLE,
+ MRB_POOL_CREATE_MODE_USER,
MRB_POOL_CREATE_MODE_MAX
};
@@ -264,6 +265,38 @@ struct rte_mempool * mrb_pool_adapter_locate_by_socket(struct mrb_pool_adapter *
return NULL;
}
+int mrb_pool_adapter_config_single(struct mrb_pool_adapter * adapter, struct mrb_main * ctx)
+{
+ struct mrb_pool * m_pool = ZMALLOC(sizeof(struct mrb_pool));
+ MR_VERIFY_MALLOC(m_pool);
+
+ m_pool->socket_id = SOCKET_ID_ANY;
+ m_pool->sz_direct_pktmbuf = ctx->sz_direct_pktmbuf;
+ m_pool->sz_indirect_pktmbuf = ctx->sz_indirect_pktmbuf;
+ m_pool->sz_cache = ctx->sz_cache;
+ m_pool->sz_data = ctx->sz_data;
+
+ snprintf(m_pool->symbol, sizeof(m_pool->symbol), "single");
+ TAILQ_INSERT_TAIL(&ctx->pool_list, m_pool, next);
+ return RT_SUCCESS;
+}
+
+struct rte_mempool * mrb_pool_adapter_locate_single(struct mrb_pool_adapter * adapter,
+ struct mrb_main * ctx, const char * symbol, unsigned int type, socket_id_t socket_id, cpu_id_t cpu_id)
+{
+ RTE_SET_USED(symbol);
+ RTE_SET_USED(cpu_id);
+ RTE_SET_USED(adapter);
+ RTE_SET_USED(socket_id);
+
+ if (__LOCATE_TYPE_DIRECT_POOL == type)
+ return TAILQ_FIRST(&ctx->pool_list)->direct;
+ if (__LOCATE_TYPE_INDIRECT_POOL == type)
+ return TAILQ_FIRST(&ctx->pool_list)->indirect;
+
+ return NULL;
+}
+
int mrb_pool_adapter_config_by_phydev(struct mrb_pool_adapter * adapter, struct mrb_main * ctx)
{
return 0;
@@ -281,6 +314,14 @@ int mrb_pool_adapter_config_by_user(struct mrb_pool_adapter * adapter, struct mr
return 0;
}
+static struct mrb_pool_adapter adapter_create_by_single =
+{
+ .create_mode = MRB_POOL_CREATE_MODE_SINGLE,
+ .fn_config = mrb_pool_adapter_config_single,
+ .fn_create_pool = mrb_pool_adapter_create_pool_common,
+ .fn_locate_pool = mrb_pool_adapter_locate_single
+};
+
static struct mrb_pool_adapter adapter_create_by_phydev =
{
.create_mode = MRB_POOL_CREATE_MODE_PER_PHYDEV,
@@ -390,6 +431,9 @@ int mrb_pool_config(struct sc_main * sc)
case MRB_POOL_CREATE_MODE_PER_LCORE:
ctx->adapter = &adapter_create_by_lcore;
break;
+ case MRB_POOL_CREATE_MODE_SINGLE:
+ ctx->adapter = &adapter_create_by_single;
+ break;
case MRB_POOL_CREATE_MODE_USER:
ctx->adapter = &adapter_create_by_user;
break;