kvikio: Segmentation fault when using RemoteFile.pread on multiple remote files
The following script, which uses RemoteFile.open_s3 followed by a pread on multiple s3 objects, segfaults.
import cupy as cp
import kvikio
BUCKET = "kvikiobench-56481"
def main():
paths = [
f"data/parquet-large/timeseries.parquet/part.{i}.parquet" for i in range(4)
]
def pread_one(path):
rf = kvikio.RemoteFile.open_s3(BUCKET, path)
buf = cp.empty(rf.nbytes() // 8)
return rf.pread(buf)
not_done = {pread_one(path) for path in paths}
# spin lock, till we're done
while not_done:
not_done = {
x for x in not_done if not x.done()
}
print("Parallel done")
if __name__ == "__main__":
main()
I’m not a gdb expert, but here’s some output indicating the failure happens in kvikio::RemoteHandle::read:
$ gdb python
[...]
Reading symbols from python...
(gdb) run bug.py
Starting program: /home/ubuntu/miniforge3/envs/kvikio-env/bin/python bug.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff4400640 (LWP 8711)]
[New Thread 0x7ffff3a00640 (LWP 8712)]
[New Thread 0x7fffe3000640 (LWP 8713)]
[Detaching after vfork from child process 8714]
[New Thread 0x7fffd3c00640 (LWP 8715)]
[Thread 0x7fffd3c00640 (LWP 8715) exited]
[New Thread 0x7fffd3c00640 (LWP 8716)]
[New Thread 0x7fffc5e00640 (LWP 8720)]
[New Thread 0x7fffc1e00640 (LWP 8721)]
[New Thread 0x7fffc1400640 (LWP 8722)]
Thread 8 "python" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffc1e00640 (LWP 8721)]
0x00007fffd428bf97 in kvikio::RemoteHandle::read(void*, unsigned long, unsigned long) () from /home/ubuntu/miniforge3/envs/kvikio-env/lib/python3.12/site-packages/kvikio/_lib/../../../../libkvikio.so
As an aside, would this be the recommended way to read multiple objects in parallel, without having to use Python threads?
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 17 (17 by maintainers)
Agree, I think this is the best solution and I don’t think that the overhead is an issue now that we have
gds_threshold(we didn’t have the GDS threshold when IOFuture was implemented). But we should confirm the performance impact before deciding.OK, upon second read of the
parallel_operation.hppcode I see what we’re doing there. The future returned fromparallel_iois just calling get on each contained future, but the actual I/O tasks have been submitted to the pool insubmit_taskand are running asynchronously. The downside with the current approach is that the returned future is set up such that (because it is submitted withlaunch::deferred, which does not execute untilwaitorgetis called on the future) there is no way to check if the data is available without blocking the main thread. IMHO the change in #596 isn’t quite what we want because it convertsdoneto a blocking operation. I would instead suggest that what we want is to also submit thegather_taskslambda to the pool and use one of the pool’s threads to cycle and check for completion. That preserves the ability to use the returned future in an asynchronous manner by checking for completion in a non-blocking way. WDYT? Alternatively, we could return a custom type instead of a std::future and have that type support querying the completion of all constituent tasks on the main thread without forcing a wait.In the
file_handle.cppI don’t follow your logic forit seems like if these are unlikely to become the bottleneck, we should just execute them synchronously. For API consistency I could see returning a future, but it seems like we want to put the
waitcall directly here. There is no version where we call these APIs where we don’t eventually want the result, right? So what’s the benefit of doing it lazily if all the deferred work still has to be done eventually and it is also not going to be parallelized?I guess we have three overall design options:
Generally, I would say that C++ developers expect minimal ownership and Python developers expect full ownership management.
I am leaning towards option 3 to keep the Python API as close as possible to the C++ API. And I don’t think the performance overhead of ownership management will become an issue in this (fairly expensive) IO context.
Anyways, no matter the design option we choose, it should be implemented throughout KvikIO (not just for IOFutures).
Ah, this is a nasty gotcha.
preaddoesn’t hold a reference tobuf, so you allocatebufin yourpread_onefunction but it is dropped by the time we try to read into the actual pointer.