On Wed, Sep 27, 2017 at 01:47:00PM +0530, Mohit Agrawal wrote: > Niels, > > Thanks for your reply, I think these built-in function provides by gcc > and it should support most of the architecture. > In your view what could be the archietecure that does not support these > builtin function ?? Yes, these functions and built-in with gcc and probably clang. I think i386 does not support them, and maybe some ARM versions do not do so either. Some distributions build packages for many different architectures, so we need to make sure they can keep on doing that. Other distributions do not use gcc, and may not have support for these (or the same) atomic operations. It is not really a problem, as the atomic.h and refcount.h headers have fallback implementations (using locks, similar to the current situation). Cheers, Niels > > > Regards > Mohit Agrawal > > On Wed, Sep 27, 2017 at 1:20 PM, Niels de Vos <ndevos@xxxxxxxxxx> wrote: > > > On Wed, Sep 27, 2017 at 12:55:37PM +0530, Mohit Agrawal wrote: > > > Hi, > > > > > > I was checking code of internal data structures (dict,fd,rpc_clnt > > etc.) > > > those we use in glusterfs to store data. > > > Usually we use common pattern to take reference of data structure in > > > xlator level, in ref function we do take lock(mutex_lock) > > > and update(increase) reference counter and in unref function we do > > take > > > lock and decrease reference counter and > > > check if ref counter is become 0 after decrease then destroy object. > > > > > > I think to update reference counter we don't need to take a lock, we > > can > > > use atomic in-built function those > > > can improve performance > > > > The below is not portable for all architectures. However we have > > refcount.h in libglusterfs/src/ which hides the portability things. One > > of the big advantages to use this, is that the code for reference > > counting is the same everywhere. Some structures have been updated with > > GF_REF_* macros, more can surely be done. > > > > For other more basic counters that do not function as reference counter, > > the libglusterfs/src/atomic.h macros can be used. The number of lock > > instructions on modern architectures can be reduced considerably this > > way. It will likely come with a performance increase, but the usage of a > > standard API makes the code simpler to understand and that is my main > > interest :) > > > > Obviously I'm all for replacing the lock+count+unlock sequences for many > > structures! > > > > Thanks, > > Niels > > > > > > > > > > For ex: Below is a example for specific to dict_ref/unref > > > To increase refCount we can use below built-in function > > > dict_ref > > > { > > > __atomic_add_fetch (&this->refcount, 1, __ATOMIC_SEQ_CST); > > > > > > } > > > > > > dict_unref > > > { > > > __atomic_sub_fetch (&this->refcount, 1, __ATOMIC_SEQ_CST); > > > __atomic_load (&this->refcount, &ref, __ATOMIC_SEQ_CST); > > > } > > > > > > In the same way we can use for all other shared data-structure also in > > > case of take/release reference. > > > > > > I have not tested yet how much performance improvement we can gain > > but i > > > think there should be some improvement. > > > Please share your input on this, appreciate your input. > > > > > > Regards > > > Mohit Agrawal > > > > > _______________________________________________ > > > Gluster-devel mailing list > > > Gluster-devel@xxxxxxxxxxx > > > http://lists.gluster.org/mailman/listinfo/gluster-devel > > > > _______________________________________________ Gluster-devel mailing list Gluster-devel@xxxxxxxxxxx http://lists.gluster.org/mailman/listinfo/gluster-devel