All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: cmm@us.ibm.com
Cc: kiran@scalex86.org, Laurent.Vivier@bull.net,
	linux-kernel@vger.kernel.org, ext2-devel@lists.sourceforge.net,
	linux-fsdevel@vger.kernel.org
Subject: Re: [RFC][PATCH 1/3] per cpu counter fixes for unsigned long type counter overflow
Date: Mon, 10 Apr 2006 15:18:17 -0700	[thread overview]
Message-ID: <20060410151817.27766565.akpm@osdl.org> (raw)
In-Reply-To: <1144691947.3964.54.camel@dyn9047017067.beaverton.ibm.com>

Mingming Cao <cmm@us.ibm.com> wrote:
>
> [PATCH 1/3] - Currently the"long" type counter maintained in percpu
> counter could have issue when handling a counter that is a unsigned long
> type. Most cases this could be easily fixed by casting the returned
> value to "unsigned long". But for the "overflow" issue, i.e. because of
> the percpu global counter is a approsimate value, there is a
> possibility that at some point the global counter is close to the max
> limit (oxffff_feee) but after updating from a local counter a positive
> value, the global counter becomes a small value (i.e.0x 00000012). 
> 
> This patch tries to avoid this overflow happen. When updating from a
> local counter to the global counter, add a check to see if the updated
> value is less than before if we are doing an positive add, or if the
> updated value is greater than before if we are doing an negative add.
> Either way we should postpone the updating from this local counter to
> the global counter.
> 
>  
> -static void __percpu_counter_mod(struct percpu_counter *fbc, long amount)
> +static void __percpu_counter_mod(struct percpu_counter *fbc, long amount,
> +				int llcheck)

Confused.  What does "ll" stand for throughout this patch?

Whatever it is, I suspect we need to choose something better ;)

>  {
>  	long count;
>  	long *pcount;
>  	int cpu = smp_processor_id();
> +	unsigned long before, after;
> +	int update = 1;
>  
>  	pcount = per_cpu_ptr(fbc->counters, cpu);
>  	count = *pcount + amount;
>  	if (count >= FBC_BATCH || count <= -FBC_BATCH) {
>  		spin_lock(&fbc->lock);
> -		fbc->count += count;
> -		*pcount = 0;
> +		before = fbc->count;
> +		after = before + count;
> +		if (llcheck && ((count > 0 && after < before) ||
> +				( count < 0 && after > before)))
> +			update = 0;
> +
> +		if (update) {
> +			fbc->count = after;
> +			*pcount = 0;
> +		}

The above bit of magic deserves an explanatory comment.

>  		spin_unlock(&fbc->lock);
>  	} else {
>  		*pcount = count;
>  	}
>  }
>  
> +void percpu_counter_mod_ll(struct percpu_counter *fbc, long amount)
> +{
> +	preempt_disable();
> +	__percpu_counter_mod(fbc, amount, 1);
> +	preempt_enable();
> +}
> +EXPORT_SYMBOL(percpu_counter_mod_ll);

An introductory comment which describes the difference between this and
percpu_counter_mod() would be helpful, please.



  reply	other threads:[~2006-04-10 23:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-10 17:59 [RFC][PATCH 1/3] per cpu counter fixes for unsigned long type counter overflow Mingming Cao
2006-04-10 22:18 ` Andrew Morton [this message]
2006-04-11  1:09   ` Mingming Cao
2006-04-11  7:54     ` Andreas Dilger
2006-04-11 17:23       ` Mingming Cao
2006-04-21 14:59 ` [PATCH 2/2] ext3 free blocks counter initialization fix Mingming Cao
2006-04-24 22:51   ` [PATCH 2/2] Set initial value when calling percpu counter initialization routine Mingming Cao
2006-04-24 22:51     ` Mingming Cao

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=20060410151817.27766565.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=Laurent.Vivier@bull.net \
    --cc=cmm@us.ibm.com \
    --cc=ext2-devel@lists.sourceforge.net \
    --cc=kiran@scalex86.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 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.