util: shorten thread names to avoid Linux truncation #35173

pull l0rinc wants to merge 6 commits into bitcoin:master from l0rinc:l0rinc/thread-name-truncation changing 8 files +14 −13
  1. l0rinc commented at 4:47 PM on April 28, 2026: contributor

    Problem

    Linux limits thread names set through PR_SET_NAME to 15 usable characters:

    The name can be up to 16 bytes long, including the terminating null byte.

    Longer names are silently truncated. Bitcoin Core prefixes system thread names with b-, leaving only 13 bytes for readable names. This makes longer names less useful in system tools, for example b-coinstatsindex and b-txospenderindex, and makes verbose suffixes like b-http_pool_N spend much of the available space.

    The same limit is documented in the existing thread-name helper: https://github.com/bitcoin/bitcoin/blob/8b49e2dd4eed93d08a3d9681d444aaf441ab0037/src/util/threadnames.cpp#L25

    This was noticed during review of #31132 (review)

    Fix

    Shorten the affected OS thread names while keeping them recognizable.

    ThreadPool workers now use a dotted numeric suffix, so HTTP workers are named like b-http.0.

    Indexer thread names are shortened to fit within the Linux limit after the b- prefix:

    basic block filter index -> basicfltridx
    coinstatsindex           -> coinstatsidx
    txospenderindex          -> txospenderidx
    

    Indexer display names, getindexinfo keys, command-line options, and on-disk index paths are unchanged.

    Testing

    See https://godbolt.org/z/GhEsKehh9 for a simple reproducer.

    Alternatively you can start bitcoind on Linux with the affected indexes enabled and read the kernel-visible thread names.

    Before this change, the affected names are truncated or unnecessarily long:

    b-basic block f
    b-coinstatsinde
    b-http_pool_15
    b-txospenderind
    

    After this change, the same check shows compact, untruncated names:

    b-basicfltridx
    b-coinstatsidx
    b-http.15
    b-txospenderidx
    
  2. DrahtBot added the label Utils/log/libs on Apr 28, 2026
  3. DrahtBot commented at 4:47 PM on April 28, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK andrewtoth, hebasto, naiyoma, hodlinator

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34132 (coins: drop error catcher, centralize fatal read handling by l0rinc)

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. util: shorten ThreadPool worker names
    ThreadPool workers currently format their names as `name_pool_N`.
    
    Linux truncates the system thread name to 15 visible bytes, so `b-http_pool_N` spends much of that space on the suffix.
    
    Use a dotted numeric suffix so HTTP worker names become `b-http.N`, leaving more room for longer pool names.
    1d042ee324
  5. index: separate display and thread names
    BaseIndex currently uses the same name for logs, getindexinfo, prune locks, and the sync thread.
    
    Add a separate thread name that defaults to the display name, so later commits can shorten the OS thread name without changing the public index name.
    dd137e7a95
  6. index: shorten basic filter thread name 0fa02ded15
  7. index: shorten coinstats thread name 51df315306
  8. index: shorten txospender thread name 76049dda90
  9. doc: list compact index thread names
    The indexer thread names are no longer just `b-txindex` plus unspecified variants.
    
    List the compact names so the thread-name reference matches the shortened names used to avoid Linux truncation.
    9701d1a6bc
  10. l0rinc force-pushed on Apr 28, 2026
  11. DrahtBot added the label CI failed on Apr 28, 2026
  12. andrewtoth commented at 5:27 PM on April 28, 2026: contributor

    Concept ACK

  13. DrahtBot removed the label CI failed on Apr 28, 2026
  14. hebasto commented at 4:36 PM on April 29, 2026: member

    Before this change, the affected names are truncated or unnecessarily long:

    b-basic block f
    b-coinstatsinde
    b-http_pool_15
    b-txospenderind
    

    After this change, the same check shows compact, untruncated names:

    b-basicfltridx
    b-coinstatsidx
    b-http.15
    b-txospenderidx
    

    Concept ACK.

    b-http_pool_15 fits just fine. Does it really need to be shortened?

  15. l0rinc commented at 4:43 PM on April 29, 2026: contributor

    b-http_pool_15 fits just fine. Does it really need to be shortened?

    The issue is specific to longer pool names. ThreadPool workers get both Bitcoin Core’s b- prefix and the _pool_<n> suffix, so inputfetch_test from #31132 (review) becomes b-inputfetch_test_pool_15. On Linux, that is truncated to b-inputfetch_te, which loses the worker suffix entirely.

  16. naiyoma commented at 5:12 PM on April 30, 2026: contributor

    Concept ACK

  17. in src/index/blockfilterindex.cpp:78 in 9701d1a6bc
      74 | @@ -75,7 +75,7 @@ static std::map<BlockFilterType, BlockFilterIndex> g_filter_indexes;
      75 |  
      76 |  BlockFilterIndex::BlockFilterIndex(std::unique_ptr<interfaces::Chain> chain, BlockFilterType filter_type,
      77 |                                     size_t n_cache_size, bool f_memory, bool f_wipe)
      78 | -    : BaseIndex(std::move(chain), BlockFilterTypeName(filter_type) + " block filter index")
      79 | +    : BaseIndex(std::move(chain), BlockFilterTypeName(filter_type) + " block filter index", BlockFilterTypeName(filter_type) + "fltridx")
    


    hodlinator commented at 6:19 PM on April 30, 2026:

    nit: b-basicfltridx should IMO be renamed to include some version of "block".

        : BaseIndex(std::move(chain), BlockFilterTypeName(filter_type) + " block filter index", BlockFilterTypeName(filter_type).substr(0, 5) + "blkftrdb")
    

    Giving b-basicblkftrdb (15 chars). Uses "DB" instead of "IDX" which is less accurate but shorter. 😬

    Another strategy could be to consider dropping the b--prefix for Linux or all platforms since figuring out which process a thread belongs to shouldn't be too hard. It appears we already shortened the prefix once in the past though, see 386ae0f6916d11d72022cc6f6b62bb2b82594f24.


    naiyoma commented at 9:44 AM on May 1, 2026:

    b-basicfltridx should IMO be renamed to include some version of "block".

    It seems we have to drop something for it to fit. Maybe these other options might work: blkfltrbasic blkfltrbscidx

    Another strategy could be to consider dropping the b--prefix

    I find the prefix useful, as it makes the threads easily identifiable alongside others.


    hodlinator commented at 11:14 AM on May 1, 2026:

    blkfltrbscidx

    Converting "basic" into "bsc" would require implementing something like StripVowels() or adding another function than BlockFilterTypeName() (BlockFilterCrampedName()). Maybe not strictly necessary.

    Maybe one could change the order to: b-blkfltidx<typename> and just let typename be truncated automatically.

    (I think flt is better abbreviation for "filter", ftr feelds like "footer". Much bikeshedding :grin:).

    I find the prefix useful, as it makes the threads easily identifiable alongside others.

    Yeah, I guess it makes it easier to differentiate our threads from those spawned by libraries we depend on.

  18. hodlinator commented at 6:22 PM on April 30, 2026: contributor

    Concept ACK


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: 2026-05-03 06:12 UTC

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