From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EDE8FA0C3F; Thu, 15 Apr 2021 16:24:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 75E571622AA; Thu, 15 Apr 2021 16:24:08 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id 0ADAE1622A9 for ; Thu, 15 Apr 2021 16:24:06 +0200 (CEST) IronPort-SDR: dL6Tyaj1BrbXQk2U6i4jSjnXEd8sxtxPqLFP9KJpj2s581Q73/mLO6zsDLmQAFERxS9SI8sQUG Zq2hzET9Ic4A== X-IronPort-AV: E=McAfee;i="6200,9189,9955"; a="215367012" X-IronPort-AV: E=Sophos;i="5.82,225,1613462400"; d="scan'208";a="215367012" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2021 07:24:05 -0700 IronPort-SDR: Aq5AiFIFqy3oPrYk6LV2mhUs8bDPDJkTNiQeQoow/EzDjgKGZnsK6OWYWTJr7I7ZQT4p11P9cW koY4HWm44/2Q== X-IronPort-AV: E=Sophos;i="5.82,225,1613462400"; d="scan'208";a="425194751" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.213.218.92]) ([10.213.218.92]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2021 07:24:04 -0700 To: xiangxia.m.yue@gmail.com Cc: dev@dpdk.org References: <20210325082125.37488-1-xiangxia.m.yue@gmail.com> From: "Burakov, Anatoly" Message-ID: <13b8ee99-39a7-c0a6-39fc-e126802d656d@intel.com> Date: Thu, 15 Apr 2021 15:24:01 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <20210325082125.37488-1-xiangxia.m.yue@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH] eal/linux: add operation LOCK_NB to flock() X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 25-Mar-21 8:21 AM, xiangxia.m.yue@gmail.com wrote: > From: Tonghao Zhang > > The hugepage of different size, 2MB, 1GB may be mounted on > the same directory (e.g /dev/hugepages). Then dpdk > primary process will be blocked. To address this issue, > add the LOCK_NB flags to flock(). > > $ cat /proc/mounts > ... > none /dev/hugepages hugetlbfs rw,seclabel,relatime,pagesize=1024M 0 0 > none /dev/hugepages hugetlbfs rw,seclabel,relatime,pagesize=2M 0 0 > > Add more details for err logs. > > Signed-off-by: Tonghao Zhang > --- > lib/librte_eal/linux/eal_hugepage_info.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/lib/librte_eal/linux/eal_hugepage_info.c b/lib/librte_eal/linux/eal_hugepage_info.c > index d97792cadeb6..1ff76e539053 100644 > --- a/lib/librte_eal/linux/eal_hugepage_info.c > +++ b/lib/librte_eal/linux/eal_hugepage_info.c > @@ -451,9 +451,12 @@ hugepage_info_init(void) > hpi->lock_descriptor = open(hpi->hugedir, O_RDONLY); > > /* if blocking lock failed */ > - if (flock(hpi->lock_descriptor, LOCK_EX) == -1) { > + if (flock(hpi->lock_descriptor, LOCK_EX | LOCK_NB) == -1) { > RTE_LOG(CRIT, EAL, > - "Failed to lock hugepage directory!\n"); > + "Failed to lock hugepage directory! " > + "The hugepage dir (%s) was locked by " > + "other processes or self twice.\n", > + hpi->hugedir); > break; > } > /* clear out the hugepages dir from unused pages */ > Use cases such as "having two hugetlbfs page sizes on the same hugetlbfs mountpoint" are user error, but i agree that deadlocking is probably not the way we want to go about it. An alternative way would be to check if we already have a mountpoint with the same path, and this would produce a better error message (as a user, "hugepage dir is locked by self twice" doesn't tell me anything useful), at a cost of slightly more complicated code. I'm not sure which way i want to go here. Normally, hugetlbfs shouldn't be staying locked for long, so i'm wary of adding a LOCK_NB here, so i feel slightly uneasy about this patch. Do you have any opinions? Also, do other OS's EALs need similar fix? -- Thanks, Anatoly