Thread (1 message) 1 message, 1 author, 2018-10-06

Re: [RFC PATCH bpf-next v4 4/7] bpf: add bpf queue and stack maps

From: Alexei Starovoitov <hidden>
Date: 2018-10-06 01:41:41

On Thu, Oct 04, 2018 at 10:40:55PM -0500, Mauricio Vasquez wrote:
quoted
quoted
+	/* 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.
quoted
The memory waste becomes quite large when max_entries are high.
Yes, you are right, we have the different choices described below.
quoted
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help