bcc slabratetop fatal error

Posted rtoax

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bcc slabratetop fatal error相关的知识,希望对你有一定的参考价值。

tools/slabratetop: call to undeclared function ‘slab_address’

When my system uses SLUB And the kernel version >=5.16, there are the following problems:

$ sudo ./slabratetop.py
In file included from /virtual/main.c:13:
include/linux/slub_def.h:162:26: warning: call to undeclared function 'slab_address'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        void *object = x - (x - slab_address(slab)) % cache->size;
                                ^
include/linux/slub_def.h:162:46: error: invalid operands to binary expression ('void *' and 'unsigned int')
        void *object = x - (x - slab_address(slab)) % cache->size;
                           ~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~
include/linux/slub_def.h:164:8: error: incomplete definition of type 'struct slab'
                (slab->objects - 1) * cache->size;
                 ~~~~^
include/linux/kasan.h:13:8: note: forward declaration of 'struct slab'
struct slab;
       ^
In file included from /virtual/main.c:13:
include/linux/slub_def.h:184:31: warning: call to undeclared function 'slab_address'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        return __obj_to_index(cache, slab_address(slab), obj);
                                     ^
include/linux/slub_def.h:184:31: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'void *' [-Wint-conversion]
        return __obj_to_index(cache, slab_address(slab), obj);
                                     ^~~~~~~~~~~~~~~~~~
include/linux/slub_def.h:173:14: note: passing argument to parameter 'addr' here
                                          void *addr, void *obj)
                                                ^
include/linux/slub_def.h:190:13: error: incomplete definition of type 'struct slab'
        return slab->objects;
               ~~~~^
include/linux/kasan.h:13:8: note: forward declaration of 'struct slab'
struct slab;
       ^
2 warnings and 4 errors generated.
Traceback (most recent call last):
  File "/home/rongtao/Git/bcc/tools/./slabratetop.py", line 111, in <module>
    b = BPF(text=bpf_text)
        ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/bcc/__init__.py", line 475, in __init__
    raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module <text>

see commit 40f3bf0cb04c(“mm: Convert struct page to struct slab in functions used by other subsystems”)

This issue should be modified in the kernel, I’m trying to fix this

https://lore.kernel.org/all/tencent_ABA832E296819D1053D6C625ADCAF76BC706@qq.com/

#if 0
static inline void *nearest_obj(struct kmem_cache *cache, const struct slab *slab,
                void *x) 
    void *object = x - (x - slab_address(slab)) % cache->size;
    void *last_object = slab_address(slab) +
        (slab->objects - 1) * cache->size;
    void *result = (unlikely(object > last_object)) ? last_object : object;

    result = fixup_red_left(cache, result);
    return result;

#endif

/* Determine object index from a given position */
static inline unsigned int __obj_to_index(const struct kmem_cache *cache,
                      void *addr, void *obj)

    return reciprocal_divide(kasan_reset_tag(obj) - addr,
                 cache->reciprocal_size);


#if 0
static inline unsigned int obj_to_index(const struct kmem_cache *cache,
                    const struct slab *slab, void *obj)

    if (is_kfence_address(obj))
        return 0;
    return __obj_to_index(cache, slab_address(slab), obj);

#endif

#if 0
static inline int objs_per_slab(const struct kmem_cache *cache,
                     const struct slab *slab)

    return slab->objects;

#endif

提交 commit

mm: Functions used internally should not be put into slub_def.h

commit 40f3bf0cb04c("mm: Convert struct page to struct slab in functions
used by other subsystems") introduce 'slab_address()' and 'struct slab'
in slab_def.h(CONFIG_SLAB) and slub_def.h(CONFIG_SLUB). When referencing
a header file <linux/slub_def.h> in a module or BPF code, 'slab_address()'
and 'struct slab' are not recognized, resulting in incomplete and
undefined errors(see bcc slabratetop.py error [0]).

Moving the function definitions of reference data structures such as
struct slab and slab_address() such as nearest_obj(), obj_to_index(),
and objs_per_slab() to the internal header file slab.h solves this
fatal problem.

[0] https://github.com/iovisor/bcc/issues/4438

以上是关于bcc slabratetop fatal error的主要内容,如果未能解决你的问题,请参考以下文章

bcc slabratetop fatal error

tools/slabratetop: call to undeclared function ‘slab_address‘

tools/slabratetop: call to undeclared function ‘slab_address‘

git err : fatal: remote origin already exists.

Err "Kernel panic - not syncing: Fatal exception"

[ERR] collect2: fatal error: cannot find 'ld'