Re: [PATCH 05/17] writeback: quit throttling when signal pending

From: Wu Fengguang
Date: Tue Sep 14 2010 - 05:17:42 EST


On Tue, Sep 14, 2010 at 04:44:37PM +0800, KOSAKI Motohiro wrote:
> > On Tue, Sep 14, 2010 at 04:23:56PM +0800, KOSAKI Motohiro wrote:
> > > > Subject: writeback: quit throttling when fatal signal pending
> > > > From: Wu Fengguang <fengguang.wu@xxxxxxxxx>
> > > > Date: Wed Sep 08 17:40:22 CST 2010
> > > >
> > > > This allows quick response to Ctrl-C etc. for impatient users.
> > > >
> > > > It mainly helps the rare bdi/global dirty exceeded cases.
> > > > In the normal case of not exceeded, it will quit the loop anyway.
> > > >
> > > > CC: Neil Brown <neilb@xxxxxxx>
> > > > Signed-off-by: Wu Fengguang <fengguang.wu@xxxxxxxxx>
> > > > ---
> > > > mm/page-writeback.c | 3 +++
> > > > 1 file changed, 3 insertions(+)
> > > >
> > > > --- linux-next.orig/mm/page-writeback.c 2010-09-12 13:25:23.000000000 +0800
> > > > +++ linux-next/mm/page-writeback.c 2010-09-13 11:39:33.000000000 +0800
> > > > @@ -552,6 +552,9 @@ static void balance_dirty_pages(struct a
> > > > __set_current_state(TASK_INTERRUPTIBLE);
> > > > io_schedule_timeout(pause);
> > > >
> > > > + if (fatal_signal_pending(current))
> > > > + break;
> > > > +
> > > > check_exceeded:
> > > > /*
> > > > * The bdi thresh is somehow "soft" limit derived from the
> > >
> > > I think we need to change callers (e.g. generic_perform_write) too.
> > > Otherwise, plenty write + SIGKILL combination easily exceed dirty limit.
> > > It mean we can see strange OOM.
> >
> > If it's dangerous, we can do without this patch.
>
> How?

As you described.

> > The users can still
> > get quick response in normal case after all.
> >
> > However, I suspect the process is guaranteed to exit on
> > fatal_signal_pending, so it won't dirty more pages :)
>
> Process exiting is delayed until syscall exiting. So, we exit write syscall
> manually if necessary.

Got it, you mean this fix. It looks good. I didn't add "status =
-EINTR" in the patch because the bottom line "written ? : status" will
always select the non-zero written.

diff --git a/mm/filemap.c b/mm/filemap.c
index 3d4df44..f6d2740 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2304,7 +2304,8 @@ again:
written += copied;

balance_dirty_pages_ratelimited(mapping);
-
+ if (fatal_signal_pending(current))
+ break;
} while (iov_iter_count(i));

return written ? written : status;

Thanks,
Fengguang
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/