* [PATCH] make iunique use a do/while loop rather than its obscure goto loop
@ 2007-01-30 15:45 Jeffrey Layton
2007-01-31 8:16 ` Christoph Hellwig
0 siblings, 1 reply; 7+ messages in thread
From: Jeffrey Layton @ 2007-01-30 15:45 UTC (permalink / raw)
To: linux-fsdevel, linux-kernel; +Cc: hch
While working on a case, 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;
}
EXPORT_SYMBOL(iunique);
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] make iunique use a do/while loop rather than its obscure goto loop
2007-01-30 15:45 [PATCH] make iunique use a do/while loop rather than its obscure goto loop Jeffrey Layton
@ 2007-01-31 8:16 ` Christoph Hellwig
0 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2007-01-31 8:16 UTC (permalink / raw)
To: Jeffrey Layton; +Cc: linux-fsdevel, linux-kernel, hch
On Tue, Jan 30, 2007 at 10:45:54AM -0500, Jeffrey Layton wrote:
> While working on a case, 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;
Looks good, thanks
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] make iunique use a do/while loop rather than its obscure goto loop
@ 2007-04-11 21:58 Jeffrey Layton
2007-04-13 18:42 ` Andrew Morton
2007-06-23 8:08 ` Christoph Hellwig
0 siblings, 2 replies; 7+ messages in thread
From: Jeffrey Layton @ 2007-04-11 21:58 UTC (permalink / raw)
To: akpm; +Cc: hch, linux-kernel, linux-fsdevel
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;
}
EXPORT_SYMBOL(iunique);
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] make iunique use a do/while loop rather than its obscure goto loop
2007-04-11 21:58 Jeffrey Layton
@ 2007-04-13 18:42 ` Andrew Morton
2007-04-13 19:08 ` Jeff Layton
2007-06-23 8:08 ` Christoph Hellwig
1 sibling, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2007-04-13 18:42 UTC (permalink / raw)
To: Jeffrey Layton; +Cc: hch, linux-kernel, linux-fsdevel
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?
Shouldn't counter be per-sb?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] make iunique use a do/while loop rather than its obscure goto loop
2007-04-13 18:42 ` Andrew Morton
@ 2007-04-13 19:08 ` Jeff Layton
2007-04-13 19:55 ` Andrew Morton
0 siblings, 1 reply; 7+ messages in thread
From: Jeff Layton @ 2007-04-13 19:08 UTC (permalink / raw)
To: Andrew Morton; +Cc: hch, linux-kernel, linux-fsdevel
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] make iunique use a do/while loop rather than its obscure goto loop
2007-04-13 19:08 ` Jeff Layton
@ 2007-04-13 19:55 ` Andrew Morton
0 siblings, 0 replies; 7+ messages in thread
From: Andrew Morton @ 2007-04-13 19:55 UTC (permalink / raw)
To: Jeff Layton; +Cc: hch, linux-kernel, linux-fsdevel
On Fri, 13 Apr 2007 15:08:38 -0400
Jeff Layton <jlayton@redhat.com> wrote:
> >
> > 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.
oh.
(wonders why alpha and s390 use unsigned int for ino_t while everyone
else uses unsigned long)
> We could potentially put that in an "unlikely" if you
> think that would be better.
Doubt if it'd make much difference.
> > 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?
Well, that'd be a separate patch. Sometime, if you're keen.
If that function is ever a performance problem, it'll be an awful
performance problem and we'd need to so something smarter than
a linear search - an idr tree, for example.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] make iunique use a do/while loop rather than its obscure goto loop
2007-04-11 21:58 Jeffrey Layton
2007-04-13 18:42 ` Andrew Morton
@ 2007-06-23 8:08 ` Christoph Hellwig
1 sibling, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2007-06-23 8:08 UTC (permalink / raw)
To: Jeffrey Layton; +Cc: akpm, hch, linux-kernel, linux-fsdevel
On Wed, Apr 11, 2007 at 05:58:56PM -0400, Jeffrey Layton 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;
> }
>
> EXPORT_SYMBOL(iunique);
---end quoted text---
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-06-23 8:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-30 15:45 [PATCH] make iunique use a do/while loop rather than its obscure goto loop Jeffrey Layton
2007-01-31 8:16 ` Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2007-04-11 21:58 Jeffrey Layton
2007-04-13 18:42 ` Andrew Morton
2007-04-13 19:08 ` Jeff Layton
2007-04-13 19:55 ` Andrew Morton
2007-06-23 8:08 ` Christoph Hellwig
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).