mm: vmpressure: Fix a race that would erroneously clear accumulated data

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>
fourteen
Sultan Alsawaf 4 years ago committed by Jenna
parent b40c4e120b
commit faf978cab1
  1. 9
      mm/vmpressure.c

@ -353,8 +353,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;
@ -364,13 +364,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;

Loading…
Cancel
Save