From: Jeff Layton <jlayton@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: hch@infradead.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] make iunique use a do/while loop rather than its obscure goto loop
Date: Fri, 13 Apr 2007 15:08:38 -0400 [thread overview]
Message-ID: <461FD536.80903@redhat.com> (raw)
In-Reply-To: <20070413114214.cb9328f5.akpm@linux-foundation.org>
Andrew Morton wrote:
> On Wed, 11 Apr 2007 17:58:56 -0400
> Jeffrey Layton <jlayton@redhat.com> wrote:
>
>> A while back, Christoph mentioned that he thought that iunique ought to be
>> cleaned up to use a more conventional loop construct. This patch does that,
>> turning the strange goto loop into a do/while.
>>
>> Signed-off-by: Jeff Layton <jlayton@redhat.com>
>>
>> diff --git a/fs/inode.c b/fs/inode.c
>> index 23fc1fd..90e7587 100644
>> --- a/fs/inode.c
>> +++ b/fs/inode.c
>> @@ -689,21 +689,18 @@ ino_t iunique(struct super_block *sb, ino_t max_reserved)
>> struct inode *inode;
>> struct hlist_head * head;
>> ino_t res;
>> +
>> spin_lock(&inode_lock);
>> -retry:
>> - if (counter > max_reserved) {
>> - head = inode_hashtable + hash(sb,counter);
>> + do {
>> + if (counter <= max_reserved)
>> + counter = max_reserved + 1;
>> res = counter++;
>> + head = inode_hashtable + hash(sb, res);
>> inode = find_inode_fast(sb, head, res);
>> - if (!inode) {
>> - spin_unlock(&inode_lock);
>> - return res;
>> - }
>> - } else {
>> - counter = max_reserved + 1;
>> - }
>> - goto retry;
>> -
>> + } while (inode != NULL);
>> + spin_unlock(&inode_lock);
>> +
>> + return res;
>> }
>>
>
> hm.
>
> ino_t iunique(struct super_block *sb, ino_t max_reserved)
> {
> static ino_t counter;
> struct inode *inode;
> struct hlist_head * head;
> ino_t res;
>
> spin_lock(&inode_lock);
> do {
> if (counter <= max_reserved)
> counter = max_reserved + 1;
> res = counter++;
> head = inode_hashtable + hash(sb, res);
> inode = find_inode_fast(sb, head, res);
> } while (inode != NULL);
> spin_unlock(&inode_lock);
>
> return res;
> }
>
> The counter-vs-max_reserved test can be moved outside the loop, can't it?
>
No. If the counter wraps while we're looping, then we'll need to skip
past the "reserved" inode numbers. So we need to check this on every
loop iteration. We could potentially put that in an "unlikely" if you
think that would be better.
> Shouldn't counter be per-sb?
I doubt it really matters too much, but it could potentially be more
efficient to do that, especially after a wraparound on the counter. It
might be reasonable to make new_inode use a per-sb counter as well. Do
you think it's worth respinning?
-- Jeff
next prev parent reply other threads:[~2007-04-13 19:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-11 21:58 [PATCH] make iunique use a do/while loop rather than its obscure goto loop Jeffrey Layton
2007-04-13 18:42 ` Andrew Morton
2007-04-13 19:08 ` Jeff Layton [this message]
2007-04-13 19:55 ` Andrew Morton
2007-06-23 8:08 ` Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2007-01-30 15:45 Jeffrey Layton
2007-01-31 8:16 ` Christoph Hellwig
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=461FD536.80903@redhat.com \
--to=jlayton@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=hch@infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).