Re: [PATCH net-next 1/3] ptr_ring: add PTR_RING_BATCH
From: Michael S. Tsirkin
Date: Fri Nov 27 2026 - 13:59:42 EST
On Wed, Nov 25, 2026 at 04:23:09PM +0100, Simon Schippers wrote:
> Name the batch size in which the consumer frees entries, so that users
> of a ring can size their own work to it. The next patch uses it in veth.
>
> No functional change.
>
> Signed-off-by: Simon Schippers <simon.schippers@xxxxxxxxxxxxxx>
> ---
> include/linux/ptr_ring.h | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/ptr_ring.h b/include/linux/ptr_ring.h
> index 631c43fde4407..b851a9c170bf6 100644
> --- a/include/linux/ptr_ring.h
> +++ b/include/linux/ptr_ring.h
> @@ -27,6 +27,11 @@
> #include <asm/errno.h>
> #endif
>
> +/* Consumed entries are freed in batches of this size, unless the ring is
> + * smaller than two batches
> + */
> +#define PTR_RING_BATCH (SMP_CACHE_BYTES * 2 / (int)sizeof(void *))
> +
> struct ptr_ring {
> int producer ____cacheline_aligned_in_smp;
> spinlock_t producer_lock;
> @@ -506,7 +511,7 @@ static inline void **__ptr_ring_init_queue_alloc_noprof(unsigned int size, gfp_t
> static inline void __ptr_ring_set_size(struct ptr_ring *r, int size)
> {
> r->size = size;
> - r->batch = SMP_CACHE_BYTES * 2 / sizeof(*(r->queue));
> + r->batch = PTR_RING_BATCH;
> /* We need to set batch at least to 1 to make logic
> * in __ptr_ring_discard_one work correctly.
> * Batching too much (because ring is small) would cause a lot of
If this helps, sure:
Acked-by: Michael S. Tsirkin <mst@xxxxxxxxxx>
> --
> 2.43.0