Skip to content

Commit dc1daf0

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 dc1daf0

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

sdb/commands/spl/internal/kmem_helpers.py

Lines changed: 15 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,25 @@ 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+
if backed_by_linux_cache(cache):
102+
try:
103+
return int(drgn_percpu.percpu_counter_sum(cache.skc_linux_alloc))
104+
except AttributeError:
105+
#
106+
# The percpu_counter referenced above wasn't in ZoL until the
107+
# following commit: ec1fea4516ac2f0c08d31d6308929298d1b281d0
108+
#
109+
# Fall back to the old-mechanism of using skc_obj_alloc if that
110+
# percpu_counter member doesn't exist (an AttributeError will
111+
# be thrown).
112+
#
113+
pass
100114
return int(cache.skc_obj_alloc.value_())
101115

102116

0 commit comments

Comments
 (0)