From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Marchand Subject: [PATCH RFC] eal: change default per socket memory allocation Date: Wed, 30 Apr 2014 16:15:04 +0200 Message-ID: <1398867304-21171-1-git-send-email-david.marchand@6wind.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable To: dev-VfR2kkLFssw@public.gmane.org Return-path: List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" From: Didier Pallard Currently, if there is more memory in hugepages than the amount requested by dpdk application, the memory is allocated by taking as much memory as possible from each socket, starting from first one. For example if a system is configured with 8 GB in 2 sockets (4 GB per socket), and dpdk is requesting only 4GB of memory, all memory will be taken in socket 0 (that have exactly 4GB of free hugepages) even if some cores are configured on socket 1, and there are free hugepages on socket 1... Change this behaviour to allocate memory on all sockets where some cores are configured, spreading the memory amongst sockets using following ratio per socket: N=C2=B0 of cores configured on the socket / Total number of configured co= res * requested memory This algorithm is used when memory amount is specified globally using -m option. Per socket memory allocation can always be done using --socket-mem option. Signed-off-by: Didier Pallard --- lib/librte_eal/bsdapp/eal/eal.c | 24 ++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal.c | 24 ++++++++++++++++++++++++ lib/librte_eal/linuxapp/eal/eal_memory.c | 8 ++++---- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/= eal.c index 5c181b3..b6b5f20 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -869,6 +869,30 @@ rte_eal_init(int argc, char **argv) internal_config.memory =3D eal_get_hugepage_mem_size(); } =20 + /* Automatically spread requested memory amongst detected sockets accor= ding */ + /* to number of cores from cpu mask present on each socket */ + if (internal_config.no_hugetlbfs =3D=3D 0 && + internal_config.process_type !=3D RTE_PROC_SECONDARY && + internal_config.xen_dom0_support =3D=3D 0 && + internal_config.force_sockets =3D=3D 0) { + int cpu_per_socket[RTE_MAX_NUMA_NODES]; + unsigned lcore_id, socket_id; + + /* Compute number of cores per socket */ + memset(cpu_per_socket, 0, sizeof(cpu_per_socket)); + RTE_LCORE_FOREACH(lcore_id) { + cpu_per_socket[rte_lcore_to_socket_id(lcore_id)]++; + } + + /* Set memory amount per socket; round up to be sure that sum of all *= / + /* sockets allocation is greater than requested memory size */ + for (socket_id=3D0 ; socket_id 0; socket= ++) { /* if specific memory amounts per socket weren't requested */ - if (internal_config.force_sockets =3D=3D 0) { + if (internal_config.force_sockets =3D=3D 0 && memory[socket] =3D=3D 0)= { /* take whatever is available */ - memory[socket] =3D RTE_MIN(get_socket_mem_size(socket), + memory[socket] =3D RTE_MIN((int64_t) get_socket_mem_size(socket), total_mem); } /* skips if the memory on specific socket wasn't requested */ --=20 1.7.10.4