Re: [patch 6/6] mm: fix pagecache write deadlocks

From: Peter Zijlstra
Date: Sun Oct 15 2006 - 09:53:33 EST



> > > + /*
> > > + * Must not enter the pagefault handler here, because we hold
> > > + * the page lock, so we might recursively deadlock on the same
> > > + * lock, or get an ABBA deadlock against a different lock, or
> > > + * against the mmap_sem (which nests outside the page lock).
> > > + * So increment preempt count, and use _atomic usercopies.
> > > + */
> > > + inc_preempt_count();
> > > if (likely(nr_segs == 1))
> > > - copied = filemap_copy_from_user(page, offset,
> > > + copied = filemap_copy_from_user_atomic(page, offset,
> > > buf, bytes);
> > > else
> > > - copied = filemap_copy_from_user_iovec(page, offset,
> > > - cur_iov, iov_offset, bytes);
> > > + copied = filemap_copy_from_user_iovec_atomic(page,
> > > + offset, cur_iov, iov_offset,
> > > + bytes);
> > > + dec_preempt_count();
> > > +
> >
> > Why use raw {inc,dec}_preempt_count() and not
> > preempt_{disable,enable}()? Is the compiler barrier not needed here? And
> > do we really want to avoid the preempt_check_resched()?
>
> Counter to intuition, we actually don't mind being preempted here,
> but we do mind entering the (core) pagefault handler. Incrementing
> the preempt count causes the arch specific handler to bail out early
> before it takes any locks.
>
> Clear as mud? Wrapping it in a better name might be an improvement?
> Or wrapping it into the copy*user_atomic functions themselves (which
> is AFAIK the only place we use it).

Right, but since you do inc the preempt_count you do disable preemption,
might as well check TIF_NEED_RESCHED when enabling preemption again.

Sticking it in the atomic copy functions does make sense to me.

-
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/