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: UtsavBalar1231 <utsavbalar1231@gmail.com>
  • Loading branch information
kerneltoast authored and UtsavBalar1231 committed Jul 14, 2021
1 parent 5e70453 commit d220bf4
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 @@ -352,8 +352,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 @@ -363,13 +363,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 d220bf4

Please sign in to comment.