From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id A04A61BE03; Fri, 21 Dec 2018 13:12:24 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Dec 2018 04:12:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,381,1539673200"; d="scan'208";a="131863313" Received: from aburakov-mobl1.ger.corp.intel.com (HELO [10.252.9.59]) ([10.252.9.59]) by fmsmga001.fm.intel.com with ESMTP; 21 Dec 2018 04:12:22 -0800 To: Thomas Monjalon Cc: dev@dpdk.org, stable@dpdk.org, ferruh.yigit@intel.com, bruce.richardson@intel.com, arybchenko@solarflare.com, olivier.matz@6wind.com References: <884a355bde19652d57c253c6b36036571c4f46ee.1543926108.git.anatoly.burakov@intel.com> <8322983.QTS3aZyW4V@xps> From: "Burakov, Anatoly" Message-ID: <83787667-1a16-6845-4ebd-dafca474f7ea@intel.com> Date: Fri, 21 Dec 2018 12:12:21 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.3.3 MIME-Version: 1.0 In-Reply-To: <8322983.QTS3aZyW4V@xps> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH 18.11] malloc: fix deadlock when using malloc stats X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Dec 2018 12:12:25 -0000 On 21-Dec-18 12:09 PM, Thomas Monjalon wrote: > 04/12/2018 13:22, Anatoly Burakov: >> Currently, malloc statistics and external heap creation code >> use memory hotplug lock as a way to synchronize accesses to >> heaps (as in, locking the hotplug lock to prevent list of heaps >> from changing under our feet). At the same time, malloc >> statistics code will also lock the heap because it needs to >> access heap data and does not want any other thread to allocate >> anything from that heap. >> >> In such scheme, it is possible to enter a deadlock with the >> following sequence of events: >> >> thread 1 thread 2 >> rte_malloc() >> rte_malloc_dump_stats() >> take heap lock >> take hotplug lock >> failed to allocate, >> attempt to take >> hotplug lock >> attempt to take heap lock >> >> Neither thread will be able to continue, as both of them are >> waiting for the other one to drop the lock. Adding an >> additional lock will require an ABI change, so instead of >> that, make malloc statistics calls thread-unsafe with >> respect to creating/destroying heaps. >> >> Fixes: 72cf92b31855 ("malloc: index heaps using heap ID rather than NUMA node") >> Cc: stable@dpdk.org >> >> Signed-off-by: Anatoly Burakov >> --- >> >> Notes: >> IMO this is the best we can do for 18.11 without breaking ABI. >> For 19.02, we can introduce a new global heap lock (something >> i should've done in the first place...), so this patch is >> not applicable to 19.02. For 19.02, we can fix this properly >> by introducing another lock and breaking the EAL ABI. >> >> Not sure where to put docs update, feedback welcome. > > This patch is also changing the API, because functions become not thread-safe. > I think you should note it in the release notes. > About 19.02, do we want to take this patch (with release notes updated)? > Yes and yes. Technically, they still are thread-safe when it comes to individual heap access - they just aren't thread-safe with regards to creating/destroying heaps (so, we may enter the dump function, and a heap may be added/removed while we're iterating over the list of heaps). I'll send a v2 with release notes update. -- Thanks, Anatoly