Locking on pagecache_lock is no way to stabilize page count, but this
doesn't need it stabilized: it's just checking there's nothing but us
which can be interested in the page. Okay, we now know that
read_swap_cache_async can get "interested" in surprising pages (when
the swap entry it asks for has meanwhile been replaced), but I don't
see how that endangers the logic here - it could briefly bump count
too high to pass the "don't write" test, but that errs on the safe side.
If you think this racy, how come you still allow "exclusive_swap_page"
use elsewhere? Actually, I think these tests would be better replaced
by use of "exclusive_swap_page", wouldn't they? But perhaps I'll find
I'm off-by-one when I try it tomorrow.
> Another way to fix the race is to change lookup_swap_cache to do
> find_lock_page instead of find_get_page, and then check the page is
> still a swapcachepage after you got it locked (that was the old way,
> somebody changed it and introduced the race, I like lookup_swap_cache to
> use find_get_page so I dropped such check to fix it, it was a minor
> optimization but yes probably worthwhile to reintroduce after addressing
> this race in one of the two ways described).
Well, I certainly agree the system can survive without this optimization,
and I wouldn't want to restore it if it were buggy. I just don't see
the scenario you're afraid of, and nobody had questioned it before.
> It is also buggy, if something it should be "page_count(page) != 1" (not
> != 2).
I don't think so: as the comment says, one for the page cache,
one for the caller of writepage, one (perhaps) for page->buffers.
Hugh
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/