1

System: Ubuntu 14.04 Kernel 4.10.12

So I'm in the process of trying to understand how to use ftrace, but something I noticed is derailing me a bit:

available_filter_functions can be used to filter what's being traced to certain functions. But the function I'm trying to trace (in this case, KSM's main worker function ksm_do_scan) isn't showing up in the list.

Here is the list of available functions (filtered by ksm-functions):

root@test:/sys/kernel/debug/tracing# cat available_filter_functions | grep             
ksm

ksm_memory_callback
break_ksm
unmerge_ksm_pages
get_ksm_page
try_to_merge_with_ksm_page
ksm_scan_thread (calls ksm_do_scan)
__ksm_enter
ksm_madvise
__ksm_exit
ksm_might_need_to_copy
rmap_walk_ksm
ksm_migrate_page

And here is what ksm_do_scan looks like:

static void ksm_do_scan(unsigned int scan_npages)
{
    struct rmap_item *rmap_item;
    struct page *uninitialized_var(page);

    while (scan_npages-- && likely(!freezing(current))) {
        cond_resched();
        rmap_item = scan_get_next_rmap_item(&page);
        if (!rmap_item)
                return;
        cmp_and_merge_page(page, rmap_item);
        put_page(page);
    }
}

I tested this on another system that had been setup with Kernel version 4.4.0-31, and ksm_do_scan() showed up on the list of available_filter_functions (even though it had the same code as the 4.10.12 version). So I figured it must have something to do with how The 4.10.12 Kernel was configured, but I'm not sure. All of recommended .config options that I've seen so far are enabled:

CONFIG_FUNCTION_TRACER=y
CONFIG_FUNCTION_GRAPH_TRACER=y
CONFIG_STACK_TRACER=y
CONFIG_DYNAMIC_FTRACE=y

Finally, I know that ftrace blacklists functions that are annotated with __init and __devinit because kernel init functions are loaded during initialization and removed when initialization is done, but ksm_do_scan doesn't contain either of those annotations.

Is there a specific way to write functions so that they are recognized by ftrace as available_filter_functions (that my be kernel version specific)?

MangoOfFury
  • 97
  • 3
  • 11
  • 1
    It might be that in former kernel compiler inlined it, that's why ftrace lost track. You may instrument the function in question explicitly: http://lxr.free-electrons.com/source/Documentation/trace/tracepoints.txt – 0andriy Apr 28 '17 at 19:46
  • interesting. Are there downsides to doing this as opposed to trace simply being able to find the function? – MangoOfFury Apr 28 '17 at 22:56
  • Possible duplicate of [How to make a linux kernel function available to ftrace function\_graph tracer?](https://stackoverflow.com/questions/15271551/how-to-make-a-linux-kernel-function-available-to-ftrace-function-graph-tracer) – Ciro Santilli OurBigBook.com Jun 24 '17 at 20:45

0 Answers0