26 Jul, 2020

1 commit

  • Though the number of lock-acquisitions is tracked as unsigned long, this
    is passed as the divisor to div_s64() which interprets it as a s32,
    giving nonsense values with more than 2 billion acquisitons. E.g.

    acquisitions holdtime-min holdtime-max holdtime-total holdtime-avg
    -------------------------------------------------------------------------
    2350439395 0.07 353.38 649647067.36 0.-32

    Signed-off-by: Chris Wilson
    Signed-off-by: Ingo Molnar
    Cc: Peter Zijlstra
    Link: https://lore.kernel.org/r/20200725185110.11588-1-chris@chris-wilson.co.uk

    Chris Wilson
     

11 Feb, 2020

5 commits

  • Once a lock class is zapped, all the lock chains that include the zapped
    class are essentially useless. The lock_chain structure itself can be
    reused, but not the corresponding chain_hlocks[] entries. Over time,
    we will run out of chain_hlocks entries while there are still plenty
    of other lockdep array entries available.

    To fix this imbalance, we have to make chain_hlocks entries reusable
    just like the others. As the freed chain_hlocks entries are in blocks of
    various lengths. A simple bitmap like the one used in the other reusable
    lockdep arrays isn't applicable. Instead the chain_hlocks entries are
    put into bucketed lists (MAX_CHAIN_BUCKETS) of chain blocks. Bucket 0
    is the variable size bucket which houses chain blocks of size larger than
    MAX_CHAIN_BUCKETS sorted in decreasing size order. Initially, the whole
    array is in one chain block (the primordial chain block) in bucket 0.

    The minimum size of a chain block is 2 chain_hlocks entries. That will
    be the minimum allocation size. In other word, allocation requests
    for one chain_hlocks entry will cause 2-entry block to be returned and
    hence 1 entry will be wasted.

    Allocation requests for the chain_hlocks are fulfilled first by looking
    for chain block of matching size. If not found, the first chain block
    from bucket[0] (the largest one) is split. That can cause hlock entries
    fragmentation and reduce allocation efficiency if a chain block of size >
    MAX_CHAIN_BUCKETS is ever zapped and put back to after the primordial
    chain block. So the MAX_CHAIN_BUCKETS must be large enough that this
    should seldom happen.

    By reusing the chain_hlocks entries, we are able to handle workloads
    that add and zap a lot of lock classes without the risk of running out
    of chain_hlocks entries as long as the total number of outstanding lock
    classes at any time remain within a reasonable limit.

    Two new tracking counters, nr_free_chain_hlocks & nr_large_chain_blocks,
    are added to track the total number of chain_hlocks entries in the
    free bucketed lists and the number of large chain blocks in buckets[0]
    respectively. The nr_free_chain_hlocks replaces nr_chain_hlocks.

    The nr_large_chain_blocks counter enables to see if we should increase
    the number of buckets (MAX_CHAIN_BUCKETS) available so as to avoid to
    avoid the fragmentation problem in bucket[0].

    An internal nfsd test that ran for more than an hour and kept on
    loading and unloading kernel modules could cause the following message
    to be displayed.

    [ 4318.443670] BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low!

    The patched kernel was able to complete the test with a lot of free
    chain_hlocks entries to spare:

    # cat /proc/lockdep_stats
    :
    dependency chains: 18867 [max: 65536]
    dependency chain hlocks: 74926 [max: 327680]
    dependency chain hlocks lost: 0
    :
    zapped classes: 1541
    zapped lock chains: 56765
    large chain blocks: 1

    By changing MAX_CHAIN_BUCKETS to 3 and add a counter for the size of the
    largest chain block. The system still worked and We got the following
    lockdep_stats data:

    dependency chains: 18601 [max: 65536]
    dependency chain hlocks used: 73133 [max: 327680]
    dependency chain hlocks lost: 0
    :
    zapped classes: 1541
    zapped lock chains: 56702
    large chain blocks: 45165
    large chain block size: 20165

    By running the test again, I was indeed able to cause chain_hlocks
    entries to get lost:

    dependency chain hlocks used: 74806 [max: 327680]
    dependency chain hlocks lost: 575
    :
    large chain blocks: 48737
    large chain block size: 7

    Due to the fragmentation, it is possible that the
    "MAX_LOCKDEP_CHAIN_HLOCKS too low!" error can happen even if a lot of
    of chain_hlocks entries appear to be free.

    Fortunately, a MAX_CHAIN_BUCKETS value of 16 should be big enough that
    few variable sized chain blocks, other than the initial one, should
    ever be present in bucket 0.

    Suggested-by: Peter Zijlstra
    Signed-off-by: Waiman Long
    Signed-off-by: Peter Zijlstra (Intel)
    Signed-off-by: Ingo Molnar
    Link: https://lkml.kernel.org/r/20200206152408.24165-7-longman@redhat.com

    Waiman Long
     
  • Add a new counter nr_zapped_lock_chains to track the number lock chains
    that have been removed.

    Signed-off-by: Waiman Long
    Signed-off-by: Peter Zijlstra (Intel)
    Signed-off-by: Ingo Molnar
    Link: https://lkml.kernel.org/r/20200206152408.24165-6-longman@redhat.com

    Waiman Long
     
  • If a lock chain contains a class that is zapped, the whole lock chain is
    likely to be invalid. If the zapped class is at the end of the chain,
    the partial chain without the zapped class should have been stored
    already as the current code will store all its predecessor chains. If
    the zapped class is somewhere in the middle, there is no guarantee that
    the partial chain will actually happen. It may just clutter up the hash
    and make searching slower. I would rather prefer storing the chain only
    when it actually happens.

    So just dump the corresponding chain_hlocks entries for now. A latter
    patch will try to reuse the freed chain_hlocks entries.

    This patch also changes the type of nr_chain_hlocks to unsigned integer
    to be consistent with the other counters.

    Signed-off-by: Waiman Long
    Signed-off-by: Peter Zijlstra (Intel)
    Signed-off-by: Ingo Molnar
    Link: https://lkml.kernel.org/r/20200206152408.24165-5-longman@redhat.com

    Waiman Long
     
  • The whole point of the lockdep dynamic key patch is to allow unused
    locks to be removed from the lockdep data buffers so that existing
    buffer space can be reused. However, there is no way to find out how
    many unused locks are zapped and so we don't know if the zapping process
    is working properly.

    Add a new nr_zapped_classes counter to track that and show it in
    /proc/lockdep_stats.

    Signed-off-by: Waiman Long
    Signed-off-by: Peter Zijlstra (Intel)
    Signed-off-by: Ingo Molnar
    Link: https://lkml.kernel.org/r/20200206152408.24165-4-longman@redhat.com

    Waiman Long
     
  • Currently, the irq_context field of a lock chains displayed in
    /proc/lockdep_chains is just a number. It is likely that many people
    may not know what a non-zero number means. To make the information more
    useful, print the actual irq names ("softirq" and "hardirq") instead.

    Signed-off-by: Waiman Long
    Signed-off-by: Peter Zijlstra (Intel)
    Signed-off-by: Ingo Molnar
    Link: https://lkml.kernel.org/r/20200206152408.24165-3-longman@redhat.com

    Waiman Long
     

04 Feb, 2020

1 commit

  • The most notable change is DEFINE_SHOW_ATTRIBUTE macro split in
    seq_file.h.

    Conversion rule is:

    llseek => proc_lseek
    unlocked_ioctl => proc_ioctl

    xxx => proc_xxx

    delete ".owner = THIS_MODULE" line

    [akpm@linux-foundation.org: fix drivers/isdn/capi/kcapi_proc.c]
    [sfr@canb.auug.org.au: fix kernel/sched/psi.c]
    Link: http://lkml.kernel.org/r/20200122180545.36222f50@canb.auug.org.au
    Link: http://lkml.kernel.org/r/20191225172546.GB13378@avx2
    Signed-off-by: Alexey Dobriyan
    Signed-off-by: Stephen Rothwell
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     

17 Jan, 2020

1 commit

  • It was found that two lines in the output of /proc/lockdep_stats have
    indentation problem:

    # cat /proc/lockdep_stats
    :
    in-process chains: 25057
    stack-trace entries: 137827 [max: 524288]
    number of stack traces: 7973
    number of stack hash chains: 6355
    combined max dependencies: 1356414598
    hardirq-safe locks: 57
    hardirq-unsafe locks: 1286
    :

    All the numbers displayed in /proc/lockdep_stats except the two stack
    trace numbers are formatted with a field with of 11. To properly align
    all the numbers, a field width of 11 is now added to the two stack
    trace numbers.

    Fixes: 8c779229d0f4 ("locking/lockdep: Report more stack trace statistics")
    Signed-off-by: Waiman Long
    Signed-off-by: Peter Zijlstra (Intel)
    Reviewed-by: Bart Van Assche
    Link: https://lkml.kernel.org/r/20191211213139.29934-1-longman@redhat.com

    Waiman Long
     

25 Jul, 2019

3 commits

  • Report the number of stack traces and the number of stack trace hash
    chains. These two numbers are useful because these allow to estimate
    the number of stack trace hash collisions.

    Signed-off-by: Bart Van Assche
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Waiman Long
    Cc: Will Deacon
    Link: https://lkml.kernel.org/r/20190722182443.216015-5-bvanassche@acm.org
    Signed-off-by: Ingo Molnar

    Bart Van Assche
     
  • This patch does not change the behavior of the lockdep code.

    Signed-off-by: Bart Van Assche
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Waiman Long
    Cc: Will Deacon
    Link: https://lkml.kernel.org/r/20190722182443.216015-2-bvanassche@acm.org
    Signed-off-by: Ingo Molnar

    Bart Van Assche
     
  • The usage is now hidden in an #ifdef, so we need to move
    the variable itself in there as well to avoid this warning:

    kernel/locking/lockdep_proc.c:203:21: error: unused variable 'class' [-Werror,-Wunused-variable]

    Signed-off-by: Arnd Bergmann
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Andrew Morton
    Cc: Bart Van Assche
    Cc: Linus Torvalds
    Cc: Paul E. McKenney
    Cc: Peter Zijlstra
    Cc: Qian Cai
    Cc: Thomas Gleixner
    Cc: Waiman Long
    Cc: Will Deacon
    Cc: Will Deacon
    Cc: Yuyang Du
    Cc: frederic@kernel.org
    Fixes: 68d41d8c94a3 ("locking/lockdep: Fix lock used or unused stats error")
    Link: https://lkml.kernel.org/r/20190715092809.736834-1-arnd@arndb.de
    Signed-off-by: Ingo Molnar

    Arnd Bergmann
     

13 Jul, 2019

1 commit

  • The stats variable nr_unused_locks is incremented every time a new lock
    class is register and decremented when the lock is first used in
    __lock_acquire(). And after all, it is shown and checked in lockdep_stats.

    However, under configurations that either CONFIG_TRACE_IRQFLAGS or
    CONFIG_PROVE_LOCKING is not defined:

    The commit:

    091806515124b20 ("locking/lockdep: Consolidate lock usage bit initialization")

    missed marking the LOCK_USED flag at IRQ usage initialization because
    as mark_usage() is not called. And the commit:

    886532aee3cd42d ("locking/lockdep: Move mark_lock() inside CONFIG_TRACE_IRQFLAGS && CONFIG_PROVE_LOCKING")

    further made mark_lock() not defined such that the LOCK_USED cannot be
    marked at all when the lock is first acquired.

    As a result, we fix this by not showing and checking the stats under such
    configurations for lockdep_stats.

    Reported-by: Qian Cai
    Signed-off-by: Yuyang Du
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: Paul E. McKenney
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Will Deacon
    Cc: arnd@arndb.de
    Cc: frederic@kernel.org
    Link: https://lkml.kernel.org/r/20190709101522.9117-1-duyuyang@gmail.com
    Signed-off-by: Ingo Molnar

    Yuyang Du
     

28 Feb, 2019

1 commit

  • This patch does not change any functionality but makes the next patch in
    this series easier to read.

    Signed-off-by: Bart Van Assche
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Andrew Morton
    Cc: Johannes Berg
    Cc: Linus Torvalds
    Cc: Paul E. McKenney
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Waiman Long
    Cc: Will Deacon
    Cc: johannes.berg@intel.com
    Cc: tj@kernel.org
    Link: https://lkml.kernel.org/r/20190214230058.196511-14-bvanassche@acm.org
    Signed-off-by: Ingo Molnar

    Bart Van Assche
     

09 Oct, 2018

1 commit

  • A sizable portion of the CPU cycles spent on the __lock_acquire() is used
    up by the atomic increment of the class->ops stat counter. By taking it out
    from the lock_class structure and changing it to a per-cpu per-lock-class
    counter, we can reduce the amount of cacheline contention on the class
    structure when multiple CPUs are trying to acquire locks of the same
    class simultaneously.

    To limit the increase in memory consumption because of the percpu nature
    of that counter, it is now put back under the CONFIG_DEBUG_LOCKDEP
    config option. So the memory consumption increase will only occur if
    CONFIG_DEBUG_LOCKDEP is defined. The lock_class structure, however,
    is reduced in size by 16 bytes on 64-bit archs after ops removal and
    a minor restructuring of the fields.

    This patch also fixes a bug in the increment code as the counter is of
    the 'unsigned long' type, but atomic_inc() was used to increment it.

    Signed-off-by: Waiman Long
    Acked-by: Peter Zijlstra
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: Will Deacon
    Link: http://lkml.kernel.org/r/d66681f3-8781-9793-1dcf-2436a284550b@redhat.com
    Signed-off-by: Ingo Molnar

    Waiman Long
     

16 May, 2018

2 commits


02 Nov, 2017

1 commit

  • Many source files in the tree are missing licensing information, which
    makes it harder for compliance tools to determine the correct license.

    By default all files without license information are under the default
    license of the kernel, which is GPL version 2.

    Update the files which contain no license information with the 'GPL-2.0'
    SPDX license identifier. The SPDX identifier is a legally binding
    shorthand, which can be used instead of the full boiler plate text.

    This patch is based on work done by Thomas Gleixner and Kate Stewart and
    Philippe Ombredanne.

    How this work was done:

    Patches were generated and checked against linux-4.14-rc6 for a subset of
    the use cases:
    - file had no licensing information it it.
    - file was a */uapi/* one with no licensing information in it,
    - file was a */uapi/* one with existing licensing information,

    Further patches will be generated in subsequent months to fix up cases
    where non-standard license headers were used, and references to license
    had to be inferred by heuristics based on keywords.

    The analysis to determine which SPDX License Identifier to be applied to
    a file was done in a spreadsheet of side by side results from of the
    output of two independent scanners (ScanCode & Windriver) producing SPDX
    tag:value files created by Philippe Ombredanne. Philippe prepared the
    base worksheet, and did an initial spot review of a few 1000 files.

    The 4.13 kernel was the starting point of the analysis with 60,537 files
    assessed. Kate Stewart did a file by file comparison of the scanner
    results in the spreadsheet to determine which SPDX license identifier(s)
    to be applied to the file. She confirmed any determination that was not
    immediately clear with lawyers working with the Linux Foundation.

    Criteria used to select files for SPDX license identifier tagging was:
    - Files considered eligible had to be source code files.
    - Make and config files were included as candidates if they contained >5
    lines of source
    - File already had some variant of a license header in it (even if
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

10 Aug, 2017

1 commit

  • Two boots + a make defconfig, the first didn't have the redundant bit
    in, the second did:

    lock-classes: 1168 1169 [max: 8191]
    direct dependencies: 7688 5812 [max: 32768]
    indirect dependencies: 25492 25937
    all direct dependencies: 220113 217512
    dependency chains: 9005 9008 [max: 65536]
    dependency chain hlocks: 34450 34366 [max: 327680]
    in-hardirq chains: 55 51
    in-softirq chains: 371 378
    in-process chains: 8579 8579
    stack-trace entries: 108073 88474 [max: 524288]
    combined max dependencies: 178738560 169094640

    max locking depth: 15 15
    max bfs queue depth: 320 329

    cyclic checks: 9123 9190

    redundant checks: 5046
    redundant links: 1828

    find-mask forwards checks: 2564 2599
    find-mask backwards checks: 39521 39789

    So it saves nearly 2k links and a fair chunk of stack-trace entries, but
    as expected, makes no real difference on the indirect dependencies.

    At the same time, you see the max BFS depth increase, which is also
    expected, although it could easily be boot variance -- these numbers are
    not entirely stable between boots.

    The down side is that the cycles in the graph become larger and thus
    the reports harder to read.

    XXX: do we want this as a CONFIG variable, implied by LOCKDEP_SMALL?

    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Byungchul Park
    Cc: Linus Torvalds
    Cc: Mel Gorman
    Cc: Michal Hocko
    Cc: Nikolay Borisov
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Cc: akpm@linux-foundation.org
    Cc: boqun.feng@gmail.com
    Cc: iamjoonsoo.kim@lge.com
    Cc: kernel-team@lge.com
    Cc: kirill@shutemov.name
    Cc: npiggin@gmail.com
    Cc: walken@google.com
    Link: http://lkml.kernel.org/r/20170303091338.GH6536@twins.programming.kicks-ass.net
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

25 Dec, 2016

1 commit


23 Apr, 2016

1 commit

  • lock_chain::base is used to store an index into the chain_hlocks[]
    array, however that array contains more elements than can be indexed
    using the u16.

    Change the lock_chain structure to use a bitfield to encode the data
    it needs and add BUILD_BUG_ON() assertions to check the fields are
    wide enough.

    Also, for DEBUG_LOCKDEP, assert that we don't run out of elements of
    that array; as that would wreck the collision detectoring.

    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Alfredo Alvarez Fernandez
    Cc: Andrew Morton
    Cc: Linus Torvalds
    Cc: Paul E. McKenney
    Cc: Peter Zijlstra
    Cc: Sedat Dilek
    Cc: Theodore Ts'o
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/20160330093659.GS3408@twins.programming.kicks-ass.net
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

23 Nov, 2015

1 commit

  • There were still a number of references to my old Red Hat email
    address in the kernel source. Remove these while keeping the
    Red Hat copyright notices intact.

    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Arnaldo Carvalho de Melo
    Cc: Jiri Olsa
    Cc: Linus Torvalds
    Cc: Mike Galbraith
    Cc: Peter Zijlstra
    Cc: Stephane Eranian
    Cc: Thomas Gleixner
    Cc: Vince Weaver
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

07 Jun, 2015

1 commit

  • The lock_class iteration of /proc/lock_stat is not serialized against
    the lockdep_free_key_range() call from module unload.

    Therefore it can happen that we find a class of which ->name/->key are
    no longer valid.

    There is a further bug in zap_class() that left ->name dangling. Cure
    this. Use RCU_INIT_POINTER() because NULL.

    Since lockdep_free_key_range() is rcu_sched serialized, we can read
    both ->name and ->key under rcu_read_lock_sched() (preempt-disable)
    and be assured that if we observe a !NULL value it stays safe to use
    for as long as we hold that lock.

    If we observe both NULL, skip the entry.

    Reported-by: Jerome Marchand
    Tested-by: Jerome Marchand
    Signed-off-by: Peter Zijlstra (Intel)
    Cc: Andrew Morton
    Cc: H. Peter Anvin
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Link: http://lkml.kernel.org/r/20150602105013.GS3644@twins.programming.kicks-ass.net
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

11 Nov, 2013

1 commit

  • > kernel/locking/lockdep_proc.c: In function 'seq_lock_time':
    > >> kernel/locking/lockdep_proc.c:424:23: warning: comparison of distinct pointer types lacks a cast [enabled by default]
    >
    > 418 static void seq_lock_time(struct seq_file *m, struct lock_time *lt)
    > 419 {
    > 420 seq_printf(m, "%14lu", lt->nr);
    > 421 seq_time(m, lt->min);
    > 422 seq_time(m, lt->max);
    > 423 seq_time(m, lt->total);
    > > 424 seq_time(m, lt->nr ? do_div(lt->total, lt->nr) : 0);
    > 425 }

    My compiler refuses to actually say that; but it looks wrong in that
    do_div() returns the remainder, not the divisor.

    Reported-by: Fengguang Wu
    Tested-by: Fengguang Wu
    Signed-off-by: Peter Zijlstra
    Cc: Davidlohr Bueso
    Link: http://lkml.kernel.org/r/20131106164230.GE16117@laptop.programming.kicks-ass.net
    Signed-off-by: Ingo Molnar

    Peter Zijlstra
     

06 Nov, 2013

1 commit