[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20181005184139.lo3agre2tyn73csr@ast-mbp.dhcp.thefacebook.com>
Date: Fri, 5 Oct 2018 11:41:40 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Mauricio Vasquez <mauricio.vasquez@...ito.it>
Cc: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>, netdev@...r.kernel.org
Subject: Re: [RFC PATCH bpf-next v4 4/7] bpf: add bpf queue and stack maps
On Thu, Oct 04, 2018 at 10:40:55PM -0500, Mauricio Vasquez wrote:
>
> > > + /* Round up queue size to nearest power of 2 */
> > > + max_entries = index_mask + 1;
> > what's the point of roundup ?
>
> If the size of the buffer is power of two we can wrap the indexes with an
> AND operation instead of MOD.
>
> > The memory waste becomes quite large when max_entries are high.
> Yes, you are right, we have the different choices described below.
>
> >
> > If queue/stack is sized to exact max_entries,
> > then 'count' can be removed too, right?
>
> If we don't use 'count' and we want to use the AND operation for wrapping
> indexes, the max entries should be 2^ - 1 because a slot is lost to
> distinguish between full/empty queue/stack.
>
> Just to summarize, we have these options:
> 1. Allow any size, round up, use the AND operation and 'count' (current).
> 2. Allow only power of 2 sizes, use the AND operation and 'count'.
> 3. Allow any size, no roundup, use the MOD operation and leaving an empty
> slot.
>
> I prefer 1 or 2, but I don't have a strong opinion, maybe allowing only
> power of two max entries could be too limiting.
> Another consideration: is this really too bad to waste memory when user
> requires a size far away of the next power of 2?
I think there is 4th option. Neither AND nor MOD is necessary.
Pls take a look at ptr_ring implementation.
Powered by blists - more mailing lists