|
20 | 20 |
|
21 | 21 | import drgn |
22 | 22 | 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 |
24 | 24 |
|
25 | 25 | import sdb |
26 | 26 |
|
27 | 27 |
|
28 | 28 | def is_root_cache(cache: drgn.Object) -> bool: |
29 | 29 | 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 |
31 | 38 |
|
32 | 39 |
|
33 | 40 | 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()) |
38 | 52 |
|
39 | 53 |
|
40 | 54 | def for_each_child_cache(root_cache: drgn.Object) -> Iterable[drgn.Object]: |
41 | 55 | 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 [] |
45 | 66 |
|
46 | 67 |
|
47 | 68 | def for_each_node(cache: drgn.Object) -> Iterable[drgn.Object]: |
|
0 commit comments