2626
2727
2828def is_root_cache (cache : drgn .Object ) -> bool :
29- assert cache .type_ . type_name ( ) == 'struct kmem_cache *'
29+ assert sdb . type_canonical_name ( cache .type_ ) == 'struct kmem_cache *'
3030 return int (cache .memcg_params .root_cache .value_ ()) == 0x0
3131
3232
@@ -38,14 +38,14 @@ def for_each_root_cache() -> Iterable[drgn.Object]:
3838
3939
4040def for_each_child_cache (root_cache : drgn .Object ) -> Iterable [drgn .Object ]:
41- assert root_cache .type_ . type_name ( ) == 'struct kmem_cache *'
41+ assert sdb . type_canonical_name ( root_cache .type_ ) == 'struct kmem_cache *'
4242 yield from list_for_each_entry (
4343 "struct kmem_cache" , root_cache .memcg_params .children .address_of_ (),
4444 "memcg_params.children_node" )
4545
4646
4747def nr_slabs (cache : drgn .Object ) -> int :
48- assert cache .type_ . type_name ( ) == 'struct kmem_cache *'
48+ assert sdb . type_canonical_name ( cache .type_ ) == 'struct kmem_cache *'
4949 nslabs : int = cache .node [0 ].nr_slabs .counter .value_ ()
5050 if is_root_cache (cache ):
5151 for child in for_each_child_cache (cache ):
@@ -54,30 +54,30 @@ def nr_slabs(cache: drgn.Object) -> int:
5454
5555
5656def entries_per_slab (cache : drgn .Object ) -> int :
57- assert cache .type_ . type_name ( ) == 'struct kmem_cache *'
57+ assert sdb . type_canonical_name ( cache .type_ ) == 'struct kmem_cache *'
5858 return int (cache .oo .x .value_ ()) & 0xffff
5959
6060
6161def entry_size (cache : drgn .Object ) -> int :
62- assert cache .type_ . type_name ( ) == 'struct kmem_cache *'
62+ assert sdb . type_canonical_name ( cache .type_ ) == 'struct kmem_cache *'
6363 return int (cache .size .value_ ())
6464
6565
6666def object_size (cache : drgn .Object ) -> int :
67- assert cache .type_ . type_name ( ) == 'struct kmem_cache *'
67+ assert sdb . type_canonical_name ( cache .type_ ) == 'struct kmem_cache *'
6868 return int (cache .object_size .value_ ())
6969
7070
7171def total_memory (cache : drgn .Object ) -> int :
72- assert cache .type_ . type_name ( ) == 'struct kmem_cache *'
72+ assert sdb . type_canonical_name ( cache .type_ ) == 'struct kmem_cache *'
7373 nslabs = nr_slabs (cache )
7474 epslab = entries_per_slab (cache )
7575 esize = entry_size (cache )
7676 return nslabs * epslab * esize
7777
7878
7979def objs (cache : drgn .Object ) -> int :
80- assert cache .type_ . type_name ( ) == 'struct kmem_cache *'
80+ assert sdb . type_canonical_name ( cache .type_ ) == 'struct kmem_cache *'
8181 count : int = cache .node [0 ].total_objects .counter .value_ ()
8282 if is_root_cache (cache ):
8383 for child in for_each_child_cache (cache ):
@@ -86,7 +86,7 @@ def objs(cache: drgn.Object) -> int:
8686
8787
8888def inactive_objs (cache : drgn .Object ) -> int :
89- assert cache .type_ . type_name ( ) == 'struct kmem_cache *'
89+ assert sdb . type_canonical_name ( cache .type_ ) == 'struct kmem_cache *'
9090 node = cache .node [0 ].partial # assumption nr_node_ids == 0
9191 free = 0
9292 for page in list_for_each_entry ("struct page" , node .address_of_ (), "lru" ):
@@ -98,17 +98,17 @@ def inactive_objs(cache: drgn.Object) -> int:
9898
9999
100100def active_objs (cache : drgn .Object ) -> int :
101- assert cache .type_ . type_name ( ) == 'struct kmem_cache *'
101+ assert sdb . type_canonical_name ( cache .type_ ) == 'struct kmem_cache *'
102102 return objs (cache ) - inactive_objs (cache )
103103
104104
105105def active_memory (cache : drgn .Object ) -> int :
106- assert cache .type_ . type_name ( ) == 'struct kmem_cache *'
106+ assert sdb . type_canonical_name ( cache .type_ ) == 'struct kmem_cache *'
107107 return active_objs (cache ) * entry_size (cache )
108108
109109
110110def util (cache : drgn .Object ) -> int :
111- assert cache .type_ . type_name ( ) == 'struct kmem_cache *'
111+ assert sdb . type_canonical_name ( cache .type_ ) == 'struct kmem_cache *'
112112 total_mem = total_memory (cache )
113113 if total_mem == 0 :
114114 return 0
@@ -129,8 +129,8 @@ def cache_get_free_pointer(cache: drgn.Object, p: drgn.Object) -> drgn.Object:
129129 function assumes that CONFIG_SLAB_FREELIST_HARDENED
130130 is set in the target
131131 """
132- assert cache .type_ . type_name ( ) == 'struct kmem_cache *'
133- assert p .type_ . type_name ( ) == 'void *'
132+ assert sdb . type_canonical_name ( cache .type_ ) == 'struct kmem_cache *'
133+ assert sdb . type_canonical_name ( p .type_ ) == 'void *'
134134 hardened_ptr = p + cache .offset .value_ ()
135135
136136 #
@@ -177,7 +177,7 @@ def for_each_freeobj_in_slab(cache: drgn.Object,
177177
178178
179179def for_each_partial_slab_in_cache (cache : drgn .Object ) -> Iterable [drgn .Object ]:
180- assert cache .type_ . type_name ( ) == 'struct kmem_cache *'
180+ assert sdb . type_canonical_name ( cache .type_ ) == 'struct kmem_cache *'
181181
182182 node = cache .node [0 ].partial # assumption nr_node_ids == 0
183183 yield from list_for_each_entry ("struct page" , node .address_of_ (), "lru" )
@@ -192,6 +192,7 @@ def for_each_object_in_cache(cache: drgn.Object) -> Iterable[drgn.Object]:
192192 Goes through each object in the SLUB cache supplied
193193 yielding them to the consumer.
194194 """
195+ assert sdb .type_canonical_name (cache .type_ ) == 'struct kmem_cache *'
195196 pg_slab_flag = 1 << sdb .get_prog ().constant ('PG_slab' ).value_ ()
196197
197198 cache_children = {child .value_ () for child in for_each_child_cache (cache )}
0 commit comments