Re: locking question: do_mmap(), do_munmap()

Stephen C. Tweedie
1999-10-11T15:50:27Z

Hi,

On Sun, 10 Oct 1999 15:03:45 -0400 (EDT), Alexander Viro
<viro@math.psu.edu> said:

> Hold on. In swap_out_mm() you have to protect find_vma() (OK, it doesn't
> block, but we'll have to take care of mm->mmap_cache) _and_ you'll have to
> protect vma from destruction all way down to try_to_swap_out(). And to
> vma->swapout(). Which can sleep, so spinlocks are out of question
> here.

No, spinlocks would be ideal. The vma swapout codes _have_ to be
prepared for the vma to be destroyed as soon as we sleep. In fact, the
entire mm may disappear if the process happens to exit. Once we know
which page to write where, the swapout operation becomes a per-page
operation, not per-vma.

We had some rather interesting bugs in the 1.0 and 1.2 timeframes
surrounding exactly this. Nowadays we assume that all mm context
disappears as soon as the swapper blocks. We bump the refcount on the
page itself to make the page write safe, but we have to be very careful
indeed to do all the mm manipulations before we get to that stage.

--Stephen