01 Nov, 2011

1 commit


13 Sep, 2011

1 commit

  • The percpu_counter::lock can be taken in atomic context and therefore
    cannot be preempted on -rt - annotate it.

    In mainline this change documents the low level nature of
    the lock - otherwise there's no functional difference. Lockdep
    and Sparse checking will work as usual.

    Signed-off-by: Thomas Gleixner
    Signed-off-by: Ingo Molnar

    Thomas Gleixner
     

17 Dec, 2010

1 commit

  • The this_cpu_* options can be used to optimize __percpu_counter_add a bit. Avoids
    some address arithmetic and saves 12 bytes.

    Before:

    00000000000001d3 :
    1d3: 55 push %rbp
    1d4: 48 89 e5 mov %rsp,%rbp
    1d7: 41 55 push %r13
    1d9: 41 54 push %r12
    1db: 53 push %rbx
    1dc: 48 89 fb mov %rdi,%rbx
    1df: 48 83 ec 08 sub $0x8,%rsp
    1e3: 4c 8b 67 30 mov 0x30(%rdi),%r12
    1e7: 65 4c 03 24 25 00 00 add %gs:0x0,%r12
    1ee: 00 00
    1f0: 4d 63 2c 24 movslq (%r12),%r13
    1f4: 48 63 c2 movslq %edx,%rax
    1f7: 49 01 f5 add %rsi,%r13
    1fa: 49 39 c5 cmp %rax,%r13
    1fd: 7d 0a jge 209
    1ff: f7 da neg %edx
    201: 48 63 d2 movslq %edx,%rdx
    204: 49 39 d5 cmp %rdx,%r13
    207: 7f 1e jg 227
    209: 48 89 df mov %rbx,%rdi
    20c: e8 00 00 00 00 callq 211
    211: 4c 01 6b 18 add %r13,0x18(%rbx)
    215: 48 89 df mov %rbx,%rdi
    218: 41 c7 04 24 00 00 00 movl $0x0,(%r12)
    21f: 00
    220: e8 00 00 00 00 callq 225
    225: eb 04 jmp 22b
    227: 45 89 2c 24 mov %r13d,(%r12)
    22b: 5b pop %rbx
    22c: 5b pop %rbx
    22d: 41 5c pop %r12
    22f: 41 5d pop %r13
    231: c9 leaveq
    232: c3 retq

    After:

    00000000000001d3 :
    1d3: 55 push %rbp
    1d4: 48 63 ca movslq %edx,%rcx
    1d7: 48 89 e5 mov %rsp,%rbp
    1da: 41 54 push %r12
    1dc: 53 push %rbx
    1dd: 48 89 fb mov %rdi,%rbx
    1e0: 48 8b 47 30 mov 0x30(%rdi),%rax
    1e4: 65 44 8b 20 mov %gs:(%rax),%r12d
    1e8: 4d 63 e4 movslq %r12d,%r12
    1eb: 49 01 f4 add %rsi,%r12
    1ee: 49 39 cc cmp %rcx,%r12
    1f1: 7d 0a jge 1fd
    1f3: f7 da neg %edx
    1f5: 48 63 d2 movslq %edx,%rdx
    1f8: 49 39 d4 cmp %rdx,%r12
    1fb: 7f 21 jg 21e
    1fd: 48 89 df mov %rbx,%rdi
    200: e8 00 00 00 00 callq 205
    205: 4c 01 63 18 add %r12,0x18(%rbx)
    209: 48 8b 43 30 mov 0x30(%rbx),%rax
    20d: 48 89 df mov %rbx,%rdi
    210: 65 c7 00 00 00 00 00 movl $0x0,%gs:(%rax)
    217: e8 00 00 00 00 callq 21c
    21c: eb 04 jmp 222
    21e: 65 44 89 20 mov %r12d,%gs:(%rax)
    222: 5b pop %rbx
    223: 41 5c pop %r12
    225: c9 leaveq
    226: c3 retq

    Reviewed-by: Pekka Enberg
    Reviewed-by: Tejun Heo
    Reviewed-by: Mathieu Desnoyers
    Acked-by: H. Peter Anvin
    Signed-off-by: Christoph Lameter
    Signed-off-by: Tejun Heo

    Christoph Lameter
     

27 Oct, 2010

3 commits

  • this_cpu_ptr() avoids an array lookup and can use the percpu offset of the
    local cpu directly.

    Signed-off-by: Christoph Lameter
    Cc: Eric Dumazet
    Cc: Tejun Heo
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Christoph Lameter
     
  • All percpu counters are linked to a global list on initialization and
    removed from it on destruction. The list is walked during CPU up/down.
    If a percpu counter is freed without being properly destroyed, the system
    will oops only on the next CPU up/down making it pretty nasty to track
    down. This patch adds debugobj support for percpu counters so that such
    problems can be found easily.

    As percpu counters don't make sense on stack and can't be statically
    initialized, debugobj support is pretty simple. It's initialized and
    activated on counter initialization, and deactivatd and destroyed on
    counter destruction. With this patch applied, the bug fixed by commit
    602586a83b719df0fbd94196a1359ed35aeb2df3 (shmem: put_super must
    percpu_counter_destroy) triggers the following warning on tmpfs unmount
    and the system won't oops on the next cpu up/down operation.

    ------------[ cut here ]------------
    WARNING: at lib/debugobjects.c:259 debug_print_object+0x5c/0x70()
    Hardware name: Bochs
    ODEBUG: free active (active state 0) object type: percpu_counter
    Modules linked in:
    Pid: 3999, comm: umount Not tainted 2.6.36-rc2-work+ #5
    Call Trace:
    [] warn_slowpath_common+0x7f/0xc0
    [] warn_slowpath_fmt+0x46/0x50
    [] debug_print_object+0x5c/0x70
    [] debug_check_no_obj_freed+0x125/0x210
    [] kfree+0xb3/0x2f0
    [] shmem_put_super+0x1d/0x30
    [] generic_shutdown_super+0x56/0xe0
    [] kill_anon_super+0x16/0x60
    [] kill_litter_super+0x27/0x30
    [] deactivate_locked_super+0x45/0x60
    [] deactivate_super+0x4a/0x70
    [] mntput_no_expire+0x86/0xe0
    [] sys_umount+0x6f/0x360
    [] system_call_fastpath+0x16/0x1b
    ---[ end trace cce2a341ba3611a7 ]---

    Signed-off-by: Tejun Heo
    Acked-by: Thomas Gleixner
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Tejun Heo
     
  • WARNING: at lib/list_debug.c:26 __list_add+0x3f/0x81()
    Hardware name: Express5800/B120a [N8400-085]
    list_add corruption. next->prev should be prev (ffffffff81a7ea00), but was dead000000200200. (next=ffff88080b872d58).
    Modules linked in: aoe ipt_MASQUERADE iptable_nat nf_nat autofs4 sunrpc bridge 8021q garp stp llc ipv6 cpufreq_ondemand acpi_cpufreq freq_table dm_round_robin dm_multipath kvm_intel kvm uinput lpfc scsi_transport_fc igb ioatdma scsi_tgt i2c_i801 i2c_core dca iTCO_wdt iTCO_vendor_support pcspkr shpchp megaraid_sas [last unloaded: aoe]
    Pid: 54, comm: events/3 Tainted: G W 2.6.34-vanilla1 #1
    Call Trace:
    [] warn_slowpath_common+0x7c/0x94
    [] warn_slowpath_fmt+0x41/0x43
    [] __list_add+0x3f/0x81
    [] __percpu_counter_init+0x59/0x6b
    [] bdi_init+0x118/0x17e
    [] blk_alloc_queue_node+0x79/0x143
    [] blk_alloc_queue+0x11/0x13
    [] aoeblk_gdalloc+0x8e/0x1c9 [aoe]
    [] aoecmd_sleepwork+0x25/0xa8 [aoe]
    [] worker_thread+0x1a9/0x237
    [] ? aoecmd_sleepwork+0x0/0xa8 [aoe]
    [] ? autoremove_wake_function+0x0/0x39
    [] ? worker_thread+0x0/0x237
    [] kthread+0x7f/0x87
    [] kernel_thread_helper+0x4/0x10
    [] ? kthread+0x0/0x87
    [] ? kernel_thread_helper+0x0/0x10

    It's because there is no initialization code for a list_head contained in
    the struct backing_dev_info under CONFIG_HOTPLUG_CPU, and the bug comes up
    when block device drivers calling blk_alloc_queue() are used. In case of
    me, I got them by using aoe.

    Signed-off-by: Masanori Itoh
    Cc: Tejun Heo
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Masanori ITOH
     

10 Aug, 2010

1 commit

  • Add percpu_counter_compare that allows for a quick but accurate comparison
    of percpu_counter with a given value.

    A rough count is provided by the count field in percpu_counter structure,
    without accounting for the other values stored in individual cpu counters.

    The actual count is a sum of count and the cpu counters. However, count
    field is never different from the actual value by a factor of
    batch*num_online_cpu. We do not need to get actual count for comparison
    if count is different from the given value by this factor and allows for
    quick comparison without summing up all the per cpu counters.

    Signed-off-by: Tim Chen
    Cc: Hugh Dickins
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Tim Chen
     

07 Jan, 2009

2 commits

  • …/git/tip/linux-2.6-tip

    * 'core-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
    rcu: fix rcutorture bug
    rcu: eliminate synchronize_rcu_xxx macro
    rcu: make treercu safe for suspend and resume
    rcu: fix rcutree grace-period-latency bug on small systems
    futex: catch certain assymetric (get|put)_futex_key calls
    futex: make futex_(get|put)_key() calls symmetric
    locking, percpu counters: introduce separate lock classes
    swiotlb: clean up EXPORT_SYMBOL usage
    swiotlb: remove unnecessary declaration
    swiotlb: replace architecture-specific swiotlb.h with linux/swiotlb.h
    swiotlb: add support for systems with highmem
    swiotlb: store phys address in io_tlb_orig_addr array
    swiotlb: add hwdev to swiotlb_phys_to_bus() / swiotlb_sg_to_bus()

    Linus Torvalds
     
  • For NR_CPUS >= 16 values, FBC_BATCH is 2*NR_CPUS

    Considering more and more distros are using high NR_CPUS values, it makes
    sense to use a more sensible value for FBC_BATCH, and get rid of NR_CPUS.

    A sensible value is 2*num_online_cpus(), with a minimum value of 32 (This
    minimum value helps branch prediction in __percpu_counter_add())

    We already have a hotcpu notifier, so we can adjust FBC_BATCH dynamically.

    We rename FBC_BATCH to percpu_counter_batch since its not a constant
    anymore.

    Signed-off-by: Eric Dumazet
    Acked-by: David S. Miller
    Acked-by: Peter Zijlstra
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eric Dumazet
     

06 Jan, 2009

1 commit


29 Dec, 2008

1 commit

  • Impact: fix lockdep false positives

    Classify percpu_counter instances similar to regular lock objects --
    that is, per instantiation site.

    The networking code has increased its use of percpu_counters, which
    leads to false positives if they are treated as a single class.

    Signed-off-by: Peter Zijlstra
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

11 Dec, 2008

3 commits

  • Revert

    commit e8ced39d5e8911c662d4d69a342b9d053eaaac4e
    Author: Mingming Cao
    Date: Fri Jul 11 19:27:31 2008 -0400

    percpu_counter: new function percpu_counter_sum_and_set

    As described in

    revert "percpu counter: clean up percpu_counter_sum_and_set()"

    the new percpu_counter_sum_and_set() is racy against updates to the
    cpu-local accumulators on other CPUs. Revert that change.

    This means that ext4 will be slow again. But correct.

    Reported-by: Eric Dumazet
    Cc: "David S. Miller"
    Cc: Peter Zijlstra
    Cc: Mingming Cao
    Cc:
    Cc: [2.6.27.x]
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrew Morton
     
  • Revert

    commit 1f7c14c62ce63805f9574664a6c6de3633d4a354
    Author: Mingming Cao
    Date: Thu Oct 9 12:50:59 2008 -0400

    percpu counter: clean up percpu_counter_sum_and_set()

    Before this patch we had the following:

    percpu_counter_sum(): return the percpu_counter's value

    percpu_counter_sum_and_set(): return the percpu_counter's value, copying
    that value into the central value and zeroing the per-cpu counters before
    returning.

    After this patch, percpu_counter_sum_and_set() has gone, and
    percpu_counter_sum() gets the old percpu_counter_sum_and_set()
    functionality.

    Problem is, as Eric points out, the old percpu_counter_sum_and_set()
    functionality was racy and wrong. It zeroes out counters on "other" cpus,
    without holding any locks which will prevent races agaist updates from
    those other CPUS.

    This patch reverts 1f7c14c62ce63805f9574664a6c6de3633d4a354. This means
    that percpu_counter_sum_and_set() still has the race, but
    percpu_counter_sum() does not.

    Note that this is not a simple revert - ext4 has since started using
    percpu_counter_sum() for its dirty_blocks counter as well.

    Note that this revert patch changes percpu_counter_sum() semantics.

    Before the patch, a call to percpu_counter_sum() will bring the counter's
    central counter mostly up-to-date, so a following percpu_counter_read()
    will return a close value.

    After this patch, a call to percpu_counter_sum() will leave the counter's
    central accumulator unaltered, so a subsequent call to
    percpu_counter_read() can now return a significantly inaccurate result.

    If there is any code in the tree which was introduced after
    e8ced39d5e8911c662d4d69a342b9d053eaaac4e was merged, and which depends
    upon the new percpu_counter_sum() semantics, that code will break.

    Reported-by: Eric Dumazet
    Cc: "David S. Miller"
    Cc: Peter Zijlstra
    Cc: Mingming Cao
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrew Morton
     
  • We should first delete the counter from percpu_counters list
    before freeing memory, or a percpu_counter_hotcpu_callback()
    could dereference a NULL pointer.

    Signed-off-by: Eric Dumazet
    Acked-by: David S. Miller
    Cc: Peter Zijlstra
    Cc: Mingming Cao
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Eric Dumazet
     

10 Oct, 2008

1 commit

  • percpu_counter_sum_and_set() and percpu_counter_sum() is the same except
    the former updates the global counter after accounting. Since we are
    taking the fbc->lock to calculate the precise value of the counter in
    percpu_counter_sum() anyway, it should simply set fbc->count too, as the
    percpu_counter_sum_and_set() does.

    This patch merges these two interfaces into one.

    Signed-off-by: Mingming Cao
    Acked-by: Peter Zijlstra
    Cc:
    Signed-off-by: Andrew Morton
    Signed-off-by: "Theodore Ts'o"

    Mingming Cao
     

12 Jul, 2008

1 commit

  • Delayed allocation need to check free blocks at every write time.
    percpu_counter_read_positive() is not quit accurate. delayed
    allocation need a more accurate accounting, but using
    percpu_counter_sum_positive() is frequently is quite expensive.

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

    Signed-off-by: Mingming Cao
    Signed-off-by: "Theodore Ts'o"

    Mingming Cao
     

30 Apr, 2008

1 commit

  • Provide a place in sysfs (/sys/class/bdi) for the backing_dev_info object.
    This allows us to see and set the various BDI specific variables.

    In particular this properly exposes the read-ahead window for all relevant
    users and /sys/block//queue/read_ahead_kb should be deprecated.

    With patient help from Kay Sievers and Greg KH

    [mszeredi@suse.cz]

    - split off NFS and FUSE changes into separate patches
    - document new sysfs attributes under Documentation/ABI
    - do bdi_class_init as a core_initcall, otherwise the "default" BDI
    won't be initialized
    - remove bdi_init_fmt macro, it's not used very much

    [akpm@linux-foundation.org: fix ia64 warning]
    Signed-off-by: Peter Zijlstra
    Cc: Kay Sievers
    Acked-by: Greg KH
    Cc: Trond Myklebust
    Signed-off-by: Miklos Szeredi
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Peter Zijlstra
     

20 Oct, 2007

1 commit

  • Some of the per-cpu counters and thus their locks are accessed from IRQ
    contexts. This can cause a deadlock if it interrupts a cpu-offline thread
    which is transferring a dead-cpu's counts to the global counter.

    Add appropriate IRQ protection in the cpu-hotplug callback path.

    Signed-off-by: Gautham R Shenoy
    Cc: KAMEZAWA Hiroyuki
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Gautham R Shenoy
     

17 Oct, 2007

8 commits


17 Jul, 2007

2 commits

  • Now that we have implemented hotunplug-time counter spilling,
    percpu_counter_sum() only needs to look at online CPUs.

    Cc: Gautham R Shenoy
    Cc: Oleg Nesterov
    Cc: Peter Zijlstra
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrew Morton
     
  • per-cpu counters presently must iterate over all possible CPUs in the
    exhaustive percpu_counter_sum().

    But it can be much better to only iterate over the presently-online CPUs. To
    do this, we must arrange for an offlined CPU's count to be spilled into the
    counter's central count.

    We can do this for all percpu_counters in the machine by linking them into a
    single global list and walking that list at CPU_DEAD time.

    (I hope. Might have race windows in which the percpu_counter_sum() count is
    inaccurate?)

    Cc: Gautham R Shenoy
    Cc: Oleg Nesterov
    Cc: Peter Zijlstra
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Andrew Morton
     

23 Jun, 2006

2 commits

  • The percpu counter data type are changed in this set of patches to support
    more users like ext3 who need more than 32 bit to store the free blocks
    total in the filesystem.

    - Generic perpcu counters data type changes. The size of the global counter
    and local counter were explictly specified using s64 and s32. The global
    counter is changed from long to s64, while the local counter is changed from
    long to s32, so we could avoid doing 64 bit update in most cases.

    - Users of the percpu counters are updated to make use of the new
    percpu_counter_init() routine now taking an additional parameter to allow
    users to pass the initial value of the global counter.

    Signed-off-by: Mingming Cao
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Mingming Cao
     
  • - Move percpu_counter routines from mm/swap.c to lib/percpu_counter.c

    Signed-off-by: Ravikiran Thirumalai
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Ravikiran G Thirumalai