Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1671083

Re: [PATCH v2 2/2] writeback: Rework wb_[dec|inc]_stat family of functions

From Nikolay Borisov <nborisov@suse.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2 2/2] writeback: Rework wb_[dec|inc]_stat family of functions
Date 2017-06-20 22:30 +0200
Message-ID <tUxWH-4Sn-27@gated-at.bofh.it> (permalink)
References <tUvib-3ak-37@gated-at.bofh.it> <tUvLc-3zj-33@gated-at.bofh.it> <tUxai-4kt-27@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw



On 20.06.2017 22:37, Tejun Heo wrote:
> Hello, Nikolay.
> 
> On Tue, Jun 20, 2017 at 09:02:00PM +0300, Nikolay Borisov wrote:
>> Currently the writeback statistics code uses a percpu counters to hold
>> various statistics. Furthermore we have 2 families of functions - those which
>> disable local irq and those which doesn't and whose names begin with
>> double underscore. However, they both end up calling __add_wb_stats which in
>> turn calls percpu_counter_add_batch which is already irq-safe.
> 
> Heh, looks like I was confused.  __percpu_counter_add() is not
> irq-safe.  It disables preemption and uses __this_cpu_read(), so
> there's no protection against irq.  If writeback statistics want
> irq-safe operations and it does, it would need these separate
> operations.  Am I missing something?

So looking at the history of the commit initially there was
preempt_disable + this_cpu_ptr which was later changed in:

819a72af8d66 ("percpucounter: Optimize __percpu_counter_add a bit
through the use of this_cpu() options.")


I believe that having __this_cpu_read ensures that we get an atomic
snapshot of the variable but when we are doing the actual write e.g. the
else {} branch we actually use this_cpu_add which ought to be preempt +
irq safe, meaning we won't get torn write. In essence we have atomic
reads by merit of __this_cpu_read + atomic writes by merit of using
raw_spin_lock_irqsave in the if() branch and this_cpu_add in the else {}
branch.

> 
> Thanks.
> 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/2] percpu_counter: Rename __percpu_counter_add to percpu_counter_add_batch Nikolay Borisov <nborisov@suse.com> - 2017-06-20 13:40 +0200
  [PATCH 2/2] writeback: Rework wb_[dec|inc]_stat family of functions Nikolay Borisov <nborisov@suse.com> - 2017-06-20 13:40 +0200
    Re: [PATCH 2/2] writeback: Rework wb_[dec|inc]_stat family of  functions Tejun Heo <tj@kernel.org> - 2017-06-20 19:40 +0200
      [PATCH v2 2/2] writeback: Rework wb_[dec|inc]_stat family of functions Nikolay Borisov <nborisov@suse.com> - 2017-06-20 20:10 +0200
        Re: [PATCH v2 2/2] writeback: Rework wb_[dec|inc]_stat family of  functions Tejun Heo <tj@kernel.org> - 2017-06-20 21:40 +0200
          Re: [PATCH v2 2/2] writeback: Rework wb_[dec|inc]_stat family of  functions Nikolay Borisov <nborisov@suse.com> - 2017-06-20 22:30 +0200
            Re: [PATCH v2 2/2] writeback: Rework wb_[dec|inc]_stat family of  functions Tejun Heo <tj@kernel.org> - 2017-06-20 22:40 +0200
              Re: [PATCH v2 2/2] writeback: Rework wb_[dec|inc]_stat family of  functions Nikolay Borisov <nborisov@suse.com> - 2017-06-20 22:40 +0200
              [PATCH v3] writeback: Rework wb_[dec|inc]_stat family of functions Nikolay Borisov <nborisov@suse.com> - 2017-06-21 09:30 +0200
                Re: [PATCH v3] writeback: Rework wb_[dec|inc]_stat family of  functions Tejun Heo <tj@kernel.org> - 2017-06-21 18:40 +0200
                Re: [PATCH v3] writeback: Rework wb_[dec|inc]_stat family of  functions Jan Kara <jack@suse.cz> - 2017-06-22 11:20 +0200
  Re: [PATCH 1/2] percpu_counter: Rename __percpu_counter_add to  percpu_counter_add_batch Tejun Heo <tj@kernel.org> - 2017-06-20 19:30 +0200
    [PATCH v2 1/2] percpu_counter: Rename __percpu_counter_add to percpu_counter_add_batch Nikolay Borisov <nborisov@suse.com> - 2017-06-20 20:10 +0200
      [PATCH] percpu_counter: Rename __percpu_counter_add to  percpu_counter_add_batch Tejun Heo <tj@kernel.org> - 2017-06-20 21:50 +0200
        Re: [PATCH] percpu_counter: Rename __percpu_counter_add to  percpu_counter_add_batch David Miller <davem@davemloft.net> - 2017-06-20 22:00 +0200
        Re: [PATCH] percpu_counter: Rename __percpu_counter_add to  percpu_counter_add_batch "Darrick J. Wong" <darrick.wong@oracle.com> - 2017-06-21 03:20 +0200
        Re: [PATCH] percpu_counter: Rename __percpu_counter_add to  percpu_counter_add_batch David Sterba <dsterba@suse.cz> - 2017-06-21 14:10 +0200

csiph-web