Skip to content

Commit e7e1f49

Browse files
authored
DLPX-87072 sdb: slabs command no longer works in 5.15 kernels (#334)
= Github Issue Tracker Automation Closes #333
1 parent 18bd28d commit e7e1f49

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

sdb/commands/linux/internal/slub_helpers.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,49 @@
2020

2121
import drgn
2222
from drgn.helpers.linux.list import list_for_each_entry
23-
from drgn.helpers.linux.slab import find_containing_slab_cache
23+
from drgn.helpers.linux.slab import find_containing_slab_cache, for_each_slab_cache
2424

2525
import sdb
2626

2727

2828
def is_root_cache(cache: drgn.Object) -> bool:
2929
assert sdb.type_canonical_name(cache.type_) == 'struct kmem_cache *'
30-
return int(cache.memcg_params.root_cache.value_()) == 0x0
30+
#
31+
# In v5.9 and later the `memcg_params` field and the concept
32+
# of root+children caches was completely removed.
33+
#
34+
try:
35+
return int(cache.memcg_params.root_cache.value_()) == 0x0
36+
except AttributeError:
37+
return False
3138

3239

3340
def for_each_root_cache() -> Iterable[drgn.Object]:
34-
yield from list_for_each_entry(
35-
"struct kmem_cache",
36-
sdb.get_object("slab_root_caches").address_of_(),
37-
"memcg_params.__root_caches_node")
41+
#
42+
# In v5.9 and later the `memcg_params` field and the concept
43+
# of root+children caches was completely removed.
44+
#
45+
try:
46+
yield from list_for_each_entry(
47+
"struct kmem_cache",
48+
sdb.get_object("slab_root_caches").address_of_(),
49+
"memcg_params.__root_caches_node")
50+
except KeyError:
51+
yield from for_each_slab_cache(sdb.get_prog())
3852

3953

4054
def for_each_child_cache(root_cache: drgn.Object) -> Iterable[drgn.Object]:
4155
assert sdb.type_canonical_name(root_cache.type_) == 'struct kmem_cache *'
42-
yield from list_for_each_entry(
43-
"struct kmem_cache", root_cache.memcg_params.children.address_of_(),
44-
"memcg_params.children_node")
56+
#
57+
# In v5.9 and later the `memcg_params` field and the concept
58+
# of root+children caches was completely removed.
59+
#
60+
try:
61+
yield from list_for_each_entry(
62+
"struct kmem_cache", root_cache.memcg_params.children.address_of_(),
63+
"memcg_params.children_node")
64+
except AttributeError:
65+
yield from []
4566

4667

4768
def for_each_node(cache: drgn.Object) -> Iterable[drgn.Object]:

0 commit comments

Comments
 (0)