All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Josef Bacik <jbacik@fb.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Christoph Hellwig <hch@infradead.org>, Chris Mason <clm@fb.com>,
	linux-fsdevel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: [PATCH 3.14 111/114] vfs: fix bad hashing of dentries
Date: Mon, 15 Sep 2014 12:26:51 -0700	[thread overview]
Message-ID: <20140915192644.882764318@linuxfoundation.org> (raw)
In-Reply-To: <20140915192641.428509513@linuxfoundation.org>

3.14-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Linus Torvalds <torvalds@linux-foundation.org>

commit 99d263d4c5b2f541dfacb5391e22e8c91ea982a6 upstream.

Josef Bacik found a performance regression between 3.2 and 3.10 and
narrowed it down to commit bfcfaa77bdf0 ("vfs: use 'unsigned long'
accesses for dcache name comparison and hashing"). He reports:

 "The test case is essentially

      for (i = 0; i < 1000000; i++)
              mkdir("a$i");

  On xfs on a fio card this goes at about 20k dir/sec with 3.2, and 12k
  dir/sec with 3.10.  This is because we spend waaaaay more time in
  __d_lookup on 3.10 than in 3.2.

  The new hashing function for strings is suboptimal for <
  sizeof(unsigned long) string names (and hell even > sizeof(unsigned
  long) string names that I've tested).  I broke out the old hashing
  function and the new one into a userspace helper to get real numbers
  and this is what I'm getting:

      Old hash table had 1000000 entries, 0 dupes, 0 max dupes
      New hash table had 12628 entries, 987372 dupes, 900 max dupes
      We had 11400 buckets with a p50 of 30 dupes, p90 of 240 dupes, p99 of 567 dupes for the new hash

  My test does the hash, and then does the d_hash into a integer pointer
  array the same size as the dentry hash table on my system, and then
  just increments the value at the address we got to see how many
  entries we overlap with.

  As you can see the old hash function ended up with all 1 million
  entries in their own bucket, whereas the new one they are only
  distributed among ~12.5k buckets, which is why we're using so much
  more CPU in __d_lookup".

The reason for this hash regression is two-fold:

 - On 64-bit architectures the down-mixing of the original 64-bit
   word-at-a-time hash into the final 32-bit hash value is very
   simplistic and suboptimal, and just adds the two 32-bit parts
   together.

   In particular, because there is no bit shuffling and the mixing
   boundary is also a byte boundary, similar character patterns in the
   low and high word easily end up just canceling each other out.

 - the old byte-at-a-time hash mixed each byte into the final hash as it
   hashed the path component name, resulting in the low bits of the hash
   generally being a good source of hash data.  That is not true for the
   word-at-a-time case, and the hash data is distributed among all the
   bits.

The fix is the same in both cases: do a better job of mixing the bits up
and using as much of the hash data as possible.  We already have the
"hash_32|64()" functions to do that.

Reported-by: Josef Bacik <jbacik@fb.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Chris Mason <clm@fb.com>
Cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/dcache.c |    3 +--
 fs/namei.c  |    4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -106,8 +106,7 @@ static inline struct hlist_bl_head *d_ha
 					unsigned int hash)
 {
 	hash += (unsigned long) parent / L1_CACHE_BYTES;
-	hash = hash + (hash >> d_hash_shift);
-	return dentry_hashtable + (hash & d_hash_mask);
+	return dentry_hashtable + hash_32(hash, d_hash_shift);
 }
 
 /* Statistics gathering. */
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -34,6 +34,7 @@
 #include <linux/device_cgroup.h>
 #include <linux/fs_struct.h>
 #include <linux/posix_acl.h>
+#include <linux/hash.h>
 #include <asm/uaccess.h>
 
 #include "internal.h"
@@ -1624,8 +1625,7 @@ static inline int nested_symlink(struct
 
 static inline unsigned int fold_hash(unsigned long hash)
 {
-	hash += hash >> (8*sizeof(int));
-	return hash;
+	return hash_64(hash, 32);
 }
 
 #else	/* 32-bit case */



  parent reply	other threads:[~2014-09-15 20:13 UTC|newest]

Thread overview: 120+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-15 19:25 [PATCH 3.14 000/114] 3.14.19-stable review Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 001/114] media: xc5000: Fix get_frequency() Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 002/114] media: xc4000: " Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 003/114] media: au0828: Only alt setting logic when needed Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 005/114] media: mt9v032: fix hblank calculation Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 006/114] media: v4l: vsp1: Remove the unneeded vsp1_video_buffer video field Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 007/114] media: sms: Remove CONFIG_ prefix from Kconfig symbols Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 008/114] iommu/amd: Fix cleanup_domain for mass device removal Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 009/114] spi: orion: fix incorrect handling of cell-index DT property Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 010/114] spi: omap2-mcspi: Configure hardware when slave driver changes mode Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 011/114] s390/locking: Reenable optimistic spinning Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 013/114] firmware: Do not use WARN_ON(!spin_is_locked()) Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 014/114] tpm: missing tpm_chip_put in tpm_get_random() Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 015/114] tpm: Provide a generic means to override the chip returned timeouts Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 016/114] tpm: Properly clean sysfs entries in error path Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 017/114] CAPABILITIES: remove undefined caps from all processes Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 018/114] kernel/smp.c:on_each_cpu_cond(): fix warning in fallback path Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 019/114] mfd: omap-usb-host: Fix improper mask use Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 020/114] regulator: arizona-ldo1: remove bypass functionality Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 021/114] powerpc/mm/numa: Fix break placement Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 022/114] powerpc/mm: Use read barrier when creating real_pte Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 023/114] powerpc/pseries: Failure on removing device node Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 024/114] powerpc/pseries: Avoid deadlock on removing ddw Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 025/114] powerpc/thp: Add write barrier after updating the valid bit Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 026/114] powerpc/thp: Dont recompute vsid and ssize in loop on invalidate Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 027/114] powerpc/thp: Invalidate old 64K based hash page mapping before insert of 4k pte Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 028/114] powerpc/thp: Handle combo pages in invalidate Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 029/114] powerpc/thp: Invalidate with vpn in loop Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 030/114] powerpc/thp: Use ACCESS_ONCE when loading pmdp Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 031/114] Drivers: scsi: storvsc: Implement a eh_timed_out handler Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 032/114] Drivers: scsi: storvsc: Filter commands based on the storage protocol version Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 033/114] Drivers: scsi: storvsc: Change the limits to reflect the values on the host Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 034/114] Drivers: scsi: storvsc: Set cmd_per_lun to reflect value supported by the Host Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 035/114] Drivers: scsi: storvsc: Fix a bug in handling VMBUS protocol version Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 036/114] drivers: scsi: storvsc: Set srb_flags in all cases Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 037/114] drivers: scsi: storvsc: Correctly handle TEST_UNIT_READY failure Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 038/114] scsi_scan: Restrict sequential scan to 256 LUNs Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 039/114] scsi: add a blacklist flag which enables VPD page inquiries Greg Kroah-Hartman
2014-09-15 21:23   ` Sitsofe Wheeler
2014-09-15 19:25 ` [PATCH 3.14 040/114] scsi: do not issue SCSI RSOC command to Promise Vtrak E610f Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 041/114] scsi_transport_srp: Fix fast_io_fail_tmo=dev_loss_tmo=off behavior Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 042/114] MIPS: GIC: Prevent array overrun Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 043/114] MIPS: O32/32-bit: Fix bug which can cause incorrect system call restarts Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 044/114] MIPS: ptrace: Test correct tasks flags in task_user_regset_view() Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 045/114] MIPS: ptrace: Change GP regset to use correct core dump register layout Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 046/114] MIPS: Prevent user from setting FCSR cause bits Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 047/114] MIPS: tlbex: Fix a missing statement for HUGETLB Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 048/114] MIPS: Remove BUG_ON(!is_fpu_owner()) in do_ade() Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 049/114] MIPS: asm/reg.h: Make 32- and 64-bit definitions available at the same time Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 050/114] MIPS: OCTEON: make get_system_type() thread-safe Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 051/114] ASoC: wm8994: Prevent double lock of accdet_lock mutex on wm1811 Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 052/114] ASoC: pcm: fix dpcm_path_put in dpcm runtime update Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 053/114] ASoC: wm_adsp: Add missing MODULE_LICENSE Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 054/114] ASoC: blackfin: use samples to set silence Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 055/114] ASoC: samsung: Correct I2S DAI suspend/resume ops Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 056/114] ASoC: adau1701: fix adau1701_reg_read() Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 057/114] ASoC: max98090: Fix missing free_irq Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 058/114] ASoC: pxa: pxa-ssp: small leak in probe() Greg Kroah-Hartman
2014-09-15 19:25 ` [PATCH 3.14 059/114] ASoC: pxa-ssp: drop SNDRV_PCM_FMTBIT_S24_LE Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 061/114] ASoC: rt5640: Do not allow regmap to use bulk read-write operations Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 062/114] bfa: Fix undefined bit shift on big-endian architectures with 32-bit DMA address Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 063/114] bq2415x_charger: Fix Atomic Sleep Bug Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 064/114] ACPICA: Utilities: Fix memory leak in acpi_ut_copy_iobject_to_iobject Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 065/114] ACPI / hotplug: Check scan handlers in acpi_scan_hot_remove() Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 066/114] spi/pxa2xx: Add ACPI ID for Intel Braswell Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 067/114] ACPI: Run fixed event device notifications in process context Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 068/114] ACPI / scan: not cache _SUN value in struct acpi_device_pnp Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 069/114] ACPI / cpuidle: fix deadlock between cpuidle_lock and cpu_hotplug.lock Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 070/114] xen/events/fifo: reset control block and local HEADs on resume Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 071/114] ring-buffer: Always reset iterator to reader page Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 072/114] ring-buffer: Up rb_iter_peek() loop count to 3 Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 073/114] mnt: Only change user settable mount flags in remount Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 074/114] mnt: Move the test for MNT_LOCK_READONLY from change_mount_flags into do_remount Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 075/114] mnt: Correct permission checks in do_remount Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 076/114] mnt: Change the default remount atime from relatime to the existing value Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 077/114] mnt: Add tests for unprivileged remount cases that have found to be faulty Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 078/114] get rid of propagate_umount() mistakenly treating slaves as busy Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 079/114] fix EBUSY on umount() from MNT_SHRINKABLE Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 080/114] Bluetooth: btmrvl: wait for HOST_SLEEP_ENABLE event in suspend Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 081/114] Bluetooth: never linger on process exit Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 082/114] Bluetooth: Avoid use of session socket after the session gets freed Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 083/114] fix copy_tree() regression Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 084/114] md/raid1,raid10: always abort recover on write error Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 085/114] md/raid6: avoid data corruption during recovery of double-degraded RAID6 Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 086/114] md/raid10: fix memory leak when reshaping a RAID10 Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 087/114] md/raid10: Fix memory leak when raid10 reshape completes Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 088/114] RDMA/iwcm: Use a default listen backlog if needed Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 089/114] RDMA/uapi: Include socket.h in rdma_user_cm.h Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 090/114] xfs: ensure verifiers are attached to recovered buffers Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 091/114] xfs: quotacheck leaves dquot buffers without verifiers Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 092/114] xfs: dont dirty buffers beyond EOF Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 093/114] xfs: dont zero partial page cache pages during O_DIRECT writes Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 094/114] xfs: dont zero partial page cache pages during O_DIRECT write Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 095/114] libceph: set last_piece in ceph_msg_data_pages_cursor_init() correctly Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 096/114] libceph: add process_one_ticket() helper Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 097/114] libceph: do not hard code max auth ticket len Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 098/114] CIFS: Fix STATUS_CANNOT_DELETE error mapping for SMB2 Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 099/114] CIFS: Fix async reading on reconnects Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 100/114] CIFS: Possible null ptr deref in SMB2_tcon Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 101/114] CIFS: Fix wrong directory attributes after rename Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 102/114] vfs: add d_is_dir() Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 103/114] CIFS: Fix directory rename error Greg Kroah-Hartman
2014-09-16  5:17   ` Pavel Shilovsky
2014-09-16 14:40     ` Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 104/114] CIFS: Fix wrong filename length for SMB2 Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 105/114] CIFS: Fix wrong restart readdir for SMB1 Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 106/114] mtd/ftl: fix the double free of the buffers allocated in build_maps() Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 107/114] mtd: nand: omap: Fix 1-bit Hamming code scheme, omap_calculate_ecc() Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 108/114] blkcg: dont call into policy draining if root_blkg is already gone Greg Kroah-Hartman
2014-09-17 11:16   ` Ben Hutchings
2014-09-17 16:22     ` Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 109/114] IB/srp: Fix deadlock between host removal and multipathd Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 110/114] drm/nouveau: Bump version from 1.1.1 to 1.1.2 Greg Kroah-Hartman
2014-09-15 19:26 ` Greg Kroah-Hartman [this message]
2014-09-15 19:26 ` [PATCH 3.14 112/114] libceph: gracefully handle large reply messages from the mon Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 113/114] KEYS: Fix use-after-free in assoc_array_gc() Greg Kroah-Hartman
2014-09-15 19:26 ` [PATCH 3.14 114/114] KEYS: Fix termination condition in assoc array garbage collection Greg Kroah-Hartman
2014-09-15 21:36 ` [PATCH 3.14 000/114] 3.14.19-stable review Holger Hoffstätte
2014-09-16  1:55 ` Guenter Roeck
2014-09-16 18:41 ` Shuah Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140915192644.882764318@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=clm@fb.com \
    --cc=hch@infradead.org \
    --cc=jbacik@fb.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.