diff --git a/sdb/commands/spl/internal/kmem_helpers.py b/sdb/commands/spl/internal/kmem_helpers.py index 2653089e..22796665 100644 --- a/sdb/commands/spl/internal/kmem_helpers.py +++ b/sdb/commands/spl/internal/kmem_helpers.py @@ -20,6 +20,7 @@ import drgn import drgn.helpers.linux.list as drgn_list +import drgn.helpers.linux.percpu as drgn_percpu import sdb from sdb.commands.internal import p2 @@ -91,12 +92,25 @@ def object_size(cache: drgn.Object) -> int: def nr_objects(cache: drgn.Object) -> int: assert sdb.type_canonical_name(cache.type_) == 'struct spl_kmem_cache *' if backed_by_linux_cache(cache): - return int(cache.skc_obj_alloc.value_()) + return obj_alloc(cache) return int(cache.skc_obj_total.value_()) def obj_alloc(cache: drgn.Object) -> int: assert sdb.type_canonical_name(cache.type_) == 'struct spl_kmem_cache *' + if backed_by_linux_cache(cache): + try: + return int(drgn_percpu.percpu_counter_sum(cache.skc_linux_alloc)) + except AttributeError: + # + # The percpu_counter referenced above wasn't in ZoL until the + # following commit: ec1fea4516ac2f0c08d31d6308929298d1b281d0 + # + # Fall back to the old-mechanism of using skc_obj_alloc if that + # percpu_counter member doesn't exist (an AttributeError will + # be thrown). + # + pass return int(cache.skc_obj_alloc.value_()) diff --git a/tests/integration/test_core_generic.py b/tests/integration/test_core_generic.py index 0a0fea28..ec62a0b2 100644 --- a/tests/integration/test_core_generic.py +++ b/tests/integration/test_core_generic.py @@ -16,6 +16,7 @@ # pylint: disable=missing-module-docstring # pylint: disable=missing-function-docstring +# pylint: disable=not-callable from typing import Any diff --git a/tests/integration/test_linux_generic.py b/tests/integration/test_linux_generic.py index 5a1f00ba..5722f9b3 100644 --- a/tests/integration/test_linux_generic.py +++ b/tests/integration/test_linux_generic.py @@ -17,6 +17,7 @@ # pylint: disable=missing-module-docstring # pylint: disable=missing-function-docstring # pylint: disable=line-too-long +# pylint: disable=not-callable from typing import Any diff --git a/tests/integration/test_spl_generic.py b/tests/integration/test_spl_generic.py index 8a40aba8..2c43ce2e 100644 --- a/tests/integration/test_spl_generic.py +++ b/tests/integration/test_spl_generic.py @@ -17,6 +17,7 @@ # pylint: disable=missing-module-docstring # pylint: disable=missing-function-docstring # pylint: disable=line-too-long +# pylint: disable=not-callable from typing import Any diff --git a/tests/integration/test_zfs_generic.py b/tests/integration/test_zfs_generic.py index 3a295a27..c54c0196 100644 --- a/tests/integration/test_zfs_generic.py +++ b/tests/integration/test_zfs_generic.py @@ -17,6 +17,7 @@ # pylint: disable=missing-module-docstring # pylint: disable=missing-function-docstring # pylint: disable=line-too-long +# pylint: disable=not-callable from typing import Any diff --git a/tests/unit/test_parser.py b/tests/unit/test_parser.py index 75626d59..9192b236 100644 --- a/tests/unit/test_parser.py +++ b/tests/unit/test_parser.py @@ -15,6 +15,7 @@ # # pylint: disable=missing-docstring +# pylint: disable=not-callable from typing import List, Tuple