Skip to content

Commit

Permalink
mm: vmpressure: Fix a race that would erroneously clear accumulated data
Browse files Browse the repository at this point in the history
Since the code that determines whether data should be cleared and the
code that actually clears the data are in separate spin-locked critical
sections, new data could be generated on another CPU after it is
determined that the existing data should be cleared, but before the
current CPU clears the existing data. This would cause the new data
reported by the other CPU to be lost.

Fix the race by clearing accumulated data within the same spin-locked
critical section that determines whether or not data should be cleared.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Signed-off-by: Khusika Dhamar Gusti <mail@khusika.com>
  • Loading branch information
kerneltoast authored and Khusika Dhamar Gusti committed Aug 22, 2021
1 parent 645f849 commit 1736ebf
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions mm/vmpressure.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ static void vmpressure_global(gfp_t gfp, unsigned long scanned, bool critical,
if (critical)
scanned = calculate_vmpressure_win();

spin_lock(&vmpr->sr_lock);
if (scanned) {
spin_lock(&vmpr->sr_lock);
vmpr->scanned += scanned;
vmpr->reclaimed += reclaimed;

Expand All @@ -347,13 +347,12 @@ static void vmpressure_global(gfp_t gfp, unsigned long scanned, bool critical,
stall = vmpr->stall;
scanned = vmpr->scanned;
reclaimed = vmpr->reclaimed;
spin_unlock(&vmpr->sr_lock);

if (!critical && scanned < calculate_vmpressure_win())
if (!critical && scanned < calculate_vmpressure_win()) {
spin_unlock(&vmpr->sr_lock);
return;
}
}

spin_lock(&vmpr->sr_lock);
vmpr->scanned = 0;
vmpr->reclaimed = 0;
vmpr->stall = 0;
Expand Down

0 comments on commit 1736ebf

Please sign in to comment.