diff options
author | Chris Down <chris@chrisdown.name> | 2020-04-01 21:07:27 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2020-04-02 09:35:29 -0700 |
commit | c3d532008661da197997fc6d8098190eef9344ad (patch) | |
tree | c8ce41c0a1244c279675a4ac01c7f06eb190ee49 /mm/page_counter.c | |
parent | f86b810c2610b08afc82218068d1dfeef02dd0a1 (diff) | |
download | linux-c3d532008661da197997fc6d8098190eef9344ad.tar.gz linux-c3d532008661da197997fc6d8098190eef9344ad.tar.bz2 linux-c3d532008661da197997fc6d8098190eef9344ad.zip |
mm, memcg: prevent memory.min load/store tearing
This can be set concurrently with reads, which may cause the wrong value
to be propagated.
Signed-off-by: Chris Down <chris@chrisdown.name>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Roman Gushchin <guro@fb.com>
Cc: Tejun Heo <tj@kernel.org>
Link: http://lkml.kernel.org/r/e809b4e6b0c1626dac6945970de06409a180ee65.1584034301.git.chris@chrisdown.name
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/page_counter.c')
-rw-r--r-- | mm/page_counter.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/mm/page_counter.c b/mm/page_counter.c index 509143f232d8..c56db2d5e159 100644 --- a/mm/page_counter.c +++ b/mm/page_counter.c @@ -17,14 +17,15 @@ static void propagate_protected_usage(struct page_counter *c, unsigned long usage) { unsigned long protected, old_protected; - unsigned long low; + unsigned long low, min; long delta; if (!c->parent) return; - if (c->min || atomic_long_read(&c->min_usage)) { - protected = min(usage, c->min); + min = READ_ONCE(c->min); + if (min || atomic_long_read(&c->min_usage)) { + protected = min(usage, min); old_protected = atomic_long_xchg(&c->min_usage, protected); delta = protected - old_protected; if (delta) @@ -207,7 +208,7 @@ void page_counter_set_min(struct page_counter *counter, unsigned long nr_pages) { struct page_counter *c; - counter->min = nr_pages; + WRITE_ONCE(counter->min, nr_pages); for (c = counter; c; c = c->parent) propagate_protected_usage(c, atomic_long_read(&c->usage)); |