Skip to content

fix: [branch-1.1] log partial memory grants at DEBUG and drop the memory usage dump (#6269) - #6346

Merged
andygrove merged 1 commit into
apache:branch-1.1from
andygrove:backport-6269-branch-1.1
Sep 28, 2026
Merged

andygrove merged 1 commit into
apache:branch-1.1from
andygrove:backport-6269-branch-1.1

Conversation

@andygrove

Copy link
Copy Markdown
Member

Backport of #6269 to branch-1.1.

Cherry-picked from e1d2c11729c2fc60a5def4e87bb17e5b28df2a29 without conflicts. The three files it changes are identical on branch-1.1 and on main just before #6269, so the diff is byte-identical to upstream.

Which issue does this PR close?

Closes #6257 on branch-1.1. #6269 already closed it on main.

Rationale for this change

#6269 merged after branch-1.1 was cut at 36ab57c, so without this 1.1.0 ships both of the problems it fixes:

  • Every time Spark grants a native memory pool less than it asked for, CometTaskMemoryManager.acquireMemory logs a warning and then calls TaskMemoryManager.showMemoryUsage(), which logs at least three more lines at INFO. A partial grant is routine under memory pressure, since it is how a native operator learns to spill, so a query that spills floods the executor log.
  • showMemoryUsage() takes the TaskMemoryManager monitor. Another acquire of the same task can hold that monitor while it waits inside Spark for memory, and the thread that got the short grant keeps those bytes until it returns to native code. The task then hangs until some other task frees memory. The memory pools on branch-1.1 are the same as on main, so greedy_unified, which calls Spark without a lock, can reach this. The default fair_unified holds its lock across the call, which rules the cycle out between two native threads of a task; fix: log partial memory grants at DEBUG and drop the memory usage dump #6269 has the details. sunchao found the cycle while reviewing perf: stop holding the fair pool lock across blocking memory calls #5613.

Only logging changes. A partial grant is now logged at DEBUG, and the memory dump is gone. A reservation that really fails still says in its error how much Spark granted and which consumers hold the most memory.

What changes are included in this PR?

The original change, so see #6269 for the details. No adaptations were needed. In short:

  • acquireMemory logs a partial grant at DEBUG, behind isDebugEnabled(), and no longer calls showMemoryUsage(). A comment says why the method must not take the TaskMemoryManager monitor.
  • Two new tests in CometTaskMemoryManagerSuite, which now extends SparkFunSuite so that it can use withLogAppender.
  • The debugging guide explains why these lines are at DEBUG and how to turn them on.

How are these changes tested?

The original PR's tests, run locally on branch-1.1 with JDK 17:

  • CometTaskMemoryManagerSuite passes, 5 tests, on the default profile (Spark 4.1, Scala 2.13) and on Spark 3.4 with Scala 2.12. The build's spotless and scalastyle checks ran and passed in both.
  • With CometTaskMemoryManager.java reverted to branch-1.1's copy, both new tests fail. The INFO-level test captures two warnings and eight dump lines, the same as fix: log partial memory grants at DEBUG and drop the memory usage dump #6269 reported on main.

Against branch-1.1, the changed paths route this pull request to every suite except Spark 3.4's SQL job, the PyArrow UDF job and the benchmark check.

apache#6269)

CometTaskMemoryManager.acquireMemory logged a warning, then called
TaskMemoryManager.showMemoryUsage, every time Spark granted less memory than a
native pool asked for. A partial grant is how a native operator learns to spill,
so a query that spills logged hundreds of them. Log the partial grant at DEBUG
instead. A refusal that fails the task already says in its error what Spark
granted and lists the pool's top consumers.

Drop the dump rather than moving it to DEBUG. showMemoryUsage takes the
TaskMemoryManager monitor. Another acquire of the same task can hold that
monitor while it waits inside Spark for memory, and this thread still holds its
partial grant. The task then hangs until some other task frees memory.
greedy_unified can reach this on main, because it calls Spark without a lock.
sunchao found the cycle while reviewing apache#5613.

Closes apache#6257.

(cherry picked from commit e1d2c11)
@github-actions github-actions Bot added bug Something isn't working area:memory Memory pools, reservations, OOM handling labels Sep 28, 2026
long newUsed = used.addAndGet(acquired);
if (acquired < size) {
logger.warn(
// A partial grant is routine, not an error: the native pool either refuses the reservation,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this comment can be simplified

@comphead comphead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @andygrove

@andygrove
andygrove merged commit 021c378 into apache:branch-1.1 Sep 28, 2026
35 checks passed
@andygrove
andygrove deleted the backport-6269-branch-1.1 branch September 28, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:memory Memory pools, reservations, OOM handling bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants