Re: [PATCH for-next v8 1/8] RDMA/rxe: Replace RB tree by xarray for indexes

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

 



On Thu, Dec 16, 2021 at 05:31:55PM -0600, Bob Pearson wrote:
> +/**
> + * rxe_pool_get_index - lookup object from index
> + * @pool: the object pool
> + * @index: the index of the object
> + *
> + * Returns: the object if the index exists in the pool
> + * and the reference count on the object is positive
> + * else NULL
> + */
> +void *rxe_pool_get_index(struct rxe_pool *pool, u32 index)
>  {
>  	struct rxe_pool_elem *elem;
>  	void *obj;
>  
> +	elem = xa_load(&pool->xarray.xa, index);
> +	if (elem && kref_get_unless_zero(&elem->ref_cnt))
>  		obj = elem->obj;
> +	else
>  		obj = NULL;
>  
>  	return obj;
>  }

This has to hold some kind of lock to protect elem from free while
calling kref_get_unless_zero().

You can hold the xa_lock() around this, or use rcu_read_lock(), but
that requires using kfree_rcu to free the memory.

Jason



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux