Re: [PATCH] fragment: add fast path

Eric Dumazet
2010-06-14T07:05:00Z

>
> Without this branch. prev needs to be initialized to zero again(of
> course, we can avoid this by moving prev = NULL in the previous
> branch). next needs an assignment, and a duplicate check if the the
> queue is empty, which is already known in the above branch. Sorry, but
> I can't see which path I slow.
>
> prev = NULL;
> for (next = qp->q.fragments; next != NULL; next = next->next) {
> if (FRAG_CB(next)->offset >= offset)
> break; /* bingo! */
> prev = next;
> }
>

Concept of 'fast path' has changed over years. It used to be cpu
instructions and cycles, its now number of memory transactions.

The only thing we need to address are the cache lines we must bring into
cpu caches, and keep code short.

These days, one cache line miss -> more than one hundred instructions
that could be done during cpu stall. cpu cycles are cheap if code
already in instruction cache.

Adding a test to avoid entering a NULL loop (no fragment is stored yet)
just bloats the code, making it larger than necessary.

You dont need the else branch :

if (prev) {
if (FRAG_CB(prev)->offset < offset) {
next = NULL;
goto found;
}
else {
next = NULL;
goto found;
}

Just write :

next = NULL;
if (prev && FRAG_CB(prev)->offset < offset)
goto found;