Skip to content

Commit 9ef0a0f

Browse files
rientjestorvalds
authored andcommitted
mm, writeback: prevent race when calculating dirty limits
Setting vm_dirty_bytes and dirty_background_bytes is not protected by any serialization. Therefore, it's possible for either variable to change value after the test in global_dirty_limits() to determine whether available_memory needs to be initialized or not. Always ensure that available_memory is properly initialized. Signed-off-by: David Rientjes <rientjes@google.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Michal Hocko <mhocko@suse.cz> Cc: Rik van Riel <riel@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 14a4e21 commit 9ef0a0f

1 file changed

Lines changed: 1 addition & 4 deletions

File tree

‎mm/page-writeback.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,11 @@ static unsigned long global_dirtyable_memory(void)
261261
*/
262262
void global_dirty_limits(unsigned long *pbackground, unsigned long *pdirty)
263263
{
264+
const unsigned long available_memory = global_dirtyable_memory();
264265
unsigned long background;
265266
unsigned long dirty;
266-
unsigned long uninitialized_var(available_memory);
267267
struct task_struct *tsk;
268268

269-
if (!vm_dirty_bytes || !dirty_background_bytes)
270-
available_memory = global_dirtyable_memory();
271-
272269
if (vm_dirty_bytes)
273270
dirty = DIV_ROUND_UP(vm_dirty_bytes, PAGE_SIZE);
274271
else

0 commit comments

Comments
 (0)