Title: [260359] trunk/Source/WebKit
Revision
260359
Author
psaave...@igalia.com
Date
2020-04-20 03:22:53 -0700 (Mon, 20 Apr 2020)

Log Message

[GTK][WPE] lowWatermarkPages() in MemoryPressureMonitor.cpp only searches the "low" value inside the first "Node" section
https://bugs.webkit.org/show_bug.cgi?id=210345

Reviewed by Adrian Perez de Castro.

* UIProcess/linux/MemoryPressureMonitor.cpp:
(WebKit::lowWatermarkPages):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (260358 => 260359)


--- trunk/Source/WebKit/ChangeLog	2020-04-20 09:54:34 UTC (rev 260358)
+++ trunk/Source/WebKit/ChangeLog	2020-04-20 10:22:53 UTC (rev 260359)
@@ -1,3 +1,13 @@
+2020-04-20  Pablo Saavedra  <psaave...@igalia.com>
+
+        [GTK][WPE] lowWatermarkPages() in MemoryPressureMonitor.cpp only searches the "low" value inside the first "Node" section
+        https://bugs.webkit.org/show_bug.cgi?id=210345
+
+        Reviewed by Adrian Perez de Castro.
+
+        * UIProcess/linux/MemoryPressureMonitor.cpp:
+        (WebKit::lowWatermarkPages):
+
 2020-04-20  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK][WPE] Enable resource load statistics

Modified: trunk/Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp (260358 => 260359)


--- trunk/Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp	2020-04-20 09:54:34 UTC (rev 260358)
+++ trunk/Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp	2020-04-20 10:22:53 UTC (rev 260359)
@@ -66,9 +66,48 @@
 #define STRINGIFY(val) STRINGIFY_EXPANDED(val)
 #define ZONEINFO_TOKEN_BUFFER_SIZE 128
 
+// The lowWatermark is the sum of the low watermarks across all zones as the
+// MemAvailable info was implemented in /proc/meminfo since version 3.14 of the
+// kernel (added by commit 34e431b0a, source git.kernel.org):
+//
+// MemAvailable: An estimate of how much memory is available for starting new
+//               applications, without swapping. Calculated from MemFree,
+//               SReclaimable, the size of the file LRU lists, and the low
+//               watermarks in each zone.
+//               The estimate takes into account that the system needs some
+//               page cache to function well, and that not all reclaimable
+//               slab will be reclaimable, due to items being in use. The
+//               impact of those factors will vary from system to system.
+//
+// The fscanf() reads the input stream file until the argument list passed as
+// parameters is successfully filled.
+//
+// In our immplemetation the `while (!feof(zoneInfoFile))` loop follows the next
+// logic:
+//
+// - the first `fscanf(zoneInfoFile, " Node %*u, zone %...[^\n]\n", buffer);`
+//   iterates the `Node` sections.
+// - Then, when we found a Normal node, we start to read each single
+//   `fscanf(zoneInfoFile, "%...s", buffer);` until find a `low` token.
+// - We read the next token which is the actual `low` value and we add it to the
+//   `sumLow` summation.
+//
+// The second fscanf() reads tokens one by one because the format of each row is
+// not homogeneous (2, 3 or 6 values):
+//
+//   Node 0, zone   Normal
+//     pages free     27303
+//           min      20500
+//           low      24089
+//           high     27678
+//           spanned  3414016
+//           present  3414016
+//           managed  3337293
+//           protection: (0, 0, 0, 0, 0)
 static size_t lowWatermarkPages(FILE* zoneInfoFile)
 {
     size_t low = 0;
+    size_t sumLow = 0;
     char buffer[ZONEINFO_TOKEN_BUFFER_SIZE + 1];
     bool inNormalZone = false;
 
@@ -83,11 +122,13 @@
         r = fscanf(zoneInfoFile, "%" STRINGIFY(ZONEINFO_TOKEN_BUFFER_SIZE) "s", buffer);
         if (r == 1 && inNormalZone && !strcmp(buffer, "low")) {
             r = fscanf(zoneInfoFile, "%zu", &low);
-            if (r == 1)
-                break;
+            if (r == 1) {
+                sumLow += low;
+                continue;
+            }
         }
     }
-    return low;
+    return sumLow;
 }
 
 static inline size_t systemPageSize()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to