Re: [PATCH 1/2] mm, memcg: Avoid stale protection values when cgroup is above protection

Chris Down
2020-04-30T01:16:32Z

Hi Yafang,

Yafang Shao writes:
>Would you pls. add some comments above these newly added WRITE_ONCE() ?
>E.g.
>What does them mean to fix ?
>Why do we must add WRITE_ONCE() and READ_ONCE here and there all over
>the memcg protection ?
>Otherwise, it may be harder to understand by the others.

There is already discussion in the changelogs for previous store tear
improvements. For example, b3a7822e5e75 ("mm, memcg: prevent
mem_cgroup_protected store tearing").

WRITE_ONCE and READ_ONCE are standard compiler barriers, in this case, to avoid
store tears from writes in another thread (effective protection caching is
designed by its very nature to permit racing, but tearing is non-ideal).

You can find out more about them in the "COMPILER BARRIER" section in
Documentation/memory-barriers.txt. I'm not really seeing the value of adding an
extra comment about this specific use of them, unless you have some more
explicit concern.