> -----Original Message----- > Subject: Re: [PATCH v4] lib: set/get max memzone segments > > On 5/24/2023 11:25 PM, Ophir Munk wrote: > > Currently, the max memzones count constat (RTE_MAX_MEMZONE) is used > to > > decide how many memzones a DPDK application can have. This value could > > technically be changed by manually editing `rte_config.h` before > > compilation, but if DPDK is already compiled, that option is not useful. > > There are certain use cases that would benefit from making this value > > configurable. > > > > This commit addresses the issue by adding a new API to set the max > > number of memzones before EAL initialization (while using the old > > constant as default value), as well as an API to get current maximum > > number of memzones. > > > > Signed-off-by: Ophir Munk <ophi...@nvidia.com> > > Acked-by: Morten Brørup <m...@smartsharesystems.com> > > --- > > > + > > +int > > +rte_memzone_max_set(size_t max) > > +{ > > + struct rte_mem_config *mcfg; > > + > > + if (eal_get_internal_configuration()->init_complete > 0) > > + return -1; > > + > > + mcfg = rte_eal_get_configuration()->mem_config; > > + if (!mcfg) > > + return -1; > > + > > + mcfg->max_memzone = max; > > + > > + return 0; > > +} > > Would this even work?
Yes. It's working. I successfully ran the following test: int max = rte_memzone_max_get(); printf("Max memzone before eal_init: %d\n", max); // Printing the default max value of 2560 rte_memzone_max_set(1000); max = rte_memzone_max_get(); printf("Max memzone before eal_init after set to 1000: %d\n", max); // Printing the new max value of 1000 rte_eal_init(argc, argv); rte_memzone_max_set(2000); // Here we fail with -1 since we set after eal init max = rte_memzone_max_get(); printf("Max memzone after eal_init and after set to 2000: %d\n", max); // Printing the correct max value of 1000 > AFAIR mem_config is only available some time during > EAL init, not before (mem_config pointer will be NULL at that point). > Please note that DPDK supports early memory config (lib/eal/common/eal_common_config.c): /* early configuration structure, when memory config is not mmapped */ static struct rte_mem_config early_mem_config; So max memzone is saved in the early memory and later this memory becomes mapped (shared). Having said that - I think the current patch is correct. Please confirm. > I suggest the following flow: > > set(): > > if init_complete => return -1 Also if mem_config is NULL => return -1 > else => set local static value > > get(): > > if init_complete => return memzones.count else => return local static value > (set > to our default) > > That way we don't actually need the memconfig, and multiprocess will work > because memzones.count is shared between primary and secondary anyway. > > -- > Thanks, > Anatoly