mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	mm, memcg: prevent memory.low 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/448206f44b0fa7be9dad2ca2601d2bcb2c0b7844.1584034301.git.chris@chrisdown.name Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									15b42562d4
								
							
						
					
					
						commit
						f86b810c26
					
				
					 1 changed files with 5 additions and 3 deletions
				
			
		| 
						 | 
					@ -17,6 +17,7 @@ static void propagate_protected_usage(struct page_counter *c,
 | 
				
			||||||
				      unsigned long usage)
 | 
									      unsigned long usage)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	unsigned long protected, old_protected;
 | 
						unsigned long protected, old_protected;
 | 
				
			||||||
 | 
						unsigned long low;
 | 
				
			||||||
	long delta;
 | 
						long delta;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!c->parent)
 | 
						if (!c->parent)
 | 
				
			||||||
| 
						 | 
					@ -30,8 +31,9 @@ static void propagate_protected_usage(struct page_counter *c,
 | 
				
			||||||
			atomic_long_add(delta, &c->parent->children_min_usage);
 | 
								atomic_long_add(delta, &c->parent->children_min_usage);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (c->low || atomic_long_read(&c->low_usage)) {
 | 
						low = READ_ONCE(c->low);
 | 
				
			||||||
		protected = min(usage, c->low);
 | 
						if (low || atomic_long_read(&c->low_usage)) {
 | 
				
			||||||
 | 
							protected = min(usage, low);
 | 
				
			||||||
		old_protected = atomic_long_xchg(&c->low_usage, protected);
 | 
							old_protected = atomic_long_xchg(&c->low_usage, protected);
 | 
				
			||||||
		delta = protected - old_protected;
 | 
							delta = protected - old_protected;
 | 
				
			||||||
		if (delta)
 | 
							if (delta)
 | 
				
			||||||
| 
						 | 
					@ -222,7 +224,7 @@ void page_counter_set_low(struct page_counter *counter, unsigned long nr_pages)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct page_counter *c;
 | 
						struct page_counter *c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	counter->low = nr_pages;
 | 
						WRITE_ONCE(counter->low, nr_pages);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (c = counter; c; c = c->parent)
 | 
						for (c = counter; c; c = c->parent)
 | 
				
			||||||
		propagate_protected_usage(c, atomic_long_read(&c->usage));
 | 
							propagate_protected_usage(c, atomic_long_read(&c->usage));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue