Skip to content

Commit 7c20a3e

Browse files
committed
Update spl_kmem_caches command to be aware of new percpu counter
The following commit from ZoL introduced this counter: openzfs/zfs@ec1fea4
1 parent 9cd5599 commit 7c20a3e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

sdb/commands/spl/internal/kmem_helpers.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import drgn
2222
import drgn.helpers.linux.list as drgn_list
23+
import drgn.helpers.linux.percpu as drgn_percpu
2324

2425
import sdb
2526
from sdb.commands.internal import p2
@@ -91,12 +92,23 @@ def object_size(cache: drgn.Object) -> int:
9192
def nr_objects(cache: drgn.Object) -> int:
9293
assert sdb.type_canonical_name(cache.type_) == 'struct spl_kmem_cache *'
9394
if backed_by_linux_cache(cache):
94-
return int(cache.skc_obj_alloc.value_())
95+
return obj_alloc(cache)
9596
return int(cache.skc_obj_total.value_())
9697

9798

9899
def obj_alloc(cache: drgn.Object) -> int:
99100
assert sdb.type_canonical_name(cache.type_) == 'struct spl_kmem_cache *'
101+
try:
102+
return int(drgn_percpu.percpu_counter_sum(cache.skc_linux_alloc))
103+
except AttributeError:
104+
#
105+
# The percpu_counter referenced above wasn't in ZoL until the
106+
# following commit: ec1fea4516ac2f0c08d31d6308929298d1b281d0
107+
#
108+
# Fall back to the old-mechanism if that percpu_counter member
109+
# doesn't exist (an AttributeError will be thrown).
110+
#
111+
return int(cache.skc_obj_alloc.value_())
100112
return int(cache.skc_obj_alloc.value_())
101113

102114

0 commit comments

Comments
 (0)