Re: [PATCH 2/5][RFC] tracing: move function profiler data out offunction struct

From: Steven Rostedt
Date: Wed Mar 25 2009 - 14:16:43 EST



On Wed, 25 Mar 2009, Ingo Molnar wrote:

>
> * Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> >
> > On Wed, 25 Mar 2009, Ingo Molnar wrote:
> >
> > > > The atomic_inc_return protects against NMIs, since this is the only place
> > > > the lock is taken.
> > >
> > > i mean, if this code executes _ni_ an NMI. Or that cannot happen? We
> > > trace nmis too, dont we?
> >
> > Yes, it can execute in an NMI, but we have no issues there. If the
> > lock was taken the atomic inc is set. If an NMI comes in, it will
> > fail the atomic inc counter test and never try to take the lock.
>
> You are misunderstanding me. Can this bit:

Ah thanks,

>
> > > + if (!profile_pages->next && alloc_safe)
> > > + profile_pages->next = (void *)get_zeroed_page(GFP_ATOMIC);
>
> run in NMI context?
>
> or is alloc_safe false in that case? Even if it's safe it looks
> really messy ...

alloc_safe is true only if interrupts were enabled, preemption is enabled
and we are not in an interrupt or softirq.

So, it should fail when in NMI.

But I agree, it is messy, and I never liked it. I was trying to save
space, but the space saving is probably not worth the messy code.

For every recorded function we have:

struct ftrace_profile {
struct hlist_node *node;
unsigned long ip;
unsigned long hit;
unsigned long long calltime;
};

on x86_64 that is 40 bytes. (node is 16, ip is 8, hit is 8, calltime is 8)

Thus, a normal distro kernel has 20,000 functions, and if we were to
allocate for every function per online cpu, we have:

20K * 40 = 800K per online CPU.

But we allocate only when we use it. Though it must be warned, because
when we use it we must always be able to reference it, that memory stays
allocated. If this becomes an issue, I can add a way to clean the results
and free the memory.

I guess 800K per online CPU is not worth the messy code. I'll write up a
patch to fix that.

-- Steve

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/