From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Mon, 9 Dec 2019 01:50:47 +0300 From: "Dmitry V. Levin" To: Aleksei Nikiforov Message-ID: <20191208225047.GA30742@altlinux.org> References: <20191206131606.83061-1-darktemplar@altlinux.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pf9I7BMVVzbSWLtt" Content-Disposition: inline In-Reply-To: <20191206131606.83061-1-darktemplar@altlinux.org> Cc: ALT Devel discussion list Subject: Re: [devel] [PATCH for apt 1/2] Add option for debugging DynamicMMap::Allocate X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Dec 2019 22:50:47 -0000 Archived-At: List-Archive: List-Post: --pf9I7BMVVzbSWLtt Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Dec 06, 2019 at 04:16:05PM +0300, Aleksei Nikiforov wrote: > --- > apt/apt-pkg/contrib/mmap.cc | 15 +++++++++++++++ > apt/doc/apt.conf.5.sgml | 2 +- > 2 files changed, 16 insertions(+), 1 deletion(-) I suggest adding the name of the new option to the commit message so it would be git-grep'able, for example: Add Debug::DynamicMMap::Allocate option Add a new option for debugging DynamicMMap::Allocate. > diff --git a/apt/apt-pkg/contrib/mmap.cc b/apt/apt-pkg/contrib/mmap.cc > index a3b06cc..cf01be9 100644 > --- a/apt/apt-pkg/contrib/mmap.cc > +++ b/apt/apt-pkg/contrib/mmap.cc > @@ -265,6 +265,21 @@ std::experimental::optional DynamicMMap:= :Allocate(unsigned long Item > // No pool is allocated, use an unallocated one > if (I =3D=3D Pools + PoolCount) > { > + static const bool debug_grow =3D _config->FindB("Debug::DynamicMMa= p::Allocate", false); > + > + if (debug_grow) > + { > + Pool *pool_iter =3D Pools; > + size_t pool_idx =3D 0; > + > + _error->Warning(_("DynamicMMap::Allocate: allocating item of si= ze %lu"), ItemSize); > + > + for (; pool_idx < PoolCount; ++pool_iter, ++pool_idx) > + { > + _error->Warning(_("DynamicMMap::Allocate: Pool %zu, item siz= e: %lu, start: %lu, count: %lu"), pool_idx, pool_iter->ItemSize, pool_iter-= >Start, pool_iter->Count); > + } > + } Nitpicking: - this is debugging, there is no need to optimize, so there is no need for pool_iter; - let's use "for" loop initial declarations, they are widely used in apt already; - the type of iterator should be the same as the type of PoolCount; - lines are too long. Consider something like this (untested): if (debug_grow) { _error->Warning(_("DynamicMMap::Allocate: allocating item of size = %lu"), ItemSize); for (unsigned int i =3D 0; i < PoolCount; ++i) { _error->Warning(_("DynamicMMap::Allocate: Pool %u, item size: %= lu" ", start: %lu, count: %lu"), i, Pools[i].ItemSize, Pools[i].Start, Pools[i].Count); } } > // Woops, we ran out, the calling code should allocate more. > if (Empty =3D=3D 0) > { > diff --git a/apt/doc/apt.conf.5.sgml b/apt/doc/apt.conf.5.sgml > index 0a72e45..72fc0c3 100644 > --- a/apt/doc/apt.conf.5.sgml > +++ b/apt/doc/apt.conf.5.sgml > @@ -526,7 +526,7 @@ DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure = --apt";}; > disable the inclusion of statfs data in CDROM IDs. > > To debug issues related to dynamic memory allocation, an option > - +