A coredump generated via the coredump socket ends up transferring zeroed data when a mapping contains holes. For a large process that maps a bunch of data that's wasting a ton of work.
Jacob ran into this and Josef has bitched^wcomplained about this to me before. I dislike the coredump_filter bit solution in [1] which stops each PT_LOAD at the last populated page. The problem is real though. I don't think coredump_filter is where we need to solve this. That mask says which kinds of memory to include and it propagates across fork and exec, whereas what is being selected here is an encoding mechanism. I also think that the usermodehelper - may it swiftly die - isn't really salvagable for this and it's not the future anyway. The coredump socket already has a handshake for stuff like this. I always had an idea how this would look like but punted on it back then. So here it is. A server that raises COREDUMP_HEADER in coredump_ack->mask doesn't get the coredump as a plain byte stream but as a sequence of frames. Each one a struct coredump_frame_header followed by what it describes. A data frame carries its bytes. If a server also raises COREDUMP_SPARSE, zero frames are sent for unpopulated mappings. They only indicate how many zero bytes need to be written and to not include data. Reassembling the frames gives back the same coredump. A debugger and everything else still see an ordinary core file and nothing outside the coredump server has to learn anything. Numbers from the selftest in patch 11, on a kernel built from this series: - a process with 128 threads: 1740014 bytes on the socket for a coredump of 1075150848 bytes - a 256MB mapping with one page touched: 170542 bytes on the socket for a coredump of 268890112 bytes - the same 256MB mapping with COREDUMP_HEADER alone: 270993024 bytes on the socket, so the framing overhead itself is under one percent The first one is the interesting case. Almost all of it is thread stacks. All stacks are 8MB reservations that are nearly all holes. And they are holes in the middle of the dump rather than at the end. Link: https://lore.kernel.org/all/[email protected] [1] Signed-off-by: Christian Brauner (Amutable) <[email protected]> --- Christian Brauner (11): selftests/coredump: discard the right amount after the coredump request selftests/coredump: collapse the expected request check into the helper coredump: pin the protocol struct sizes coredump: move the negotiated mask into struct coredump_params coredump: deduplicate the to_skip flush coredump: add COREDUMP_HEADER to the coredump socket protocol coredump: add COREDUMP_SPARSE to the coredump socket protocol tools: sync coredump.h header coredump: frame the coredump when COREDUMP_HEADER is negotiated coredump: describe the holes when COREDUMP_SPARSE is negotiated selftests/coredump: test COREDUMP_HEADER and COREDUMP_SPARSE fs/coredump.c | 178 +++++++-- include/linux/coredump.h | 7 + include/uapi/linux/coredump.h | 65 +++- tools/include/uapi/linux/coredump.h | 65 +++- .../coredump/coredump_socket_protocol_test.c | 415 +++++++++++++++++++-- tools/testing/selftests/coredump/coredump_test.h | 9 +- .../selftests/coredump/coredump_test_helpers.c | 200 +++++++++- 7 files changed, 849 insertions(+), 90 deletions(-) --- base-commit: db2ddb87143519e20a95aa36c60b36107b736a58 change-id: 20260811-work-coredump-sparse-18177d77b014

