On Wed, Sep 23, 2020 at 04:01:14PM +0200, Jan Kara wrote:...
On Wed 23-09-20 09:50:04, Peter Xu wrote:
But the problem is that if you apply mm->has_pinned check on file pages,
you can get false negatives now. And that's not acceptable...
Do you mean the case where proc A pinned page P from a file, then proc B
mapped the same page P on the file, then fork() on proc B?
Yes.
If proc B didn't explicitly pinned page P in B's address space too,
shouldn't we return "false" for page_likely_dma_pinned(P)? Because if
proc B didn't pin the page in its own address space, I'd think it's ok to
get the page replaced at any time as long as the content keeps the same.
Or couldn't we?
So it depends on the reason why you call page_likely_dma_pinned(). For your
COW purposes the check is correct but e.g. for "can filesystem safely
writeback this page" the page_likely_dma_pinned() would be wrong. So I'm
not objecting to the mechanism as such. I'm mainly objecting to the generic
function name which suggests something else than what it really checks and
thus it could be used in wrong places in the future... That's why I'd
prefer to restrict the function to PageAnon pages where there's no risk of
confusion what the check actually does.
How about I introduce the helper as John suggested, but rename it to
page_maybe_dma_pinned_by_mm()
?
Then we also don't need to judge on which is more likely to happen (between
"maybe" and "likely", since that will confuse me if I only read these words..).
I didn't use any extra suffix like "cow" because I think it might be useful for
things besides cow. Fundamentally the new helper will be mm-based, so "by_mm"
seems to suite better to me.
Does that sound ok?