summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/dict.c
Commit message (Collapse)AuthorAgeFilesLines
* dict: optimize dict_serialized_length_lk functionMohit Agrawal2020-07-311-38/+9
| | | | | | | | | | | | To return the length of searlized dictionary the function iterates full dictionary and access every key value member of the dictionary.Instead of iterating full dictionary introduce a variable totkvlen at dictionary to save the key value length at the time of storing key/value pair in the dictionary. Change-Id: Ie8cfdea1cc335bce51f59179281df3c89afab68b Fixes: #1395 Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
* libglusterfs: fix warnings issued with gcc-10 -Wtype-limitsDmitry Antipov2020-07-191-65/+94
| | | | | | | | | | | | | dict.c:1129:16: warning: comparison is always false due to limited range of data type [-Wtype-limits] dict.c:1129:38: warning: comparison is always false due to limited range of data type [-Wtype-limits] dict.c:1151:16: warning: comparison is always false due to limited range of data type [-Wtype-limits] dict.c:1151:39: warning: comparison is always false due to limited range of data type [-Wtype-limits] Improve error checking and unify to common style as well. Change-Id: Ia4f890bfaaf4e29c8514ee7e4d824d69020b9332 Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru> Updates: #1002
* libglusterfs-xlator: structure loggingyatipadia2020-02-141-55/+46
| | | | | | | | convert all gf_msg() to gf_smsg() Change-Id: Id542e05faadb8041b472a2298c71fe62730e65fc Updates: #657 Signed-off-by: yatipadia <ypadia@redhat.com>
* dictionary: remove the 'extra_free' parameterYaniv Kaul2020-01-211-1/+0
| | | | | | | | | | | | | | | This parameter may have been used in the past, but is no longer needed. Removing it and the few locations it was actually referenced. This allows to remove an extra memdup as well, that was not needed in the 1st place in server_setvolume() and unserialize_rsp_direntp() functions. A followup separate patch will remove extra_stdfree parmeter from the dictionary structure. Change-Id: Ica0ff0a330672373aaa60e808b7e76ec489a0fe3 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* dict: use the free_pair's key presence or NULL as a sign of use.Yaniv Kaul2020-01-131-17/+15
| | | | | | | | | | | | | Instead of using a boolean parameter, we can use the key variable. If it's NULL, the pair is not used and can be used. Otherwise, it's in use - don't use. It saves this annoying boolean, which causes the compiler (or us explicitly) to pad with additional bytes the dict struct. Change-Id: I89f52db57f35b3ef8acf57b7de2cee37f5d18e06 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* common-utils.c: add gf_strn2boolean() functionYaniv Kaul2019-11-271-1/+1
| | | | | | | | | | | | | | | | | | | | | The function takes a string and its length and based on it returns if it's a boolean. It's identical in functionality to gf_string2boolean only with far less string comparisons since it takes into account the length of the string. dict_get_str_boolean() has been converted to use it. Other cases of gf_string2boolean() across the code base can be converted as well, but more importantly, they should be converted from dict_get_str() and then calling to gf_string2boolean to simply call dict_get_str_boolean(), which would take care of this for them. This is therefore a first step in the conversion. Change-Id: I9ee93abfc676f6e123a3919d8df8c25e8848b799 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* Revert "dict.c: remove redundant checks"MOHIT AGRAWAL2019-11-151-27/+103
| | | | | | | | | | This patch floods of dict_log at the time accessing key from dict if dict is not valid so revert the patch. This reverts commit ccf33e789f2cbd202e21340f684e2140d844a129. Change-Id: I81fa3b080a2f784254b519044ad284858583ec66 updates: bz#1193929
* libglusterfs/dict.c: Fix memory leaks.Xi Jinyu2019-11-121-0/+11
| | | | | | fixes: bz#1771365 Change-Id: Id31687c4704cbbfea1084f912ed0420c7d1cc1ec Signed-off-by: Xi Jinyu <xijinyu@cmss.chinamobile.com>
* dict.c: remove redundant checksYaniv Kaul2019-11-071-103/+27
| | | | | | | | | It removes ~2% of the object size, and did not add meaningful checks whatsoever or to readability (IMHO). Change-Id: I54346c2af47dcab13bd8d5c8ad52fc765e6afad4 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* dict.c: remove one strlen() done under lock.Yaniv Kaul2019-11-051-10/+12
| | | | | | | | It's not needed in some cases, where we can pass the key length. Change-Id: I2e8ed0b69c50a35f5858bae7c1755a0dfd2c77e5 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* dict.{c,h}: remove the lock from the _data structYaniv Kaul2019-10-111-4/+0
| | | | | | | | | I'm not sure why it was there and I did not see any use for it. In the hope I did not miss anything, I removed it. Change-Id: I02fa2e8e2a598b488fddbff4c7168dc4a41929b2 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* dict.c: dict_unserialize() can use dict_addn()Yaniv Kaul2019-07-291-1/+1
| | | | | | | | Since we know the keylen, we can use dict_addn() instead of dict_add(). Change-Id: Iebe77faa1a20ec132cba5fb85b3d2ea63339181d updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* ctime: Set mdata xattr on legacy filesKotresh HR2019-07-221-0/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | Problem: The files which were created before ctime enabled would not have "trusted.glusterfs.mdata"(stores time attributes) xattr. Upon fops which modifies either ctime or mtime, the xattr gets created with latest ctime, mtime and atime, which is incorrect. It should update only the corresponding time attribute and rest from backend Solution: Creating xattr with values from brick is not possible as each brick of replica set would have different times. So create the xattr upon successful lookup if the xattr is not created Note To Reviewers: The time attributes used to set xattr is got from successful lookup. Instead of sending the whole iatt over the wire via setxattr, a structure called mdata_iatt is sent. The mdata_iatt contains only time attributes. Change-Id: I5e535631ddef04195361ae0364336410a2895dd4 fixes: bz#1593542 Signed-off-by: Kotresh HR <khiremat@redhat.com>
* multiple files: another attempt to remove includesYaniv Kaul2019-06-141-6/+0
| | | | | | | | | | | | | | | | | | There are many include statements that are not needed. A previous more ambitious attempt failed because of *BSD plafrom (see https://review.gluster.org/#/c/glusterfs/+/21929/ ) Now trying a more conservative reduction. It does not solve all circular deps that we have, but it does reduce some of them. There is just too much to handle reasonably (dht-common.h includes dht-lock.h which includes dht-common.h ...), but it does reduce the overall number of lines of include we need to look at in the future to understand and fix the mess later one. Change-Id: I550cd001bdefb8be0fe67632f783c0ef6bee3f9f updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* glusterd: Optimize code to copy dictionary in handshake code pathMohit Agrawal2019-05-311-5/+1
| | | | | | | | | | | | | Problem: While high no. of volumes are configured around 2000 glusterd has bottleneck during handshake at the time of copying dictionary Solution: To avoid the bottleneck serialize a dictionary instead of copying key-value pair one by one Change-Id: I9fb332f432e4f915bc3af8dcab38bed26bda2b9a fixes: bz#1711297 Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
* Replace memdup() with gf_memdup()Vijay Bellur2019-04-121-2/+2
| | | | | | | | | memdup() and gf_memdup() have the same implementation. Removed one API as the presence of both can be confusing. Change-Id: I562130c668457e13e4288e592792872d2e49887e updates: bz#1193929 Signed-off-by: Vijay Bellur <vbellur@redhat.com>
* core: fix volume heal to avoid "invalid argument"Rinku Kothiya2019-03-051-2/+2
| | | | | | | | | | | This patch avoids printing of "invalid argument" unless loglevel is set to GF_LOG_DEBUG. fixes : bz#1654021 Change-Id: I0e3d43bc627526f696b12921081342ca9b4a5f84 fixes: bz#1654021 Signed-off-by: Rinku Kothiya <rkothiya@redhat.com>
* core: move "dict is NULL" logs to DEBUG log levelMilind Changire2019-02-011-2/+2
| | | | | | | | | Too many logs get printed if dict_ref() and dict_unref() are passed NULL pointer. fixes: bz#1671213 Change-Id: I18afd849d64318f68baa7b549ee310dac0e1e786 Signed-off-by: Milind Changire <mchangir@redhat.com>
* core: move logs which are only developer relevant to DEBUG levelAmar Tumballi2019-01-231-3/+3
| | | | | | | | | | | We had only changed the log level to DEBUG in release branch earlier. But considering 90%+ of our deployments happen in same env, we can look at these specific logs on need basis. With this change, the master branch will be easier to debug with lesser logs. Change-Id: I4157a7ec7d5ec9c2948b2bbc1e4cb8317f28d6b8 Updates: bz#1666833 Signed-off-by: Amar Tumballi <amarts@redhat.com>
* core: Resolve dict_leak at the time of destroying graphMohit Agrawal2019-01-141-6/+0
| | | | | | | | | | | | Problem: In gluster code some of the places it call's get_new_dict to create a dictionary without taking reference so at the time of dict_unref it has become a leak Solution: To resolve the same call dict_new instead of get_new_dict updates bz#1650403 Change-Id: I3ccbbf5af07079a4fa09aad2cd0458c8625b2f06 Signed-off-by: Mohit Agrawal <moagrawal@redhat.com>
* libglusterfs: Move devel headers under glusterfs directoryShyamsundarR2018-12-051-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | libglusterfs devel package headers are referenced in code using include semantics for a program, this while it works can be better especially when dealing with out of tree xlator builds or in general out of tree devel package usage. Towards this, the following changes are done, - moved all devel headers under a glusterfs directory - Included these headers using system header notation <> in all code outside of libglusterfs - Included these headers using own program notation "" within libglusterfs This change although big, is just moving around the headers and making it correct when including these headers from other sources. This helps us correctly include libglusterfs includes without namespace conflicts. Change-Id: Id2a98854e671a7ee5d73be44da5ba1a74252423b Updates: bz#1193929 Signed-off-by: ShyamsundarR <srangana@redhat.com>
* libglusterfs/src/dict.c : consistent initialization of parameters.Yaniv Kaul2018-11-271-60/+29
| | | | | | | | | | | | | | | | Some were assigned NULL, for no good reason, some were assigned proper initial value. Made them all consistent, as much as possible, to be assigned reasonable initial values. No expected functional changes (and I also assume the compiler already did most of this work behind the scenes anyway, so no performance implications either). Compile-tested only! updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Change-Id: I2bc0d4f2221124b5f9ef6150c86b7259074e7013
* libglusterfs/src/dict.c : use xxhash64 for hashing.Yaniv Kaul2018-09-171-13/+13
| | | | | | | | | | | | | | | | | | As part of a larger effort to consolidate hash functions and use a faster, with less collissions, I've moved to use xxhash as the hashing function for the dictionary. Note: I'm using only 32 bits of the hashes, as the hash field is currently a 32 bit variable. There's room (since the struct is not packed) to move to use a 64bit variable. Donno how it'll affect performance. Only compile-tested! updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Change-Id: Ie244efd1368234e54dd5957ee1ae5bebd7d9409a
* Land part 2 of clang-format changesGluster Ant2018-09-121-2280/+2201
| | | | | Change-Id: Ia84cc24c8924e6d22d02ac15f611c10e26db99b4 Signed-off-by: Nigel Babu <nigelb@redhat.com>
* Some (mgmt) xlators: use dict_{setn|getn|deln|get_int32n|set_int32n|set_strn}Yaniv Kaul2018-09-091-0/+45
| | | | | | | | | | | | | | | | | | | | | In a previous patch (https://review.gluster.org/20769) we've added the key length to be passed to dict_* funcs, to remove the need to strlen() it. This patch moves some xlators to use it. - It also adds dict_get_int32n which was missing. - It also reduces the size of some key variables. They were set to 1024b or PATH_MAX, where sometimes 64 bytes were really enough. Please review carefully: 1. That I did not reduce some the size of the key variables too much. 2. That I did not mix up some keys. Compile-tested only! Change-Id: Ic729baf179f40e8d02bc2350491d4bb9b6934266 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* libglusterfs/src/dict.c: remove memcpy(), gf_asprintf -> asprintfYaniv Kaul2018-09-061-216/+67
| | | | | | | | | | | | | | | | | | | | | 1. We don't need a temp. string to strotol(), we can use data->data. 2. We don't need the gf_asprintf, when a regular asprintf would do. 3. No need to CALLOC the data, can MALLOC, since we are going to populate most of the fields anyway. 4. Removed is_const member - it was not used. 5. Turned is_static to a gf_boolean_t 6. Turned another get_mem0 to get_mem (in dict_set_lk() func) 7. Remove dict_set_ptr - was exactly the same as dict_set_static_ptr (apart from the 'static' bit) and no one was using it. 8. Removed is_static from the dictionary object. Did not seem to be very useful. Compile-tested only! updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Change-Id: I7b1f6320867b154be4a94033819407f7e51cf38c
* dict: handle negative key/value length while unserializeAmar Tumballi2018-09-051-0/+7
| | | | | | Fixes: bz#1625089 Change-Id: Ie56df0da46c242846a1ba51ccb9e011af118b119 Signed-off-by: Amar Tumballi <amarts@redhat.com>
* libglusterfs/src/dict.c: fix to handle key=NULL.Yaniv Kaul2018-08-311-10/+31
| | | | | | | | | | | We don't want to strlen NULL strings. Compile-tested only! updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Change-Id: Id795998693ba410dbd80df962d48956a9e4164c4
* libglusterfs/src/dict.c: allocate memory accurately.Yaniv Kaul2018-08-301-23/+8
| | | | | | | | | | | | | | | | | | I suspect we've allocated and then set to '\0' an additional byte for no reason: gf_asprintf() allocates enough inc. the terminating null; data->len took that additional byte into account; memcpy() it back took care of that terminating null byte as well. Also, unrelated, implemented str_to_data() via strn_to_data(). Compile-tested only! updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Change-Id: I32c90e12974f51a0fbc0cfaebf9bd0fd722adc11
* libglusterfs/src/dict.{c,h}: Introduce dict_setn, dict_addn, dict_addn and ↵Yaniv Kaul2018-08-271-6/+140
| | | | | | | | | | | | | | | | | | | | | | others. They all take as a parameter the key length, instead of strlen() it. In most cases, we know the key length, we just never bothered to save and pass it along. (We most likely sprintf'ed it earlier and the return value could have been used). A more interesting addition is dict_set_nstrn() [horrible name. Ideas are welcome]. It accepts both the string length and the key length and avoids strlen() both. Some of it can be calculated on compile-time, btw. For example: dict_set_str (dict, "key", "all"); Should become: dict_set_nstrn (dict, "key", sizeof ("key"), "all", sizeof ("all")); Compile-tested only! Change-Id: Ic2667f445f6c2e22e279505f5ad435788b4b668c updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* libglusterfs/src/dict.c: perform hash calc not under lock.Yaniv Kaul2018-08-271-12/+26
| | | | | | | | | | | If possible, perform the key hash calculation not under the dictionary lock. Compile-tested only! Change-Id: I88b6ed4eff6660d8334bc08ca4eebf61960e3ca1 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* dict.c: fix indentionYaniv Kaul2018-08-271-1/+1
| | | | | | | | updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Change-Id: I3f210ae236f778fd0e8e7a17d01da21f65cb4e4b
* dict.c: do not strlen if not needed.Yaniv Kaul2018-08-271-61/+51
| | | | | | | | | | | | Use the output of sprintf(). Also, constify and initialize parameters properly. Only compile-tested! Change-Id: I33870afbe14bc1292fb08115e878d48c00a43bee updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* libglusterfs/src/dict.c: Move to GF_MALLOC() instead of GF_CALLOC() when ↵Yaniv Kaul2018-08-221-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | possible It doesn't make sense to calloc (allocate and clear) memory when the code right away fills that memory with data. It may be optimized by the compiler, or have a microscopic performance improvement. In some cases, also changed allocation size to be sizeof some struct or type instead of a pointer - easier to read. In some cases, removed redundant strlen() calls by saving the result into a variable. 1. Only done for the straightforward cases. There's room for improvement. 2. Please review carefully, especially for string allocation, with the terminating NULL string. Only compile-tested! updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com> Change-Id: Iea9098b9ec0a82a866fbc5836514b1b317daefa1
* dict.c: ensure hash is done in the right place.Yaniv Kaul2018-08-201-29/+32
| | | | | | | | | The hash should be done outside of locks, whenever is possible. Change-Id: I4f8f7455702e0489a57105cf79668c7fca90e1c0 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* dict.c: copy-pasta fix (dict -> data)Yaniv Kaul2018-08-191-2/+2
| | | | | | Change-Id: Ifda14a1cc01e0fa99ff20d710eccb43296e22955 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* libglusterfs: FORWARD_NULL coverity fixSunil Kumar Acharya2018-08-161-1/+3
| | | | | | | | | | | Fixing FORWARD_NULL coverify errors in libglusterfs. CID: 1391407, 1391410 BUG: 789278 Change-Id: I3d20523005e4418759c8a72620edff7c977d2d00 updates: bz#789278 Signed-off-by: Sunil Kumar Acharya <sheggodu@redhat.com>
* All: run codespell on the code and fix issues.Yaniv Kaul2018-07-221-3/+3
| | | | | | | | | | | | Please review, it's not always just the comments that were fixed. I've had to revert of course all calls to creat() that were changed to create() ... Only compile-tested! Change-Id: I7d02e82d9766e272a7fd9cc68e51901d69e5aab5 updates: bz#1193929 Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
* md-cache: Do not invalidate cache post set/remove xattrPoornima G2018-07-111-2/+75
| | | | | | | | | | | | | | | Since setxattr and removexattr fops cbk do not carry poststat, the stat cache was being invalidated in setxatr/remoxattr cbk. Hence the further lookup wouldn't be served from cache. To prevent this invalidation, md-cache is modified to get the poststat in set/removexattr_cbk in dict. Co-authored with Xavi Hernandez. Change-Id: I6b946be2d20b807e2578825743c25ba5927a60b4 fixes: bz#1586018 Signed-off-by: Xavi Hernandez <xhernandez@redhat.com> Signed-off-by: Poornima G <pgurusid@redhat.com>
* libglusterfs: fix comparison of a NULL dict with a non-NULL dictXavi Hernandez2018-04-181-8/+8
| | | | | | | | | | Function are_dicts_equal() had a bug when the first argument was NULL and the second one wasn't NULL. In this case it incorrectly returned that the dicts were different when they could be equal. Fixes: bz#1566732 Change-Id: I0fc245c2e7d1395865a76405dbd05e5d34db3273 Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
* Quota: heal directory on newly added bricks when quota limit is reachedSanoj Unnikrishnan2018-03-281-0/+190
| | | | | | | | | | | | | | | | | Problem: if a lookup is done on a newly added brick for a path on which limit has been reached, the lookup fails to heal the directory tree due to quota. Solution: Tag the lookup as an internal fop and ignore it in quota. Since marking internal fop does not usually give enough contextual information. Introducing new flags to pass the contextual info. Adding dict_check_flag and dict_set_flag to aid flag operations. A flag is a single bit in a bit array (currently limited to 256 bits). Change-Id: Ifb6a68bcaffedd425dd0f01f7db24edd5394c095 fixes: bz#1505355 BUG: 1505355 Signed-off-by: Sanoj Unnikrishnan <sunnikri@redhat.com>
* protocol: make on-wire-change of protocol using new XDR definition.Amar Tumballi2018-01-191-209/+0
| | | | | | | | | | | | | | | | | | | | | | With this patchset, some major things are changed in XDR, mainly: * Naming: Instead of gfs3/gfs4 settle for gfx_ for xdr structures * add iattx as a separate structure, and add conversion methods * the *_rsp structure is now changed, and is also reduced in number (ie, no need for different strucutes if it is similar to other response). * use proper XDR methods for sending dict on wire. Also, with the change of xdr structure, there are changes needed outside of xlator protocol layer to handle these properly. Mainly because the abstraction was broken to support 0-copy RDMA with payload for write and read FOP. This made transport layer know about the xdr payload, hence with the change of xdr payload structure, transport layer needed to know about the change. Updates #384 Change-Id: I1448fbe9deab0a1b06cb8351f2f37488cefe461f Signed-off-by: Amar Tumballi <amarts@redhat.com>
* dict: add another type to handle backward compatibilityAmar Tumballi2018-01-171-5/+32
| | | | | | | | | | | | | | | | This new type helps to avoid excessive logs. It should be set only in case of * volume graph building (graph.y) * dict unserialize (happens once a dictionary is received on wire in old protocol) All other dict set and get should have proper check and warning logs if there is a mismatch. updates #220 Change-Id: I1cccb304a877aa80c07aaac95f10f5005e35b9c5 Signed-off-by: Amar Tumballi <amarts@redhat.com>
* dict: fix VALIDATE_DATA_AND_LOG callAtin Mukherjee2018-01-071-2/+2
| | | | | | | | | | Couple of instances doesn't pass enough number of parameters to the function resulting compilation to fail. Updates #203 Change-Id: Id8caa6fe7fc611645ad7ff11d81a2462e4ec6bab Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
* libglusterfs: Include key name in data type validationN Balachandran2018-01-051-27/+27
| | | | | | | | | | Printing the key name makes it easier for developers to figure out which keys have dict data type mismatches. Updates #337 Change-Id: I21d9a22488a4c5e5a8d991ca2d53f1e3039f7685 Signed-off-by: N Balachandran <nbalacha@redhat.com>
* dict: add more types for valuesAmar Tumballi2018-01-051-6/+149
| | | | | | | | | | Added 2 more types which are present in gluster codebase, mainly IATT and UUID. Updates #203 Change-Id: Ib6d6d6aefb88c3494fbf93dcbe08d9979484968f Signed-off-by: Amar Tumballi <amarts@redhat.com>
* dict: support better on-wire transferAmar Tumballi2017-12-271-67/+219
| | | | | | | | | | | | | | | This patch brings data type awareness to dictionary, and also makes sure valid data is properly sent to the other side of the wire using XDR. Next step is to allow people to add more data types (for example, Bool, UUID, iatt etc), and then make it part of every fop signature in wire. Fixes #203 Change-Id: Ie0eee2db847bea2bf7dad80dec89ce3e7c5917c1 Signed-off-by: Amar Tumballi <amarts@redhat.com>
* glusterfs: Use gcc builtin ATOMIC operator to increase/decreate refcount.Mohit Agrawal2017-12-121-25/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: In glusterfs code base we call mutex_lock/unlock to take reference/dereference for a object.Sometime it could be reason for lock contention also. Solution: There is no need to use mutex to increase/decrease ref counter, instead of using mutex use gcc builtin ATOMIC operation. Test: I have not observed yet how much performance gain after apply this patch specific to glusterfs but i have tested same with below small program(mutex and atomic both) and get good difference. static int numOuterLoops; static void * threadFunc(void *arg) { int j; for (j = 0; j < numOuterLoops; j++) { __atomic_add_fetch (&glob, 1,__ATOMIC_ACQ_REL); } return NULL; } int main(int argc, char *argv[]) { int opt, s, j; int numThreads; pthread_t *thread; int verbose; int64_t n = 0; if (argc < 2 ) { printf(" Please provide 2 args Num of threads && Outer Loop\n"); exit (-1); } numThreads = atoi(argv[1]); numOuterLoops = atoi (argv[2]); if (1) { printf("\tthreads: %d; outer loops: %d;\n", numThreads, numOuterLoops); } thread = calloc(numThreads, sizeof(pthread_t)); if (thread == NULL) { printf ("calloc error so exit\n"); exit (-1); } __atomic_store (&glob, &n, __ATOMIC_RELEASE); for (j = 0; j < numThreads; j++) { s = pthread_create(&thread[j], NULL, threadFunc, NULL); if (s != 0) { printf ("pthread_create failed so exit\n"); exit (-1); } } for (j = 0; j < numThreads; j++) { s = pthread_join(thread[j], NULL); if (s != 0) { printf ("pthread_join failed so exit\n"); exit (-1); } } printf("glob value is %ld\n",__atomic_load_n (&glob,__ATOMIC_RELAXED)); exit(0); } time ./thr_count 800 800000 threads: 800; outer loops: 800000; glob value is 640000000 real 1m10.288s user 0m57.269s sys 3m31.565s time ./thr_count_atomic 800 800000 threads: 800; outer loops: 800000; glob value is 640000000 real 0m20.313s user 1m20.558s sys 0m0.028 Change-Id: Ie5030a52ea264875e002e108dd4b207b15ab7cc7 Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
* dict: Fix several coverity issues in dictMohit Agrawal2017-11-151-10/+34
| | | | | | | | | | | | | This patch fixes issues 230,592,593,110,63 from [1] [1] https://download.gluster.org/pub/gluster/glusterfs/static-analysis/master/glusterfs-coverity/2017-10-30-9aa574a5/html/ Note: Resolve FORWARD_NULL coverity issue in glusterfs_ctx_new is also fixed with this patch. BUG: 789278 Change-Id: Ic4199a144a14cc9ead7366fb1c9699197141bc86 Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
* cluster/ec: Improve performance with xattrop updateSunil Kumar Acharya2017-10-061-2/+23
| | | | | | | | | | | | Existing EC code updates the xattr on the subvolume in a sequential pattern resulting in very poor performance. With this fix EC now updates the xattr on the subvolume in parallel which improves the xattr update performance. BUG: 1445663 Change-Id: I3fc40d66db0b88875ca96a9fa01002ba386c0486 Signed-off-by: Sunil Kumar Acharya <sheggodu@redhat.com>