Re: [PATCH] mm, oom: fix potential data corruption when oom_reaper races with writer

From: Tetsuo Handa
Date: Fri Aug 04 2017 - 12:49:44 EST


Michal Hocko wrote:
> And that's why we still see the corruption. That, however, means that
> the MMF_UNSTABLE implementation has to be more complex and we have to
> hook into all anonymous memory fault paths which I hoped I could avoid
> previously.

I don't understand mm internals including pte/ptl etc. , but I guess that
the direction is correct. Since the OOM reaper basically does

Set MMF_UNSTABLE flag on mm_struct.
For each reapable page in mm_struct {
Take ptl lock.
Remove pte.
Release ptl lock.
}

the page fault handler will need to check MMF_UNSTABLE with lock held.

For each faulted page in mm_struct {
Take ptl lock.
Add pte only if MMF_UNSTABLE flag is not set.
Release ptl lock.
}