]> git.apps.os.sepia.ceph.com Git - ceph.git/commit
common: Improve linux dcache hash algorithm 11529/head
authorYibo Cai <yibo.cai@linaro.org>
Fri, 17 Jun 2016 09:51:47 +0000 (17:51 +0800)
committerNathan Cutler <ncutler@suse.com>
Wed, 9 Nov 2016 11:57:23 +0000 (12:57 +0100)
commit3f708df8638f49f465d70e826495e45d23c9aed2
tree64b2dae6d2a88bbb09cd8f7825b9c5a9ea12ead4
parent0c38c464fff2280a6345b470f1c83aa6229776cc
common: Improve linux dcache hash algorithm

In ceph_str_hash_linux(), hash value is defined as unsigned long,
which is 8 bytes on 64-bit platforms when compiled with gcc. But
the return value is truncated to 4 bytes, and there's no need to
preserve 8 bytes intermediate value in the algorithm. The compiler
doesn't figure out this fact and produces redundant code.

After removing the "long" definition, this route runs much faster.
Following result are tested on x86_64 and aarch64 platforms, built
by gcc 5.3.1 with optimization level -O2. Same output is observed
with gcc 4.8.4 and -O3 optimization.

ARM Cortex-A57
+---------------+--------------+---------------+-------------+
| String Length | Time w/ long | Time w/o long | Improvement |
+---------------+--------------+---------------+-------------+
| 32            | 0.088 us     | 0.067 us      | 24%         |
+---------------+--------------+---------------+-------------+
| 4096          | 10.26 us     | 8.20 us       | 20%         |
+---------------+--------------+---------------+-------------+
| 65536         | 164 us       | 131 us        | 20%         |
+---------------+--------------+---------------+-------------+
1048576       | 2624 us      | 2099 us       | 20%         |
+---------------+--------------+---------------+-------------+

Intel i7-4790
+---------------+--------------+---------------+-------------+
| String Length | Time w/ long | Time w/o long | Improvement |
+---------------+--------------+---------------+-------------+
| 32            | 0.033 us     | 0.028 us      | 16.3%       |
+---------------+--------------+---------------+-------------+
| 4096          | 3.87 us      | 3.64 us       | 6.2%        |
+---------------+--------------+---------------+-------------+
| 65536         | 61.3 us      | 57.8 us       | 5.7%        |
+---------------+--------------+---------------+-------------+
1048576       | 973 us       | 917 us        | 5.8%        |
+---------------+--------------+---------------+-------------+

Signed-off-by: Yibo Cai <yibo.cai@linaro.org>
(cherry picked from commit 0cdee4bf0a55f63321957729c50caf17e7cd3b4a)
src/common/ceph_hash.cc