Commit 336ca8c
[SPARK-49386][CORE][SQL][FOLLOWUP] More accurate memory tracking for memory based spill threshold
### What changes were proposed in this pull request?
This is a followup of #47856 . It makes the memory tracking more accurate in several places:
1. In `ShuffleExternalSorter`/`UnsafeExternalSorter`, the memory is used by both the sorter itself, and its underlying in-memort sorter (for sorting shuffle partition ids). We need to add them up to calcuate the current memory usage.
2. In `ExternalAppendOnlyUnsafeRowArray`, the records are inserted to an in-memory buffer first. If the buffer gets too large (currently based on num records), we switch to `UnsafeExternalSorter`. The in-memory buffer also needs a memory based threshold
### Why are the changes needed?
More accurate memory tracking results to better spill decisions
### Does this PR introduce _any_ user-facing change?
No, the feature is not released yet.
### How was this patch tested?
existing tests
### Was this patch authored or co-authored using generative AI tooling?
no
Closes #52190 from cloud-fan/spill.
Lead-authored-by: Wenchen Fan <cloud0fan@gmail.com>
Co-authored-by: Wenchen Fan <wenchen@databricks.com>
Signed-off-by: Yi Wu <yi.wu@databricks.com>1 parent 65c5775 commit 336ca8c
File tree
14 files changed
+142
-89
lines changed- core/src/main
- java/org/apache/spark
- shuffle/sort
- util/collection/unsafe/sort
- scala/org/apache/spark/internal/config
- sql/core/src
- main
- java/org/apache/spark/sql/execution
- scala/org/apache/spark/sql/execution
- aggregate
- joins
- python
- window
- test/scala/org/apache/spark/sql/execution
14 files changed
+142
-89
lines changedLines changed: 18 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
| 145 | + | |
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
| 317 | + | |
322 | 318 | | |
323 | 319 | | |
324 | 320 | | |
| |||
342 | 338 | | |
343 | 339 | | |
344 | 340 | | |
| 341 | + | |
345 | 342 | | |
346 | 343 | | |
347 | 344 | | |
348 | 345 | | |
349 | | - | |
350 | 346 | | |
351 | 347 | | |
352 | 348 | | |
| |||
417 | 413 | | |
418 | 414 | | |
419 | 415 | | |
| 416 | + | |
420 | 417 | | |
421 | 418 | | |
422 | 419 | | |
| |||
432 | 429 | | |
433 | 430 | | |
434 | 431 | | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
439 | 443 | | |
440 | 444 | | |
441 | 445 | | |
| |||
453 | 457 | | |
454 | 458 | | |
455 | 459 | | |
456 | | - | |
457 | 460 | | |
458 | 461 | | |
459 | 462 | | |
| |||
Lines changed: 24 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
| 143 | + | |
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
| 147 | + | |
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
| 160 | + | |
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | | - | |
| 190 | + | |
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
251 | | - | |
252 | 251 | | |
253 | 252 | | |
254 | 253 | | |
| |||
264 | 263 | | |
265 | 264 | | |
266 | 265 | | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
| 266 | + | |
272 | 267 | | |
273 | 268 | | |
274 | 269 | | |
| |||
320 | 315 | | |
321 | 316 | | |
322 | 317 | | |
| 318 | + | |
323 | 319 | | |
324 | 320 | | |
325 | 321 | | |
| |||
378 | 374 | | |
379 | 375 | | |
380 | 376 | | |
| 377 | + | |
381 | 378 | | |
382 | 379 | | |
383 | 380 | | |
| |||
448 | 445 | | |
449 | 446 | | |
450 | 447 | | |
| 448 | + | |
451 | 449 | | |
452 | 450 | | |
453 | 451 | | |
| |||
495 | 493 | | |
496 | 494 | | |
497 | 495 | | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
502 | 507 | | |
503 | 508 | | |
504 | 509 | | |
| |||
514 | 519 | | |
515 | 520 | | |
516 | 521 | | |
517 | | - | |
518 | 522 | | |
519 | 523 | | |
520 | 524 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1599 | 1599 | | |
1600 | 1600 | | |
1601 | 1601 | | |
1602 | | - | |
| 1602 | + | |
1603 | 1603 | | |
1604 | | - | |
| 1604 | + | |
1605 | 1605 | | |
1606 | 1606 | | |
1607 | 1607 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | | - | |
| 171 | + | |
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| |||
0 commit comments