Skip to content

c-abi: worker stacks (2 MiB default) are ~1.1 MB below a real workload's measured 3172 KB high-water #330

Closed as not planned

Description

@vikrantpuppala

Summary

A partner workload drives every kernel-c-abi worker thread to a high-water stack usage
of ~3113 KB (peak 3172 KB). The C-ABI runtime's worker stacks are whatever Rust std's
default gives — 2048 KB — which is ~1.1 MB below the observed requirement. Any
consumer running this workload on the default configuration will overflow a worker stack
and take the process down with a SIGSEGV.

This is not specific to that partner's environment: their threads were 3117 KB (larger
than our default) and still overflowed.

Measurement

LD_PRELOAD interposer on pthread_create that paints each new thread's stack with a
known byte and, at exit, reports the lowest surviving byte (true high-water). Partner ran
their real workload with RUST_MIN_STACK=8388608, which makes it pass:

[stackdiag] RLIMIT_STACK: 8388608 bytes (8192 KB) soft, unlimited hard
[stackdiag] RUST_MIN_STACK: 8388608

  kernel-c-abi   LWP 3947   8192 KB  HW   3172 KB  req 8388608  libdatabricksodbc64.so+0x105ed41
  kernel-c-abi   LWP 3948   8192 KB  HW   3113 KB  req 8388608  libdatabricksodbc64.so+0x105ed41
  ... 30 more workers, all HW 3113-3172 KB ...

Note the uniformity: all ~32 workers reach ~3113 KB, including ones unlikely to have
done heavy work. That points at a cost paid on the worker's startup/first-use path rather
than something proportional to the query workload.

configuration worker stack vs. observed 3172 KB requirement
Rust std default (RUST_MIN_STACK unset) 2048 KB too small by ~1.1 MB
#326 thread_stack_size(2 MiB) 2048 KB too small by ~1.1 MB
partner's actual (pre-workaround) 3117 KB too small — this is what crashed
RUST_MIN_STACK=8388608 (their workaround) 8192 KB ok

Where the stack goes

Recovered from the partner's core dumps by fingerprinting each frame against the string
literals its function references (the shipped driver is stripped). Innermost first:

malloc ← driver Rust allocation code ← reqwest/hyper proxy environment discovery ←
reqwest ClientBuilder::build ← TLS config ← DatabricksHttpClient::new ←
SessionBuilder ← session-config validation ← block_on_ffi ← tokio task/worker
machinery ← worker thread entry.

The 39 frames' own prologues account for only ~15 KB, so the ~3 MB is not explained by that
chain's frame sizes — the remaining consumption is somewhere in that path and still needs
to be localised.

Why this matters for #328

Issue #328 already notes that #326 sets a fixed 2 MiB rather than a floor. This makes
that worse than a cosmetic problem:

  1. 2 MiB is not merely "not larger than the host asked for" — it is demonstrably below
    what a real workload needs
    .
  2. databricks-odbc currently pins 9ecd357, which predates #326. Bumping that pin
    would cap every worker at 2 MiB and could introduce this crash for consumers who today
    get more from their runtime.

Suggested actions

  1. Do not let the ODBC pin move past #326 until the value is revisited.
  2. Make the size a floor (per c-abi: thread_stack_size(2 MiB) is a cap, not a floor — it shrinks workers when RUST_MIN_STACK is larger #328) and set it from measurement — ≥ 8 MiB would clear
    the observed 3172 KB with margin; 4 MiB would be uncomfortably close.
  3. Separately, find what consumes ~3 MB on the session-open path. A per-worker fixed cost
    of 3 MB is worth understanding on its own, independent of the stack sizing.

Reproduction aid

The interposer used for this measurement (odbc_stackdiag.c) installs a per-thread
sigaltstack, so it can also report a guard-page SIGSEGV that would otherwise produce no
usable output at all, and prints for each thread: real bounds, high-water, the stack size
the creator requested, and the creating call site. Happy to attach it.

Activity

  1. vikrantpuppala commented on Sep 9, 2026

    @vikrantpuppala
    CollaboratorAuthor

    Update after inspecting the supplied core3-guardpages.gtest core and reproducing the pthread layout with a standalone probe: the original diagnosis in this issue is incorrect. The reported 3113–3172 KiB is not kernel call-stack usage; odbc_stackdiag.c is counting static TLS as stack.

    Evidence:

    • The partner test executable has a PT_TLS segment with p_memsz = 3,167,285 bytes and p_filesz = 120 bytes. Including the other loaded objects, raw static TLS is about 3,168,645 bytes.
    • glibc/NPTL places static TLS and the thread control block at the high end of each pthread stack mapping.
    • The diagnostic computes stack_hi - deepest_write. That necessarily includes the static TLS region, producing the uniform ~3.1 MiB baseline on every worker even when little ordinary stack has been used.
    • The original 3,192,128-byte mapping was only about 24 KiB larger than the raw TLS allocation, before allowing for alignment/TCB overhead. That is why it overflowed.
    • Measuring from the initial stack pointer instead indicates roughly 19–20 KiB at startup and no more than ~79 KiB at the observed peak.

    A controlled probe with a 3,167,285-byte TLS object reproduced the same geometry: the glibc minimum stack became 3,191,936 bytes; a 3,194,880-byte request left only about 23 KiB usable; and a 2 MiB request could not create the thread because it was below the TLS-aware minimum.

    So the crash is real, but the primary cause is the unusually large static TLS allocation in the partner executable/build, not a ~3 MiB stack requirement in the kernel. I do not think we should raise the kernel-wide floor to 8 MiB. The behavior merged in #329 is the appropriate generic policy: retain the 2 MiB floor while preserving any larger caller-provided RUST_MIN_STACK.

    The partner should identify the large TLS symbol:

    readelf -W -l ./gtest_delta_db_query | grep " TLS "
    readelf -W -s ./gtest_delta_db_query |
      grep " TLS " |
      sort -k3,3nr |
      head -30

    If the binary is stripped, rebuild it with a linker map:

    -Wl,-Map=gtest_delta_db_query.map

    Then inspect the .tbss and .tdata contributors and compare PT_TLS with the production executable. That will tell us whether this is test-only instrumentation/dependency state or production code. The durable fix is to move the multi-megabyte thread_local/__thread object to heap-backed storage (or reduce it).

    As a temporary workaround, 4 MiB leaves roughly 1 MiB for ordinary stack, 6 MiB gives comfortable headroom, and 8 MiB is conservative but unnecessary based on these cores. The partner should validate the chosen temporary value under its full workload. Please share the TLS-symbol or linker-map output so we can identify the exact contributor.

    The diagnostic itself should also be corrected to exclude static TLS/use the initial stack pointer as its ordinary-stack baseline.

  2. github-actions commented on Oct 10, 2026

    @github-actions

    This issue has been marked as Stale because it has been open for 30 days with no activity. If you would like the issue to remain open, please remove the stale label or comment on the issue.

  3. github-actions commented on Oct 18, 2026

    @github-actions

    This issue was closed because it has been inactive for 7 days since being marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions