Re: [PATCH] coredump/fcntl: Add FD_CLOBCOR flag to close fd before dumping core
From: Xin Zhao
Date: Fri Jun 19 2026 - 07:28:48 EST
On Fri, 19 Jun 2026 09:23:30 +0200 Christian Brauner <brauner@xxxxxxxxxx> wrote:
> On Thu, Jun 18, 2026 at 11:07:00AM +0800, Xin Zhao wrote:
> > A coredump typically takes some time to complete. If we happen to hold a
> > write lock with flock just before triggering the coredump, that write lock
> > will not be released during the entire coredump process. As a result,
> > other processes attempting to acquire the same write lock may experience
> > significant delays.
> >
> > To address this, we introduce the F_[GET|SET]FD_EX fcntl operation and the
> > FD_CLOBCOR flag, allowing coredump_wait() to release any file descriptors
> > marked with FD_CLOBCOR. We can also assign the FD_CLOBCOR flag to specific
> > shared memory segments, preventing the coredump from including shared
> > memory that we are not interested in, thereby reducing both the coredump
> > duration and the size of the core file.
> >
> > We actually considered using signals that generate coredumps to perform
> > the actions we wanted in user space. However, since other threads within
> > the process are not frozen when handling these signals, indiscriminately
> > closing an fd can lead to concurrency issues. For example, if the thread
> > that triggered the coredump closes the fd in the signal handler while
> > other threads are using the resources associated with that fd, it could
> > cause secondary corruption of the coredump state.
> >
> > Signed-off-by: Xin Zhao <jackzxcui1989@xxxxxxx>
> > ---
>
> Eew, NAK. No way we're doing this.
> I can see a point in filtering memory that one isn't interested in but
> that has to be built on top of the coredump socket protoctol by
> extending it.
Thank you for your suggestion. Now, besides knowing about MADV_DONTDUMP to
filter out uninteresting memory, I also learned about the new method you
mentioned: the coredump socket protocol.
In addition to the need to filter out uninteresting memory during a core
dump, what I really hope to address is the issue of the flock lock being
held for a long time during the core dump process. I have completely
given up on adding a new fcntl interface to solve this problem. In the v2
version I sent, I called exit_files in coredump_wait to address this
issue. Please let me know if you have any comments on my v2 version.
Link: https://lore.kernel.org/lkml/20260619003900.3546571-1-jackzxcui1989@xxxxxxx/
Thanks
Xin Zhao