mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: viro@parcelfarce.linux.theplanet.co.uk
Cc: dipankar@in.ibm.com, manfred@colorfullife.com, torvalds@osdl.org,
	davej@redhat.com, wli@holomorphy.com,
	linux-kernel@vger.kernel.org, maneesh@in.ibm.com
Subject: Re: dentry bloat.
Date: Sun, 9 May 2004 15:27:20 -0700	[thread overview]
Message-ID: <20040509152720.039f759a.akpm@osdl.org> (raw)
In-Reply-To: <20040509221712.GA17014@parcelfarce.linux.theplanet.co.uk>

viro@parcelfarce.linux.theplanet.co.uk wrote:
>
> On Sun, May 09, 2004 at 09:03:16PM +0530, Dipankar Sarma wrote:
>  
> > Actually, what may happen is that since the dentries are added
> > in the front, a double move like that would result in hash chain
> > traversal looping. Timing dependent and unlikely, but d_move_count
> > avoided that theoritical possibility. It is not about skipping
> > dentries which is safe because a miss would result in a real_lookup()
> 
> Not really.  A miss could result in getting another dentry allocated
> for the same e.g. directory, which is *NOT* harmless at all.

The d_bucket logic does look a bit odd.

		dentry = hlist_entry(node, struct dentry, d_hash);

		/* if lookup ends up in a different bucket 
		 * due to concurrent rename, fail it
		 */
		if (unlikely(dentry->d_bucket != head))
			break;

		/*
		 * We must take a snapshot of d_move_count followed by
		 * read memory barrier before any search key comparison 
		 */
		move_count = dentry->d_move_count;

There is a window between the d_bucket test and sampling of d_move_count. 
What happens if the dentry gets moved around in there?

Anyway, regardless of that, it is more efficient to test d_bucket _after_
performing the hash comparison.  And it seems saner to perform the d_bucket
check when things are pinned down by d_lock.



 25-akpm/fs/dcache.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff -puN fs/dcache.c~dentry-d_bucket-fix fs/dcache.c
--- 25/fs/dcache.c~dentry-d_bucket-fix	2004-05-09 14:06:51.816554824 -0700
+++ 25-akpm/fs/dcache.c	2004-05-09 14:07:41.932935976 -0700
@@ -975,12 +975,6 @@ struct dentry * __d_lookup(struct dentry
 		smp_read_barrier_depends();
 		dentry = hlist_entry(node, struct dentry, d_hash);
 
-		/* if lookup ends up in a different bucket 
-		 * due to concurrent rename, fail it
-		 */
-		if (unlikely(dentry->d_bucket != head))
-			break;
-
 		smp_rmb();
 
 		if (dentry->d_name.hash != hash)
@@ -991,6 +985,13 @@ struct dentry * __d_lookup(struct dentry
 		spin_lock(&dentry->d_lock);
 
 		/*
+		 * If lookup ends up in a different bucket due to concurrent
+		 * rename, fail it
+		 */
+		if (unlikely(dentry->d_bucket != head))
+			goto terminate;
+
+		/*
 		 * Recheck the dentry after taking the lock - d_move may have
 		 * changed things.  Don't bother checking the hash because we're
 		 * about to compare the whole name anyway.
@@ -1014,6 +1015,7 @@ struct dentry * __d_lookup(struct dentry
 			atomic_inc(&dentry->d_count);
 			found = dentry;
 		}
+terminate:
 		spin_unlock(&dentry->d_lock);
 		break;
 next:

_


  reply	other threads:[~2004-05-09 22:28 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20040506200027.GC26679@redhat.com>
     [not found] ` <20040506150944.126bb409.akpm@osdl.org>
     [not found]   ` <409B1511.6010500@colorfullife.com>
2004-05-08  8:23     ` Andrew Morton
2004-05-08  9:23       ` Andrew Morton
2004-05-08 10:11         ` Andrew Morton
2004-05-08 10:12           ` Andrew Morton
2004-05-08 10:28           ` viro
2004-05-08 10:41             ` Andrew Morton
2004-05-08 10:52             ` Andrew Morton
2004-05-08 10:31           ` Manfred Spraul
2004-05-08 17:28           ` Linus Torvalds
2004-05-08 18:19             ` David S. Miller
2004-05-08 19:01             ` Andrew Morton
2004-05-08 19:13               ` Linus Torvalds
2004-05-08 19:27                 ` Andrew Morton
2004-05-08 19:27                 ` Linus Torvalds
2004-05-08 20:42                   ` Dipankar Sarma
2004-05-08 20:55                     ` Andrew Morton
2004-05-08 21:19                       ` Dipankar Sarma
2004-05-09  0:10                         ` Andrew Morton
2004-05-09  2:55                           ` Linus Torvalds
2004-05-09  3:12                             ` David S. Miller
2004-05-09  3:53                               ` Linus Torvalds
2004-05-09 21:03                                 ` Matt Mackall
2004-05-10  8:27                                   ` Helge Hafting
2004-05-10  8:32                                     ` Arjan van de Ven
2004-05-10  9:46                                       ` Andrew Morton
2004-05-10 14:54                                         ` Matt Mackall
2004-05-10 16:26                                           ` Paul E. McKenney
2004-05-10 18:34                                             ` Dipankar Sarma
2004-05-09  4:12                             ` Andrew Morton
2004-05-09  4:25                               ` Linus Torvalds
2004-05-09  4:36                                 ` Andrew Morton
2004-05-09  5:14                                   ` Linus Torvalds
2004-05-09  7:36                                     ` Rodolfo Guluarte Hale
2004-05-09  9:10                                     ` Guennadi Liakhovetski
2004-05-09  9:23                                       ` viro
2004-05-09 15:35                                       ` Linus Torvalds
2004-05-09 18:11                                         ` Matt Mackall
2004-05-09 22:08                                           ` Francois Romieu
2004-05-09 23:51                                           ` Paul Jackson
2004-05-10  7:17                                         ` Florian Weimer
2004-05-10 14:12                                         ` Rik van Riel
2004-05-09  4:43                                 ` Linus Torvalds
2004-05-09  7:28                     ` Manfred Spraul
2004-05-09 15:33                       ` Dipankar Sarma
2004-05-09 22:17                         ` viro
2004-05-09 22:27                           ` Andrew Morton [this message]
2004-05-11  5:26                             ` Maneesh Soni
2004-05-10 18:39                           ` Dipankar Sarma
2004-05-11  5:17                             ` Maneesh Soni
2004-05-08 20:13                 ` Dipankar Sarma
2004-10-06 12:58                   ` Maneesh Soni
2004-05-11 20:22                     ` Andrew Morton
2004-05-14 10:33                       ` Raghavan
2004-05-14 10:50                         ` Paul Jackson
2004-05-14 11:04                           ` Jens Axboe
2004-05-14 11:14                             ` Paul Jackson
2004-05-14 11:24                               ` Dipankar Sarma
2004-05-14 11:24                               ` Jens Axboe
2004-05-14 11:30                                 ` Paul Jackson
2004-05-14 11:18                         ` Dipankar Sarma
2004-05-14 14:44                           ` Linus Torvalds
2004-05-08 21:00               ` Dipankar Sarma

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=20040509152720.039f759a.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=davej@redhat.com \
    --cc=dipankar@in.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maneesh@in.ibm.com \
    --cc=manfred@colorfullife.com \
    --cc=torvalds@osdl.org \
    --cc=viro@parcelfarce.linux.theplanet.co.uk \
    --cc=wli@holomorphy.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®