Re: [PATCH libnetfilter_queue v2] src: Add faster alternatives to pktb_alloc()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Pablo,

On Wed, Feb 19, 2020 at 07:04:10PM +0100, Pablo Neira Ayuso wrote:
> On Sat, Feb 01, 2020 at 05:21:27PM +1100, Duncan Roe wrote:
> > Functions pktb_alloc_data, pktb_make and pktb_make_data are defined.
> > The pktb_make pair are syggested as replacements for the pktb_alloc (now) pair
> > because they are always faster.
> >
> > - Add prototypes to include/libnetfilter_queue/pktbuff.h
> > - Add pktb_alloc_data much as per Pablo's email of Wed, 8 Jan 2020
> >   speedup: point to packet data in netlink receive buffer rather than copy to
> >            area immediately following pktb struct
> > - Add pktb_make much like pktb_usebuf proposed on 10 Dec 2019
> >   2 sppedups: 1. Use an existing buffer rather than calloc and (later) free one.
> >               2. Only zero struct and extra parts of pktb - the rest is
> >                  overwritten by copy (calloc has to zero the lot).
> > - Add pktb_make_data
> >   3 speedups: All of the above
> > - Document the new functions
> > - Move pktb_alloc and pktb_alloc_data into the "other functions" group since
> >   they are slower than the "make" equivalent functions
> >
> > Signed-off-by: Duncan Roe <duncan_roe@xxxxxxxxxxxxxxx>
> > ---
> >  include/libnetfilter_queue/pktbuff.h |   3 +
> >  src/extra/pktbuff.c                  | 296 ++++++++++++++++++++++++++++++-----
> >  2 files changed, 261 insertions(+), 38 deletions(-)
> >
> > diff --git a/include/libnetfilter_queue/pktbuff.h b/include/libnetfilter_queue/pktbuff.h
> > index 42bc153..fc6bf01 100644
> > --- a/include/libnetfilter_queue/pktbuff.h
> > +++ b/include/libnetfilter_queue/pktbuff.h
> > @@ -4,6 +4,9 @@
> >  struct pkt_buff;
> >
> >  struct pkt_buff *pktb_alloc(int family, void *data, size_t len, size_t extra);
> > +struct pkt_buff *pktb_alloc_data(int family, void *data, size_t len);
> > +struct pkt_buff *pktb_make(int family, void *data, size_t len, size_t extra, void *buf, size_t bufsize);
> > +struct pkt_buff *pktb_make_data(int family, void *data, size_t len, void *buf, size_t bufsize);
>
> Hm, when I delivered the patch to you, I forgot that you main point
> was that you wanted to skip the memory allocation.
>
> I wonder if all these new functions can be consolidated into one
> single function, something like:
>
>         struct pkt_buff *pktb_alloc2(int family, void *head, size_t head_size, void *data, size_t len, size_t extra);
>
> The idea is that:
>
> * head is the memory area that is large enough for the struct pkt_buff
>   (metadata). You can add a new pktb_head_size() function that returns
>   the size of opaque struct pkt_buff structure (whose layout is not
>   exposed to the user). I think you can this void *buf in your pktb_make
>   function.
>
> * data is the memory area to store the network packet itself.

Wait, you need data & len to describe where the data is *now*. You need an extra
buf, buflen pair for where to put it.
>
> Then, you can allocate head and data in the stack and skip
> malloc/calloc.
>
> Would this work for you? I would prefer if there is just one single
> advanced function to do this.
>
> Thanks for your patience.

I think I can do as you requested.

Just one thing: do you really think pktb_alloc2 is a good name when users *must
not* call pktb_free? pktb_put would have been good but it's already taken.

Perhaps pktb_alloc2 could set a flag for pktb_free to become a no-op and maybe
issue a warning the first time it is called - would that be worth doing?

In pktb_alloc2, if extra == 0 then buf can be NULL and buflen 0, since the data
will be left in place. That way, we get a single entry point doing as much
optimising as possible.

Cheers ... Duncan.



[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux