[devel] [PATCH for apt 1/2 v3] Add Debug::DynamicMMap::Allocate option

Dmitry V. Levin ldv на altlinux.org
Вт Дек 10 01:59:42 MSK 2019


On Mon, Dec 09, 2019 at 02:03:00PM +0300, Aleksei Nikiforov wrote:
> ---
>  apt/apt-pkg/contrib/mmap.cc | 15 +++++++++++++++
>  apt/doc/apt.conf.5.sgml     |  4 ++--
>  2 files changed, 17 insertions(+), 2 deletions(-)
> 
> 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<map_ptrloc> DynamicMMap::Allocate(unsigned long Item
>     // No pool is allocated, use an unallocated one
>     if (I == Pools + PoolCount)
>     {
> +      static const bool debug_grow = _config->FindB("Debug::DynamicMMap::Allocate", false);
> +
> +      if (debug_grow)
> +      {
> +         Pool *pool_iter = Pools;
> +         size_t pool_idx = 0;
> +
> +         _error->Warning(_("DynamicMMap::Allocate: allocating item of size %lu"), ItemSize);
> +
> +         for (; pool_idx < PoolCount; ++pool_iter, ++pool_idx)
> +         {
> +            _error->Warning(_("DynamicMMap::Allocate: Pool %zu, item size: %lu, start: %lu, count: %lu"), pool_idx, pool_iter->ItemSize, pool_iter->Start, pool_iter->Count);
> +         }
> +      }
> +
>        // Woops, we ran out, the calling code should allocate more.
>        if (Empty == 0)
>        {
> diff --git a/apt/doc/apt.conf.5.sgml b/apt/doc/apt.conf.5.sgml
> index 0a72e45..0026359 100644
> --- a/apt/doc/apt.conf.5.sgml
> +++ b/apt/doc/apt.conf.5.sgml
> @@ -525,8 +525,8 @@ DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure --apt";};
>     command line for each dpkg invokation. <literal/Debug::IdentCdrom/ will 
>     disable the inclusion of statfs data in CDROM IDs.
>     </para><para>
> -   To debug issues related to dynamic memory allocation, an option
> -   <literal/Debug::DynamicMMap::Grow/ may be used.
> +   To debug issues related to dynamic memory allocation, options
> +   <literal/Debug::DynamicMMap::Grow/ and <literal/Debug::DynamicMMap::Allocate/ may be used.
>     </para>
>   </RefSect1>
>   

Sadly, for some reason most of my comments were ignored.

I'm going to apply the following edition of this patch:

From a60c3cb4fd06c84c61358af597a88717ecc36c05 Mon Sep 17 00:00:00 2001
From: Aleksei Nikiforov <darktemplar на altlinux.org>
Date: Mon, 9 Dec 2019 14:03:00 +0300
Subject: [PATCH] Add Debug::DynamicMMap::Allocate option

Co-developed-by: Dmitry V. Levin <ldv на altlinux.org>
---
 apt/apt-pkg/contrib/mmap.cc | 17 +++++++++++++++++
 apt/doc/apt.conf.5.sgml     |  4 ++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/apt/apt-pkg/contrib/mmap.cc b/apt/apt-pkg/contrib/mmap.cc
index 779d7a6..56c3cce 100644
--- a/apt/apt-pkg/contrib/mmap.cc
+++ b/apt/apt-pkg/contrib/mmap.cc
@@ -266,6 +266,23 @@ std::experimental::optional<map_ptrloc> DynamicMMap::Allocate(unsigned long Item
    // No pool is allocated, use an unallocated one
    if (I == Pools + PoolCount)
    {
+      static const bool debug_allocate =
+	      _config->FindB("Debug::DynamicMMap::Allocate", false);
+
+      if (debug_allocate)
+      {
+         _error->Warning(_("DynamicMMap::Allocate: allocating item of size %lu"),
+                         ItemSize);
+
+         for (unsigned int i = 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 == 0)
       {
diff --git a/apt/doc/apt.conf.5.sgml b/apt/doc/apt.conf.5.sgml
index 0a72e45..0026359 100644
--- a/apt/doc/apt.conf.5.sgml
+++ b/apt/doc/apt.conf.5.sgml
@@ -525,8 +525,8 @@ DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure --apt";};
    command line for each dpkg invokation. <literal/Debug::IdentCdrom/ will 
    disable the inclusion of statfs data in CDROM IDs.
    </para><para>
-   To debug issues related to dynamic memory allocation, an option
-   <literal/Debug::DynamicMMap::Grow/ may be used.
+   To debug issues related to dynamic memory allocation, options
+   <literal/Debug::DynamicMMap::Grow/ and <literal/Debug::DynamicMMap::Allocate/ may be used.
    </para>
  </RefSect1>
  
-- 
ldv
----------- следующая часть -----------
Было удалено вложение не в текстовом формате...
Имя     : signature.asc
Тип     : application/pgp-signature
Размер  : 801 байтов
Описание: отсутствует
Url     : <http://lists.altlinux.org/pipermail/devel/attachments/20191210/df8e9159/attachment.bin>


Подробная информация о списке рассылки Devel