From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Monjalon Subject: Re: [PATCH v2] eal: change default per socket memory allocation Date: Tue, 13 May 2014 18:27:07 +0200 Message-ID: <63642020.erThIODFlC@xps13> References: <1399642242-19725-1-git-send-email-david.marchand@6wind.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Cc: dev-VfR2kkLFssw@public.gmane.org To: venky.venkatesan-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org Return-path: In-Reply-To: <1399642242-19725-1-git-send-email-david.marchand-pdR9zngts4EAvxtiuMwx3w@public.gmane.org> 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" Hi Venky, There were comments on the first version of this patch and you suggeste= d to=20 try this new implementation. So do you acknowledge this patch? Thanks for your review 2014-05-09 15:30, David Marchand: > From: Didier Pallard >=20 > Currently, if there is more memory in hugepages than the amount > requested by dpdk application, the memory is allocated by taking as m= uch > 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 pe= r > socket), and dpdk is requesting only 4GB of memory, all memory will b= e > taken in socket 0 (that have exactly 4GB of free hugepages) even if s= ome > cores are configured on socket 1, and there are free hugepages on soc= ket > 1... >=20 > Change this behaviour to allocate memory on all sockets where some co= res > are configured, spreading the memory amongst sockets using following > ratio per socket: > N=B0 of cores configured on the socket / Total number of configured c= ores > * requested memory >=20 > 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. >=20 > Changes included in v2: > - only update linux implementation as bsd looks not to be ready for n= uma > - if new algorithm fails, then defaults to previous behaviour >=20 > Signed-off-by: Didier Pallard > Signed-off-by: David Marchand > --- > lib/librte_eal/linuxapp/eal/eal_memory.c | 50 > +++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 5 > deletions(-) >=20 > diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c > b/lib/librte_eal/linuxapp/eal/eal_memory.c index 73a6394..471dcfd 100= 644 > --- a/lib/librte_eal/linuxapp/eal/eal_memory.c > +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c > @@ -881,13 +881,53 @@ calc_num_pages_per_socket(uint64_t * memory, > =09if (num_hp_info =3D=3D 0) > =09=09return -1; >=20 > -=09for (socket =3D 0; socket < RTE_MAX_NUMA_NODES && total_mem !=3D = 0; socket++) > { -=09=09/* if specific memory amounts per socket weren't requested *= / > -=09=09if (internal_config.force_sockets =3D=3D 0) { > +=09/* if specific memory amounts per socket weren't requested */ > +=09if (internal_config.force_sockets =3D=3D 0) { > +=09=09int cpu_per_socket[RTE_MAX_NUMA_NODES]; > +=09=09size_t default_size, total_size; > +=09=09unsigned lcore_id; > + > +=09=09/* Compute number of cores per socket */ > +=09=09memset(cpu_per_socket, 0, sizeof(cpu_per_socket)); > +=09=09RTE_LCORE_FOREACH(lcore_id) { > +=09=09=09cpu_per_socket[rte_lcore_to_socket_id(lcore_id)]++; > +=09=09} > + > +=09=09/* > +=09=09 * Automatically spread requested memory amongst detected sock= ets > according +=09=09 * to number of cores from cpu mask present on each = socket > +=09=09 */ > +=09=09total_size =3D internal_config.memory; > +=09=09for (socket =3D 0; socket < RTE_MAX_NUMA_NODES && total_size != =3D 0; > socket++) { + > +=09=09=09/* Set memory amount per socket */ > +=09=09=09default_size =3D (internal_config.memory * cpu_per_socket[s= ocket]) > +=09=09=09 / rte_lcore_count(); > + > +=09=09=09/* Limit to maximum available memory on socket */ > +=09=09=09default_size =3D RTE_MIN(default_size,=20 get_socket_mem_size(socket)); > + > +=09=09=09/* Update sizes */ > +=09=09=09memory[socket] =3D default_size; > +=09=09=09total_size -=3D default_size; > +=09=09} > + > +=09=09/* > +=09=09 * If some memory is remaining, try to allocate it by getting = all > +=09=09 * available memory from sockets, one after the other > +=09=09 */ > +=09=09for (socket =3D 0; socket < RTE_MAX_NUMA_NODES && total_size != =3D 0; > socket++) { /* take whatever is available */ > -=09=09=09memory[socket] =3D RTE_MIN(get_socket_mem_size(socket), > -=09=09=09=09=09total_mem); > +=09=09=09default_size =3D RTE_MIN(get_socket_mem_size(socket) -=20 memory[socket], > +=09=09=09 total_size); > + > +=09=09=09/* Update sizes */ > +=09=09=09memory[socket] +=3D default_size; > +=09=09=09total_size -=3D default_size; > =09=09} > +=09} > + > +=09for (socket =3D 0; socket < RTE_MAX_NUMA_NODES && total_mem !=3D = 0; socket++) > { /* skips if the memory on specific socket wasn't requested */ > =09=09for (i =3D 0; i < num_hp_info && memory[socket] !=3D 0; i++){ > =09=09=09hp_used[i].hugedir =3D hp_info[i].hugedir;