<div dir="ltr"><div>Niels,</div><div><br></div><div> Thanks for your reply, I think these built-in function provides by gcc and it should support most of the architecture.</div><div> In your view what could be the archietecure that does not support these builtin function ??</div><div> </div><div><br></div><div>Regards</div><div>Mohit Agrawal</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 27, 2017 at 1:20 PM, Niels de Vos <span dir="ltr"><<a href="mailto:ndevos@redhat.com" target="_blank">ndevos@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Wed, Sep 27, 2017 at 12:55:37PM +0530, Mohit Agrawal wrote:<br>
> Hi,<br>
><br>
> I was checking code of internal data structures (dict,fd,rpc_clnt etc.)<br>
> those we use in glusterfs to store data.<br>
> Usually we use common pattern to take reference of data structure in<br>
> xlator level, in ref function we do take lock(mutex_lock)<br>
> and update(increase) reference counter and in unref function we do take<br>
> lock and decrease reference counter and<br>
> check if ref counter is become 0 after decrease then destroy object.<br>
><br>
> I think to update reference counter we don't need to take a lock, we can<br>
> use atomic in-built function those<br>
> can improve performance<br>
<br>
</span>The below is not portable for all architectures. However we have<br>
refcount.h in libglusterfs/src/ which hides the portability things. One<br>
of the big advantages to use this, is that the code for reference<br>
counting is the same everywhere. Some structures have been updated with<br>
GF_REF_* macros, more can surely be done.<br>
<br>
For other more basic counters that do not function as reference counter,<br>
the libglusterfs/src/atomic.h macros can be used. The number of lock<br>
instructions on modern architectures can be reduced considerably this<br>
way. It will likely come with a performance increase, but the usage of a<br>
standard API makes the code simpler to understand and that is my main<br>
interest :)<br>
<br>
Obviously I'm all for replacing the lock+count+unlock sequences for many<br>
structures!<br>
<br>
Thanks,<br>
Niels<br>
<span class=""><br>
<br>
><br>
> For ex: Below is a example for specific to dict_ref/unref<br>
> To increase refCount we can use below built-in function<br>
> dict_ref<br>
> {<br>
> __atomic_add_fetch (&this->refcount, 1, __ATOMIC_SEQ_CST);<br>
><br>
> }<br>
><br>
> dict_unref<br>
> {<br>
> __atomic_sub_fetch (&this->refcount, 1, __ATOMIC_SEQ_CST);<br>
> __atomic_load (&this->refcount, &ref, __ATOMIC_SEQ_CST);<br>
> }<br>
><br>
> In the same way we can use for all other shared data-structure also in<br>
> case of take/release reference.<br>
><br>
> I have not tested yet how much performance improvement we can gain but i<br>
> think there should be some improvement.<br>
> Please share your input on this, appreciate your input.<br>
><br>
> Regards<br>
> Mohit Agrawal<br>
<br>
</span>> ______________________________<wbr>_________________<br>
> Gluster-devel mailing list<br>
> <a href="mailto:Gluster-devel@gluster.org">Gluster-devel@gluster.org</a><br>
> <a href="http://lists.gluster.org/mailman/listinfo/gluster-devel" rel="noreferrer" target="_blank">http://lists.gluster.org/<wbr>mailman/listinfo/gluster-devel</a><br>
<br>
</blockquote></div><br></div>