Pre-split large GZIP Parquet write batches to bound GPU scratch memory #17303
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #17303"
general
weight: 0.35
thirtiseven
Contributes to #17272.
Description
Table.writeParquetChunkedwithCompressionType.GZIPpasses all Parquet pages across all row groups of the input table into a singlenvcomp::batched_compresscall inlibcudf, allocating temporary device scratch memory up to ~15x–19x the input table size (tracked in NVIDIA/cudf#25680). On 16 GiB GPUs (such as T4) with defaultspark.rapids.sql.batchSizeBytes=1g, writing wide ~1 GiB GZIP Parquet batches consistently triggersGpuSplitAndRetryOOM, host spilling, and write slowdowns even with a single active GPU task.This PR adds a plugin-side mitigation that pre-splits oversized GZIP Parquet write batches into smaller spillable slices before calling
tableWriter.write, with no new user-facing configuration and no changes to non-GZIP codecs:GpuDeviceManager.getPoolSizeLimit(private[rapids]).protected def maxWriteBatchBytes: Option[Long] = NonetoColumnarOutputWriterand split incomingSpillableColumnarBatches exceeding that cap (whilenumRows > 1) viacontiguousSplitbefore encoding. Slices are prepended back ontopendingin original row order so oversized slices from skewed variable-width rows are split again until each multi-row slice fits the cap (stopping at 1 row). Pre-splitting runs underwithRetry(..., splitSpillableInHalfByRows)when retry is enabled, is timed undernvtxId/gpuTime, and preserves single-invocationstatsTrackers.newBatch, semaphore release before FS I/O, and leak-free cleanup on failure.Cuda.DEFAULT_STREAM.sync()inSpillableColumnarBatch.apply(ContiguousTable, ...)withcloseOnExcept(ct)so a stream failure cannot leak the contiguous table during ownership transfer.maxWriteBatchBytesinGpuParquetWriter(covering Spark Parquet, Delta Lake, and Iceberg) andGpuHiveParquetWriterforCompressionType.GZIPtomath.max(poolSize / 64, 64 MiB)whenpoolSize > 0(~210–224 MiB slices on 16 GiB GPUs, leaving 80 GiB GPUs unsplit for default 1 GiB batches). Note that whenspark.rapids.sql.format.parquet.writer.rowGroupSizeBytesis configured larger than this cap on smaller GPUs, each chunkedtableWriter.writecall flushes row groups bounded by the slice size.GpuFileFormatDataWriterSuiteverifyingGpuParquetFileFormat.maxWriteBatchBytesForPool, pre-splitting and exact row order/content preservation, singlenewBatchinvocation, 1-row batches,GpuSplitAndRetryOOMduring both pre-splitting and slice encoding, skewed variable-width string re-splitting (including single oversized rows), and zero-leak cleanup on unhandled failure.Validation
sql-plugin,aggregator,dist, andintegration_testswith Spark 3.5.2 / Scala 2.12 (mvn -Dbuildver=352 install -pl sql-plugin,aggregator,dist,integration_tests -DskipTests -Dmaven.scaladoc.skip=true): succeeded (including Apache RAT).GpuFileFormatDataWriterSuite): 52/52 passed, 0 failed, 0 RMM leaks (including isolated runs of both new pre-split tests).TEST_PARALLEL=1 ./integration_tests/run_pyspark_from_build.sh -k '(parquet_write or hive_parquet_write or hive_write) and gzip'): 4/4 passed (test_write_gzip_parquet_into_hive_table,test_optimized_hive_ctas_gzip,test_compress_write_round_trip[gzip],test_parquet_write_gzip_save_as_table).antrun:run@scalastyle-all-modules): 0 errors, 0 warnings across 2,154 files.python3 scripts/check_with_resource_nesting.py: passed (0 baselined violations).python3 build/check_shim_compatibility.py coverage: PASS (0 findings across 34 buildvers).Performance
Measured on the latest head on RTX 5880 Ada with Spark 3.5.2 (
local[1], 13.4 GiB RMM ARENA pool simulating a 16 GiB GPU viaallocFraction=0.29,maxAllocFraction=0.29, defaultspark.rapids.sql.batchSizeBytes=1g, 59-column synthetic table matching the reproducer in #17272):| Workload | Before (
main) | After (this PR) ||---|---|---|
| Single ~1.0 GiB batch (
1.25Mrows,gzip) |0.98s, 1 split-retry,7.86 GBfootprint (14.77 GBuncapped) |1.02s, 0 retries,0.0 MiBspill,3.69 GBfootprint || Multi-batch ~3.0 GiB (
3.75Mrows,gzip) |5.88s, 4 split-retries,1,350.3 MiBspill,12.99 GBfootprint |2.06s(2.85x faster), 0 retries,0.0 MiBspill,5.88 GBfootprint || Single ~1.0 GiB batch (
snappy/zstdcontrol) |2.76 GB/4.52 GB|2.76 GB/4.52 GB(unchanged) |Readback row counts of GZIP output matched expected counts identically (
1,250,000and3,750,000).AI assistance was used to investigate the issue, implement the changes and tests, and prepare this description.
Checklists
Documentation
Testing
(Please provide the names of the existing tests in the PR description.)
Performance