[v5,1/1] fbarray: fix duplicated fbarray file in secondary

Message ID 20191028080745.43425-2-yasufum.o@gmail.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series fbarray: fix duplicated fbarray file in secondary |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/travis-robot success Travis build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-compilation success Compile Testing PASS
ci/Intel-compilation fail Compilation issues
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Yasufumi Ogawa Oct. 28, 2019, 8:07 a.m. UTC
  From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>

In secondary_msl_create_walk(), it creates a file for fbarrays with its
PID for reserving unique name among secondary processes. However, it
does not work if several secondaries run as app containers because each
of containerized secondary has PID 1, and failed to reserve unique name
other than first one. To reserve unique name in each of containers, use
hostname instead of PID only if PID is 1.

Cc: stable@dpdk.org

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 lib/librte_eal/linux/eal/eal_memalloc.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
  

Comments

Ananyev, Konstantin Oct. 29, 2019, 12:03 p.m. UTC | #1
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of yasufum.o@gmail.com
> Sent: Monday, October 28, 2019 8:08 AM
> To: Burakov, Anatoly <anatoly.burakov@intel.com>; david.marchand@redhat.com
> Cc: dev@dpdk.org; stable@dpdk.org; yasufum.o@gmail.com; Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
> Subject: [dpdk-dev] [PATCH v5 1/1] fbarray: fix duplicated fbarray file in secondary
> 
> From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
> 
> In secondary_msl_create_walk(), it creates a file for fbarrays with its
> PID for reserving unique name among secondary processes. However, it
> does not work if several secondaries run as app containers because each
> of containerized secondary has PID 1, and failed to reserve unique name
> other than first one. To reserve unique name in each of containers, use
> hostname instead of PID only if PID is 1.
> 
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
> ---
>  lib/librte_eal/linux/eal/eal_memalloc.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/librte_eal/linux/eal/eal_memalloc.c b/lib/librte_eal/linux/eal/eal_memalloc.c
> index af6d0d023..699079791 100644
> --- a/lib/librte_eal/linux/eal/eal_memalloc.c
> +++ b/lib/librte_eal/linux/eal/eal_memalloc.c
> @@ -1365,6 +1365,7 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl,
>  	struct rte_memseg_list *primary_msl, *local_msl;
>  	char name[PATH_MAX];
>  	int msl_idx, ret;
> +	char proc_id[HOST_NAME_MAX] = { 0 };
> 
>  	if (msl->external)
>  		return 0;
> @@ -1374,8 +1375,18 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl,
>  	local_msl = &local_memsegs[msl_idx];
> 
>  	/* create distinct fbarrays for each secondary */
> -	snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i",
> -		primary_msl->memseg_arr.name, getpid());
> +	/* If run secondary in a container, the name of fbarray file should
> +	 * not be decided with pid because getpid() always returns 1.


I wonder why is that?
What will prevent user to do something like:
docker run -it --cpuset-cpus=7-8 -v /local/kananye1:/local/kananye1 ubuntu-dpdk-local:latest /bin/bash
And then start dpdk app manually within the container?
 
> +	 * In docker, hostname is assigned as a short form of full container
> +	 * ID. So use hostname as unique ID among containers instead.
> +	 */
> +	if (getpid() == 1)
> +		gethostname(proc_id, HOST_NAME_MAX);
> +	else
> +		sprintf(proc_id, "%d", (int)getpid());
> +
> +	snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%s",
> +			primary_msl->memseg_arr.name, proc_id);
> 
>  	ret = rte_fbarray_init(&local_msl->memseg_arr, name,
>  		primary_msl->memseg_arr.len,
> --
> 2.17.1
  
Yasufumi Ogawa Oct. 30, 2019, 1:42 p.m. UTC | #2
On 2019/10/29 21:03, Ananyev, Konstantin wrote:
> 
> 
>> -----Original Message-----
>> From: dev <dev-bounces@dpdk.org> On Behalf Of yasufum.o@gmail.com
>> Sent: Monday, October 28, 2019 8:08 AM
>> To: Burakov, Anatoly <anatoly.burakov@intel.com>; david.marchand@redhat.com
>> Cc: dev@dpdk.org; stable@dpdk.org; yasufum.o@gmail.com; Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
>> Subject: [dpdk-dev] [PATCH v5 1/1] fbarray: fix duplicated fbarray file in secondary
>>
>> From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
>>
>> In secondary_msl_create_walk(), it creates a file for fbarrays with its
>> PID for reserving unique name among secondary processes. However, it
>> does not work if several secondaries run as app containers because each
>> of containerized secondary has PID 1, and failed to reserve unique name
>> other than first one. To reserve unique name in each of containers, use
>> hostname instead of PID only if PID is 1.
>>
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
>> ---
>>   lib/librte_eal/linux/eal/eal_memalloc.c | 15 +++++++++++++--
>>   1 file changed, 13 insertions(+), 2 deletions(-)
>>
>> diff --git a/lib/librte_eal/linux/eal/eal_memalloc.c b/lib/librte_eal/linux/eal/eal_memalloc.c
>> index af6d0d023..699079791 100644
>> --- a/lib/librte_eal/linux/eal/eal_memalloc.c
>> +++ b/lib/librte_eal/linux/eal/eal_memalloc.c
>> @@ -1365,6 +1365,7 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl,
>>   	struct rte_memseg_list *primary_msl, *local_msl;
>>   	char name[PATH_MAX];
>>   	int msl_idx, ret;
>> +	char proc_id[HOST_NAME_MAX] = { 0 };
>>
>>   	if (msl->external)
>>   		return 0;
>> @@ -1374,8 +1375,18 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl,
>>   	local_msl = &local_memsegs[msl_idx];
>>
>>   	/* create distinct fbarrays for each secondary */
>> -	snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i",
>> -		primary_msl->memseg_arr.name, getpid());
>> +	/* If run secondary in a container, the name of fbarray file should
>> +	 * not be decided with pid because getpid() always returns 1.
> 
> 
> I wonder why is that?
> What will prevent user to do something like:
> docker run -it --cpuset-cpus=7-8 -v /local/kananye1:/local/kananye1 ubuntu-dpdk-local:latest /bin/bash
> And then start dpdk app manually within the container?
Hi Konstantin,

Thank you for your comment.

My concern is running secondary as app container. In current 
implementation, the name of fbarray file is decided by using PID and it 
must be overlapped with other process because assigning PID is started 
from 1 in each of app container. This patch is to fix the issue.

I think it is doable running app from bash for testing, but not 
acceptable for a realistic usecase in which user manages several app 
containers.

Regards,
Yasufumi

>   
>> +	 * In docker, hostname is assigned as a short form of full container
>> +	 * ID. So use hostname as unique ID among containers instead.
>> +	 */
>> +	if (getpid() == 1)
>> +		gethostname(proc_id, HOST_NAME_MAX);
>> +	else
>> +		sprintf(proc_id, "%d", (int)getpid());
>> +
>> +	snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%s",
>> +			primary_msl->memseg_arr.name, proc_id);
>>
>>   	ret = rte_fbarray_init(&local_msl->memseg_arr, name,
>>   		primary_msl->memseg_arr.len,
>> --
>> 2.17.1
>
  
Ananyev, Konstantin Oct. 30, 2019, 7 p.m. UTC | #3
> -----Original Message-----
> From: Yasufumi Ogawa <yasufum.o@gmail.com>
> Sent: Wednesday, October 30, 2019 1:42 PM
> To: Ananyev, Konstantin <konstantin.ananyev@intel.com>; Burakov, Anatoly <anatoly.burakov@intel.com>; david.marchand@redhat.com
> Cc: dev@dpdk.org; stable@dpdk.org; Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
> Subject: Re: [dpdk-dev] [PATCH v5 1/1] fbarray: fix duplicated fbarray file in secondary
> 
> On 2019/10/29 21:03, Ananyev, Konstantin wrote:
> >
> >
> >> -----Original Message-----
> >> From: dev <dev-bounces@dpdk.org> On Behalf Of yasufum.o@gmail.com
> >> Sent: Monday, October 28, 2019 8:08 AM
> >> To: Burakov, Anatoly <anatoly.burakov@intel.com>; david.marchand@redhat.com
> >> Cc: dev@dpdk.org; stable@dpdk.org; yasufum.o@gmail.com; Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
> >> Subject: [dpdk-dev] [PATCH v5 1/1] fbarray: fix duplicated fbarray file in secondary
> >>
> >> From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
> >>
> >> In secondary_msl_create_walk(), it creates a file for fbarrays with its
> >> PID for reserving unique name among secondary processes. However, it
> >> does not work if several secondaries run as app containers because each
> >> of containerized secondary has PID 1, and failed to reserve unique name
> >> other than first one. To reserve unique name in each of containers, use
> >> hostname instead of PID only if PID is 1.
> >>
> >> Cc: stable@dpdk.org
> >>
> >> Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
> >> ---
> >>   lib/librte_eal/linux/eal/eal_memalloc.c | 15 +++++++++++++--
> >>   1 file changed, 13 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/lib/librte_eal/linux/eal/eal_memalloc.c b/lib/librte_eal/linux/eal/eal_memalloc.c
> >> index af6d0d023..699079791 100644
> >> --- a/lib/librte_eal/linux/eal/eal_memalloc.c
> >> +++ b/lib/librte_eal/linux/eal/eal_memalloc.c
> >> @@ -1365,6 +1365,7 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl,
> >>   	struct rte_memseg_list *primary_msl, *local_msl;
> >>   	char name[PATH_MAX];
> >>   	int msl_idx, ret;
> >> +	char proc_id[HOST_NAME_MAX] = { 0 };
> >>
> >>   	if (msl->external)
> >>   		return 0;
> >> @@ -1374,8 +1375,18 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl,
> >>   	local_msl = &local_memsegs[msl_idx];
> >>
> >>   	/* create distinct fbarrays for each secondary */
> >> -	snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i",
> >> -		primary_msl->memseg_arr.name, getpid());
> >> +	/* If run secondary in a container, the name of fbarray file should
> >> +	 * not be decided with pid because getpid() always returns 1.
> >
> >
> > I wonder why is that?
> > What will prevent user to do something like:
> > docker run -it --cpuset-cpus=7-8 -v /local/kananye1:/local/kananye1 ubuntu-dpdk-local:latest /bin/bash
> > And then start dpdk app manually within the container?
> Hi Konstantin,
> 
> Thank you for your comment.
> 
> My concern is running secondary as app container. In current
> implementation, the name of fbarray file is decided by using PID and it
> must be overlapped with other process because assigning PID is started
> from 1 in each of app container. This patch is to fix the issue.
> 
> I think it is doable running app from bash for testing, but not
> acceptable for a realistic usecase in which user manages several app
> containers.

User can have a bash script to start inside container first, that
would do some preparation work (setup env variables, etc.)....
Or some different scenario when user needs/wants to
spawn several processes within container. 
Inside the lib you can't assume that your usage scenario is the
only possible one. 
I think solution needs to be generic enough to cover all such cases.
BTW, why we can't always use hostname in fbarray format?

> 
> Regards,
> Yasufumi
> 
> >
> >> +	 * In docker, hostname is assigned as a short form of full container
> >> +	 * ID. So use hostname as unique ID among containers instead.
> >> +	 */
> >> +	if (getpid() == 1)
> >> +		gethostname(proc_id, HOST_NAME_MAX);
> >> +	else
> >> +		sprintf(proc_id, "%d", (int)getpid());
> >> +
> >> +	snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%s",
> >> +			primary_msl->memseg_arr.name, proc_id);
> >>
> >>   	ret = rte_fbarray_init(&local_msl->memseg_arr, name,
> >>   		primary_msl->memseg_arr.len,
> >> --
> >> 2.17.1
> >
  
Yasufumi Ogawa Oct. 31, 2019, 10:03 a.m. UTC | #4
>> -----Original Message-----
>> From: Yasufumi Ogawa <yasufum.o@gmail.com>
>> Sent: Wednesday, October 30, 2019 1:42 PM
>> To: Ananyev, Konstantin <konstantin.ananyev@intel.com>; Burakov, Anatoly <anatoly.burakov@intel.com>; david.marchand@redhat.com
>> Cc: dev@dpdk.org; stable@dpdk.org; Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
>> Subject: Re: [dpdk-dev] [PATCH v5 1/1] fbarray: fix duplicated fbarray file in secondary
>>
>> On 2019/10/29 21:03, Ananyev, Konstantin wrote:
>>>
>>>
>>>> -----Original Message-----
>>>> From: dev <dev-bounces@dpdk.org> On Behalf Of yasufum.o@gmail.com
>>>> Sent: Monday, October 28, 2019 8:08 AM
>>>> To: Burakov, Anatoly <anatoly.burakov@intel.com>; david.marchand@redhat.com
>>>> Cc: dev@dpdk.org; stable@dpdk.org; yasufum.o@gmail.com; Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
>>>> Subject: [dpdk-dev] [PATCH v5 1/1] fbarray: fix duplicated fbarray file in secondary
>>>>
>>>> From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
>>>>
>>>> In secondary_msl_create_walk(), it creates a file for fbarrays with its
>>>> PID for reserving unique name among secondary processes. However, it
>>>> does not work if several secondaries run as app containers because each
>>>> of containerized secondary has PID 1, and failed to reserve unique name
>>>> other than first one. To reserve unique name in each of containers, use
>>>> hostname instead of PID only if PID is 1.
>>>>
>>>> Cc: stable@dpdk.org
>>>>
>>>> Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
>>>> ---
>>>>    lib/librte_eal/linux/eal/eal_memalloc.c | 15 +++++++++++++--
>>>>    1 file changed, 13 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/lib/librte_eal/linux/eal/eal_memalloc.c b/lib/librte_eal/linux/eal/eal_memalloc.c
>>>> index af6d0d023..699079791 100644
>>>> --- a/lib/librte_eal/linux/eal/eal_memalloc.c
>>>> +++ b/lib/librte_eal/linux/eal/eal_memalloc.c
>>>> @@ -1365,6 +1365,7 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl,
>>>>    	struct rte_memseg_list *primary_msl, *local_msl;
>>>>    	char name[PATH_MAX];
>>>>    	int msl_idx, ret;
>>>> +	char proc_id[HOST_NAME_MAX] = { 0 };
>>>>
>>>>    	if (msl->external)
>>>>    		return 0;
>>>> @@ -1374,8 +1375,18 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl,
>>>>    	local_msl = &local_memsegs[msl_idx];
>>>>
>>>>    	/* create distinct fbarrays for each secondary */
>>>> -	snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i",
>>>> -		primary_msl->memseg_arr.name, getpid());
>>>> +	/* If run secondary in a container, the name of fbarray file should
>>>> +	 * not be decided with pid because getpid() always returns 1.
>>>
>>>
>>> I wonder why is that?
>>> What will prevent user to do something like:
>>> docker run -it --cpuset-cpus=7-8 -v /local/kananye1:/local/kananye1 ubuntu-dpdk-local:latest /bin/bash
>>> And then start dpdk app manually within the container?
>> Hi Konstantin,
>>
>> Thank you for your comment.
>>
>> My concern is running secondary as app container. In current
>> implementation, the name of fbarray file is decided by using PID and it
>> must be overlapped with other process because assigning PID is started
>> from 1 in each of app container. This patch is to fix the issue.
>>
>> I think it is doable running app from bash for testing, but not
>> acceptable for a realistic usecase in which user manages several app
>> containers.
> 
> User can have a bash script to start inside container first, that
> would do some preparation work (setup env variables, etc.)....
> Or some different scenario when user needs/wants to
> spawn several processes within container.
I don't know how to avoid to overlap PID from bash script because I 
think PIDs on host cannot see from inside of a container. So, I'm not 
sure it is possible.

> Inside the lib you can't assume that your usage scenario is the
> only possible one.
I don't want to modify it for a specific usecase, but just to avoid to 
overlap filenames. I think it is better this filename is decided by lib 
itself without any of user configuration because user don't need to care 
about the file which is used by DPDK internally.

> I think solution needs to be generic enough to cover all such cases.

> BTW, why we can't always use hostname in fbarray format?
Sorry, I don't know. But I wonder using PID is more assured to get 
unique name, but does not work only for secondary app container 
accidentally.

Yasufumi
> 
>>
>> Regards,
>> Yasufumi
>>
>>>
>>>> +	 * In docker, hostname is assigned as a short form of full container
>>>> +	 * ID. So use hostname as unique ID among containers instead.
>>>> +	 */
>>>> +	if (getpid() == 1)
>>>> +		gethostname(proc_id, HOST_NAME_MAX);
>>>> +	else
>>>> +		sprintf(proc_id, "%d", (int)getpid());
>>>> +
>>>> +	snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%s",
>>>> +			primary_msl->memseg_arr.name, proc_id);
>>>>
>>>>    	ret = rte_fbarray_init(&local_msl->memseg_arr, name,
>>>>    		primary_msl->memseg_arr.len,
>>>> --
>>>> 2.17.1
>>>
  
Ananyev, Konstantin Oct. 31, 2019, 10:32 a.m. UTC | #5
> >> -----Original Message-----
> >> From: Yasufumi Ogawa <yasufum.o@gmail.com>
> >> Sent: Wednesday, October 30, 2019 1:42 PM
> >> To: Ananyev, Konstantin <konstantin.ananyev@intel.com>; Burakov, Anatoly <anatoly.burakov@intel.com>;
> david.marchand@redhat.com
> >> Cc: dev@dpdk.org; stable@dpdk.org; Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
> >> Subject: Re: [dpdk-dev] [PATCH v5 1/1] fbarray: fix duplicated fbarray file in secondary
> >>
> >> On 2019/10/29 21:03, Ananyev, Konstantin wrote:
> >>>
> >>>
> >>>> -----Original Message-----
> >>>> From: dev <dev-bounces@dpdk.org> On Behalf Of yasufum.o@gmail.com
> >>>> Sent: Monday, October 28, 2019 8:08 AM
> >>>> To: Burakov, Anatoly <anatoly.burakov@intel.com>; david.marchand@redhat.com
> >>>> Cc: dev@dpdk.org; stable@dpdk.org; yasufum.o@gmail.com; Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
> >>>> Subject: [dpdk-dev] [PATCH v5 1/1] fbarray: fix duplicated fbarray file in secondary
> >>>>
> >>>> From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp>
> >>>>
> >>>> In secondary_msl_create_walk(), it creates a file for fbarrays with its
> >>>> PID for reserving unique name among secondary processes. However, it
> >>>> does not work if several secondaries run as app containers because each
> >>>> of containerized secondary has PID 1, and failed to reserve unique name
> >>>> other than first one. To reserve unique name in each of containers, use
> >>>> hostname instead of PID only if PID is 1.
> >>>>
> >>>> Cc: stable@dpdk.org
> >>>>
> >>>> Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
> >>>> ---
> >>>>    lib/librte_eal/linux/eal/eal_memalloc.c | 15 +++++++++++++--
> >>>>    1 file changed, 13 insertions(+), 2 deletions(-)
> >>>>
> >>>> diff --git a/lib/librte_eal/linux/eal/eal_memalloc.c b/lib/librte_eal/linux/eal/eal_memalloc.c
> >>>> index af6d0d023..699079791 100644
> >>>> --- a/lib/librte_eal/linux/eal/eal_memalloc.c
> >>>> +++ b/lib/librte_eal/linux/eal/eal_memalloc.c
> >>>> @@ -1365,6 +1365,7 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl,
> >>>>    	struct rte_memseg_list *primary_msl, *local_msl;
> >>>>    	char name[PATH_MAX];
> >>>>    	int msl_idx, ret;
> >>>> +	char proc_id[HOST_NAME_MAX] = { 0 };
> >>>>
> >>>>    	if (msl->external)
> >>>>    		return 0;
> >>>> @@ -1374,8 +1375,18 @@ secondary_msl_create_walk(const struct rte_memseg_list *msl,
> >>>>    	local_msl = &local_memsegs[msl_idx];
> >>>>
> >>>>    	/* create distinct fbarrays for each secondary */
> >>>> -	snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i",
> >>>> -		primary_msl->memseg_arr.name, getpid());
> >>>> +	/* If run secondary in a container, the name of fbarray file should
> >>>> +	 * not be decided with pid because getpid() always returns 1.
> >>>
> >>>
> >>> I wonder why is that?
> >>> What will prevent user to do something like:
> >>> docker run -it --cpuset-cpus=7-8 -v /local/kananye1:/local/kananye1 ubuntu-dpdk-local:latest /bin/bash
> >>> And then start dpdk app manually within the container?
> >> Hi Konstantin,
> >>
> >> Thank you for your comment.
> >>
> >> My concern is running secondary as app container. In current
> >> implementation, the name of fbarray file is decided by using PID and it
> >> must be overlapped with other process because assigning PID is started
> >> from 1 in each of app container. This patch is to fix the issue.
> >>
> >> I think it is doable running app from bash for testing, but not
> >> acceptable for a realistic usecase in which user manages several app
> >> containers.
> >
> > User can have a bash script to start inside container first, that
> > would do some preparation work (setup env variables, etc.)....
> > Or some different scenario when user needs/wants to
> > spawn several processes within container.
> I don't know how to avoid to overlap PID from bash script because I
> think PIDs on host cannot see from inside of a container. So, I'm not
> sure it is possible.
> 
> > Inside the lib you can't assume that your usage scenario is the
> > only possible one.
> I don't want to modify it for a specific usecase, but just to avoid to
> overlap filenames. I think it is better this filename is decided by lib
> itself without any of user configuration because user don't need to care
> about the file which is used by DPDK internally.
> 
> > I think solution needs to be generic enough to cover all such cases.
> 
> > BTW, why we can't always use hostname in fbarray format?
> Sorry, I don't know. But I wonder using PID is more assured to get
> unique name, but does not work only for secondary app container
> accidentally.


My thought was - probably we always can use the same format:
snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%s_%u",
	primary_msl->memseg_arr.name,  gethostname(), getpid());
to fix that problem?

Konstantin


> 
> Yasufumi
> >
> >>
> >> Regards,
> >> Yasufumi
> >>
> >>>
> >>>> +	 * In docker, hostname is assigned as a short form of full container
> >>>> +	 * ID. So use hostname as unique ID among containers instead.
> >>>> +	 */
> >>>> +	if (getpid() == 1)
> >>>> +		gethostname(proc_id, HOST_NAME_MAX);
> >>>> +	else
> >>>> +		sprintf(proc_id, "%d", (int)getpid());
> >>>> +
> >>>> +	snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%s",
> >>>> +			primary_msl->memseg_arr.name, proc_id);
> >>>>
> >>>>    	ret = rte_fbarray_init(&local_msl->memseg_arr, name,
> >>>>    		primary_msl->memseg_arr.len,
> >>>> --
> >>>> 2.17.1
> >>>
  

Patch

diff --git a/lib/librte_eal/linux/eal/eal_memalloc.c b/lib/librte_eal/linux/eal/eal_memalloc.c
index af6d0d023..699079791 100644
--- a/lib/librte_eal/linux/eal/eal_memalloc.c
+++ b/lib/librte_eal/linux/eal/eal_memalloc.c
@@ -1365,6 +1365,7 @@  secondary_msl_create_walk(const struct rte_memseg_list *msl,
 	struct rte_memseg_list *primary_msl, *local_msl;
 	char name[PATH_MAX];
 	int msl_idx, ret;
+	char proc_id[HOST_NAME_MAX] = { 0 };
 
 	if (msl->external)
 		return 0;
@@ -1374,8 +1375,18 @@  secondary_msl_create_walk(const struct rte_memseg_list *msl,
 	local_msl = &local_memsegs[msl_idx];
 
 	/* create distinct fbarrays for each secondary */
-	snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i",
-		primary_msl->memseg_arr.name, getpid());
+	/* If run secondary in a container, the name of fbarray file should
+	 * not be decided with pid because getpid() always returns 1.
+	 * In docker, hostname is assigned as a short form of full container
+	 * ID. So use hostname as unique ID among containers instead.
+	 */
+	if (getpid() == 1)
+		gethostname(proc_id, HOST_NAME_MAX);
+	else
+		sprintf(proc_id, "%d", (int)getpid());
+
+	snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%s",
+			primary_msl->memseg_arr.name, proc_id);
 
 	ret = rte_fbarray_init(&local_msl->memseg_arr, name,
 		primary_msl->memseg_arr.len,