Put lock logging behind DEBUG_LOCKCONTENTION preprocessor directive #24770

pull jonatack wants to merge 2 commits into bitcoin:master from jonatack:change-lock-logging-to-DEBUG_LOCKCONTENTION-one-commit changing 7 files +32 −6
  1. jonatack commented at 10:18 am on April 5, 2022: member

    This is a more minimal, no-frills version of #24734 for backport. The other fixes and improvements in that pull can be done after.

    Copy of the PR 24734 description:

    PRs #22736, #22904 and #23223 changed lock contention logging from a DEBUG_LOCKCONTENTION compile-time preprocessor directive to a runtime lock log category and improved the logging output. This changed the locking from using lock() to try_lock():

    • void Mutex::UniqueLock::lock() acquires the mutex and blocks until it gains access to it

    • bool Mutex::UniqueLock::try_lock() doesn’t block but instead immediately returns whether it acquired the mutex; it may be used by lock() internally as part of the deadlock-avoidance algorithm

    In theory the cost of try_lock might be essentially the same relative to lock. The test-and-set logic of these calls is purported to be ~ constant time, optimised and light/quick if used carefully (i.e. no mutex convoying), compared to system calls, memory/cache coherency and fences, wait queues, and (particularly) lock contentions. See the discussion around #22736 (comment) and after with respect to performance/cost aspects. However, there are reasonable concerns (see here and here) that Base::try_lock() may be potentially costly or risky compared to Base::lock() in this very frequently called code.

    One alternative to keep the run-time lock logging would be to gate the try_lock call behind the logging conditional, for example as proposed in https://github.com/bitcoin/bitcoin/commit/ccd73de1dd969097d34634c2be2fc32b03fbd09e and ACKed here. However, this would add the cost of if (LogAcceptCategory(BCLog::LOCK)) to the hotspot, instead of replacing lock with try_lock, for the most frequent happy path (non-contention).

    It turns out we can keep the advantages of the runtime lock contention logging (the ability to turn it on/off at runtime) while out of prudence putting the try_lock() call and lock logging category behind a DEBUG_LOCKCONTENTION compile-time preprocessor directive, and also still retain the lock logging enhancements of the mentioned PRs, as suggested in #24734 (comment) by W. J. van der Laan, in #22736 (review), and in the linked IRC discussion.

    Proposed here and for backport to v23.

  2. MarcoFalke added the label Needs backport (23.x) on Apr 5, 2022
  3. MarcoFalke added this to the milestone 23.0 on Apr 5, 2022
  4. Put lock logging behind DEBUG_LOCKCONTENTION preprocessor directive 39a34b6877
  5. Add DEBUG_LOCKCONTENTION documentation to the developer notes 4394733331
  6. jonatack force-pushed on Apr 5, 2022
  7. jonatack commented at 10:53 am on April 5, 2022: member
    Added the developer notes commit and headers changes per IRC feedback.
  8. DrahtBot commented at 8:09 pm on April 6, 2022: member

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #24757 (build, ci: add DEBUG_LOCKCONTENTION to –enable-debug and CI by jonatack)
    • #24748 (test/BIP324: functional tests for v2 P2P encryption by stratospher)
    • #24545 (BIP324: Enable v2 P2P encrypted transport by dhruv)
    • #23561 (BIP324: Handshake prerequisites by dhruv)
    • #23443 (p2p: Erlay support signaling by naumenkogs)
    • #23233 (BIP324: Add encrypted p2p transport {de}serializer by dhruv)
    • #21603 (log: Mitigate disk filling attacks by rate limiting LogPrintf by dergoegge)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  9. laanwj commented at 11:55 am on April 8, 2022: member
    Code review ACK 43947333315d07f59e1247bd76e0ba9d35a99e31
  10. jonatack commented at 12:00 pm on April 8, 2022: member
    Copied over the PR description.
  11. fanquake referenced this in commit 6374e24887 on Apr 8, 2022
  12. fanquake referenced this in commit 69cc83df69 on Apr 8, 2022
  13. fanquake merged this on Apr 8, 2022
  14. fanquake closed this on Apr 8, 2022

  15. fanquake removed the label Needs backport (23.x) on Apr 8, 2022
  16. jonatack deleted the branch on Apr 8, 2022
  17. fanquake commented at 12:31 pm on April 8, 2022: member
    Backported in #24807.
  18. sidhujag referenced this in commit a28ef51a18 on Apr 8, 2022
  19. laanwj referenced this in commit 308a2022c0 on Apr 8, 2022
  20. Fabcien referenced this in commit 5d9c53f2a6 on Sep 28, 2022
  21. DrahtBot locked this on Apr 8, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-22 18:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me