linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC][PATCH 6/6] delalloc ENOSPC: improve percpu counter accounting accurate
@ 2008-06-01 23:36 Mingming Cao
  2008-06-02  0:19 ` Akira Fujita
  0 siblings, 1 reply; 4+ messages in thread
From: Mingming Cao @ 2008-06-01 23:36 UTC (permalink / raw)
  To: linux-ext4

percpu counter: update center counter when sum per-cpu counter

From: Mingming cao <cmm@us.ibm.com>

Delayed allocation need to check free blocks at every write time.
percpu_counter_read_positive() is not quit accurate
 but using percpu_counter_sum_positive() for every write
frequently is quite expensive.

This patch added a new function to update center counter when
sum up per-cpu counters, to increase the accurate rate
for next percpu_counter_read()(which reads only the center counter
and require less calling expensive percpu_counter_sum().(in
ext4_has_free_blocks)

Signed-off-by: Mingming cao <cmm@us.ibm.com>

---
 fs/ext4/balloc.c               |    2 +-
 include/linux/percpu_counter.h |   12 +++++++++---
 lib/percpu_counter.c           |    7 ++++++-
 3 files changed, 16 insertions(+), 5 deletions(-)

Index: linux-2.6.26-rc4/include/linux/percpu_counter.h
===================================================================
--- linux-2.6.26-rc4.orig/include/linux/percpu_counter.h	2008-06-01 15:33:09.000000000 -0700
+++ linux-2.6.26-rc4/include/linux/percpu_counter.h	2008-06-01 15:33:14.000000000 -0700
@@ -35,7 +35,7 @@ int percpu_counter_init_irq(struct percp
 void percpu_counter_destroy(struct percpu_counter *fbc);
 void percpu_counter_set(struct percpu_counter *fbc, s64 amount);
 void __percpu_counter_add(struct percpu_counter *fbc, s64 amount, s32 batch);
-s64 __percpu_counter_sum(struct percpu_counter *fbc);
+s64 __percpu_counter_sum(struct percpu_counter *fbc, int set);
 
 static inline void percpu_counter_add(struct percpu_counter *fbc, s64 amount)
 {
@@ -44,13 +44,19 @@ static inline void percpu_counter_add(st
 
 static inline s64 percpu_counter_sum_positive(struct percpu_counter *fbc)
 {
-	s64 ret = __percpu_counter_sum(fbc);
+	s64 ret = __percpu_counter_sum(fbc, 0);
 	return ret < 0 ? 0 : ret;
 }
 
+static inline s64 percpu_counter_sum_and_set(struct percpu_counter *fbc)
+{
+	return __percpu_counter_sum(fbc, 1);
+}
+
+
 static inline s64 percpu_counter_sum(struct percpu_counter *fbc)
 {
-	return __percpu_counter_sum(fbc);
+	return __percpu_counter_sum(fbc, 0);
 }
 
 static inline s64 percpu_counter_read(struct percpu_counter *fbc)
Index: linux-2.6.26-rc4/lib/percpu_counter.c
===================================================================
--- linux-2.6.26-rc4.orig/lib/percpu_counter.c	2008-06-01 15:33:09.000000000 -0700
+++ linux-2.6.26-rc4/lib/percpu_counter.c	2008-06-01 15:33:14.000000000 -0700
@@ -52,7 +52,7 @@ EXPORT_SYMBOL(__percpu_counter_add);
  * Add up all the per-cpu counts, return the result.  This is a more accurate
  * but much slower version of percpu_counter_read_positive()
  */
-s64 __percpu_counter_sum(struct percpu_counter *fbc)
+s64 __percpu_counter_sum(struct percpu_counter *fbc, int set)
 {
 	s64 ret;
 	int cpu;
@@ -62,7 +62,12 @@ s64 __percpu_counter_sum(struct percpu_c
 	for_each_online_cpu(cpu) {
 		s32 *pcount = per_cpu_ptr(fbc->counters, cpu);
 		ret += *pcount;
+		if (set)
+			*pcount = 0;
 	}
+	if (set)
+		fbc->count = ret;
+
 	spin_unlock(&fbc->lock);
 	return ret;
 }
Index: linux-2.6.26-rc4/fs/ext4/balloc.c
===================================================================
--- linux-2.6.26-rc4.orig/fs/ext4/balloc.c	2008-06-01 15:33:36.000000000 -0700
+++ linux-2.6.26-rc4/fs/ext4/balloc.c	2008-06-01 15:34:28.000000000 -0700
@@ -1626,7 +1626,7 @@ ext4_fsblk_t ext4_has_free_blocks(struct
 
 	if (free_blocks - root_blocks < FBC_BATCH)
 		free_blocks =
-			percpu_counter_sum_positive(&sbi->s_freeblocks_counter);
+		    percpu_counter_sum_positive_set(&sbi->s_freeblocks_counter);
 	if (free_blocks - root_blocks < nblocks )
 		return free_blocks -root_blocks;
 	return nblocks;




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC][PATCH 6/6] delalloc ENOSPC: improve percpu counter accounting accurate
  2008-06-01 23:36 [RFC][PATCH 6/6] delalloc ENOSPC: improve percpu counter accounting accurate Mingming Cao
@ 2008-06-02  0:19 ` Akira Fujita
  2008-06-02  2:30   ` Mingming Cao
  0 siblings, 1 reply; 4+ messages in thread
From: Akira Fujita @ 2008-06-02  0:19 UTC (permalink / raw)
  To: cmm; +Cc: linux-ext4

Hi,

> Mingming Cao wrote:
> percpu counter: update center counter when sum per-cpu counter
>
> From: Mingming cao <cmm@us.ibm.com>
>
> Delayed allocation need to check free blocks at every write time.
> percpu_counter_read_positive() is not quit accurate
>  but using percpu_counter_sum_positive() for every write
> frequently is quite expensive.

I couldn't compile the latest ext4 patch qeueu.

  LD      fs/ext3/ext3.o
  LD      fs/ext3/built-in.o
  CC      fs/ext4/balloc.o
fs/ext4/balloc.c: In function ‘ext4_has_free_blocks’:
fs/ext4/balloc.c:1629: error: implicit declaration of function ‘percpu_counter_sum_positive_set’


> +		    percpu_counter_sum_positive_set(&sbi->s_freeblocks_counter);

Maybe the above line which in percpucounter-add-sum-and-set-function.patch
is percpu_counter_sum_and_set(&sbi->s_freeblocks_couter).

Thanks,
Akira Fujita

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC][PATCH 6/6] delalloc ENOSPC: improve percpu counter accounting accurate
  2008-06-02  0:19 ` Akira Fujita
@ 2008-06-02  2:30   ` Mingming Cao
  2008-06-02  2:45     ` Akira Fujita
  0 siblings, 1 reply; 4+ messages in thread
From: Mingming Cao @ 2008-06-02  2:30 UTC (permalink / raw)
  To: Akira Fujita; +Cc: linux-ext4

On Mon, 2008-06-02 at 09:19 +0900, Akira Fujita wrote:
> Hi,
> 
> > Mingming Cao wrote:
> > percpu counter: update center counter when sum per-cpu counter
> >
> > From: Mingming cao <cmm@us.ibm.com>
> >
> > Delayed allocation need to check free blocks at every write time.
> > percpu_counter_read_positive() is not quit accurate
> >  but using percpu_counter_sum_positive() for every write
> > frequently is quite expensive.
> 
> I couldn't compile the latest ext4 patch qeueu.
> 
>   LD      fs/ext3/ext3.o
>   LD      fs/ext3/built-in.o
>   CC      fs/ext4/balloc.o
> fs/ext4/balloc.c: In function ‘ext4_has_free_blocks’:
> fs/ext4/balloc.c:1629: error: implicit declaration of function ‘percpu_counter_sum_positive_set’
> 
> 
> > +		    percpu_counter_sum_positive_set(&sbi->s_freeblocks_counter);
> 
> Maybe the above line which in percpucounter-add-sum-and-set-function.patch
> is percpu_counter_sum_and_set(&sbi->s_freeblocks_couter).
> 

oops. Updated patch queue, please check again.

Mingming
> Thanks,
> Akira Fujita
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC][PATCH 6/6] delalloc ENOSPC: improve percpu counter accounting accurate
  2008-06-02  2:30   ` Mingming Cao
@ 2008-06-02  2:45     ` Akira Fujita
  0 siblings, 0 replies; 4+ messages in thread
From: Akira Fujita @ 2008-06-02  2:45 UTC (permalink / raw)
  To: Mingming Cao; +Cc: linux-ext4

Mingming Cao wrote:
> On Mon, 2008-06-02 at 09:19 +0900, Akira Fujita wrote:
>> Hi,
>>
>>> Mingming Cao wrote:
>>> percpu counter: update center counter when sum per-cpu counter
>>>
>>> From: Mingming cao <cmm@us.ibm.com>
>>>
>>> Delayed allocation need to check free blocks at every write time.
>>> percpu_counter_read_positive() is not quit accurate
>>>  but using percpu_counter_sum_positive() for every write
>>> frequently is quite expensive.
>> I couldn't compile the latest ext4 patch qeueu.
>>
>>   LD      fs/ext3/ext3.o
>>   LD      fs/ext3/built-in.o
>>   CC      fs/ext4/balloc.o
>> fs/ext4/balloc.c: In function ‘ext4_has_free_blocks’:
>> fs/ext4/balloc.c:1629: error: implicit declaration of function ‘percpu_counter_sum_positive_set’
>>
>>
>>> +		    percpu_counter_sum_positive_set(&sbi->s_freeblocks_counter);
>> Maybe the above line which in percpucounter-add-sum-and-set-function.patch
>> is percpu_counter_sum_and_set(&sbi->s_freeblocks_couter).
>>
> 
> oops. Updated patch queue, please check again.

I confirmed that I could compile the latest ext4 patch queue correctly.
Thanks.   :-)

Regards,
Akira Fujita
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-06-02  2:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-01 23:36 [RFC][PATCH 6/6] delalloc ENOSPC: improve percpu counter accounting accurate Mingming Cao
2008-06-02  0:19 ` Akira Fujita
2008-06-02  2:30   ` Mingming Cao
2008-06-02  2:45     ` Akira Fujita

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).