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 31984A0547; Wed, 25 Aug 2021 14:30:51 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E50AB40041; Wed, 25 Aug 2021 14:30:50 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by mails.dpdk.org (Postfix) with ESMTP id 54A524003D for ; Wed, 25 Aug 2021 14:30:50 +0200 (CEST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id E55B85C0120; Wed, 25 Aug 2021 08:30:47 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 25 Aug 2021 08:30:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=fm2; bh= a3fJ0u8kRWQygSjYvew3wxbuMI40sP83qD9iqFAZsB4=; b=VzKSSb6BshGGHB1G oDjcp6WwlrZLHH37xZC0Gnfn//IX5Nti4RWsjVS9GTwMSRMxICk+xYwE7ceeTICa FdIb7QbWkSZAovrCqNlJodluiqkszZeDe1Iw7ajm8uXGYpT8h4QOIM/V4/7BOK9v 1XKuPzY+c7rgKNfSw56JHAq2uIQeCyHfrXPa13WVl8f2mp9fREjvoHoljFk6tfcO SRLIUnNPwlgU3iEiMskgAazmIPboeSDKr+kLWDShzdjy4jKmJO024GnFW4isNakq D7tXd/gI6e5ih3/pQQF3II1iFhVc5FnEZQQcY+0aJlIjOmVf6g/hAoIhMPQpY1wC H+d/IQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=a3fJ0u8kRWQygSjYvew3wxbuMI40sP83qD9iqFAZs B4=; b=JMWCQPA+y2znSx5UfqOGnky6S4HwStV2bDtmVFoCGA2CNqiKKho9cLCYx nfvqY+AKCNANjb4rsPWo8uiuKO4aaFCIprOJUoSEFcwJp80uI2dMAPDuFhMU5Wes HlY9TjDkYG3CQaUXFnivE+OnRI+Z1ZlglMVLF4Lw2jyQvKx0feaiBj2yoeYG/TJo PKMPZQZQL9fGarQ/OsL4FtCkB8RD6EDXqbIdriw8IvtFoTw30nOPZCJ2Zhja1i07 DFQMu/MCIddONlc5v3irKsgP58VhdEvp7wwuHkXKMCp0vTODmo88HIZA1TE4jJKC 3OjRvSpNmz/ZCn5APAp/sfnFX5Z4w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddruddtledgheefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkfgjfhgggfgtsehtufertddttddvnecuhfhrohhmpefvhhhomhgr shcuofhonhhjrghlohhnuceothhhohhmrghssehmohhnjhgrlhhonhdrnhgvtheqnecugg ftrfgrthhtvghrnhepudeggfdvfeduffdtfeeglefghfeukefgfffhueejtdetuedtjeeu ieeivdffgeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepthhhohhmrghssehmohhnjhgrlhhonhdrnhgvth X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Aug 2021 08:30:46 -0400 (EDT) From: Thomas Monjalon To: "Burakov, Anatoly" Cc: Dmitry Kozlyuk , "dev@dpdk.org" , "Xueming(Steven) Li" , david.marchand@redhat.com, bruce.richardson@intel.com Date: Wed, 25 Aug 2021 14:30:44 +0200 Message-ID: <4279947.Tyd60qNmeV@thomas> In-Reply-To: <915867f6-f558-e2be-0c19-d52b313d032e@intel.com> References: <1730403.MaGYrl2sIR@thomas> <915867f6-f558-e2be-0c19-d52b313d032e@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Subject: Re: [dpdk-dev] Zeroing out memory on free 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" 25/08/2021 13:47, Burakov, Anatoly: > On 25-Aug-21 8:26 AM, Thomas Monjalon wrote: > > 24/08/2021 12:58, Dmitry Kozlyuk: > >> Hello, > >> > >> Me and Xueming are wondering why DPDK clears the memory on free > >> and not only when it's explicitly requested (rte_zmalloc). > >> > >> It's been so for a while: > >> > >> commit ea0bddbd14e68fb42d9774bc3543e51b510e48d3 > >> Author: Sergio Gonzalez Monroy > >> Date: Tue Jul 5 12:01:15 2016 +0100 > >> > >> mem: zero out memory on free > >> > >> Since commit fafcc11985a2, memzones are not guaranteed to be zeroed out. > >> This could potentially cause issues as applications might have been > >> relying on the allocated memory being zeroed out. > >> > >> On init all allocated memory is zeroed by the kernel, so by zeroing out > >> memory on free, all available dpdk memory is always zeroed. > >> > >> Fixes: fafcc11985a2 ("mem: rework memzone to be allocated by malloc") > >> > >> Signed-off-by: Sergio Gonzalez Monroy > >> > >> At present this explanation doesn't look satisfying: > >> 1. Memzone API does not promise they will be zeroed out. > >> Memzones are mostly used for DMA, so their content will likely be overwritten. > >> 2. If application assumptions are wrong, DPDK should not try to fix it. > >> Memory manager poisons memory in debug mode to detect such errors. > >> > >> Zeroing memory is quite slow, but in many cases unneeded. > >> It looks attractive to only do it in rte_zmalloc(). > >> AFAIK what prohibits moving memset() there unconditionally > >> is that the kernel already gives us cleared pages, > >> so the first allocation of each piece of memory would do unnecessary work. > >> This can be solved by giving the user a choice in EAL options > > > > No I don't think it should be workarounded in EAL options. > > > >> or with more elaborate tracking of memory dirtiness in MM. > > > > Looks a good idea. > > > >> Are there any other reasons why clearing is done the current way? > > > > I think the only reason was to avoid doing reset for the first usage. > > You're right it is not optimal when reusing memory > > without any zeroing need. > > > > You said it yourself: zeroing out memory is quite slow. This was pretty > much done for performance reasons - memory is released way less often > than allocated, and we get memory from the kernel that is *always* > zeroed out in case of hugepages, so we don't need to zero them out > initially. So, in essence, this allows us to always keeps memory zeroed > out without worrying about doing that for every allocation. Anatoly, what do you think about the idea above (marking initial state as clean, and zero on allocations only if needed)?