<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>210345</bug_id>
          
          <creation_ts>2020-04-10 10:26:25 -0700</creation_ts>
          <short_desc>[GTK][WPE] lowWatermarkPages() in MemoryPressureMonitor.cpp only searches the &quot;low&quot; value inside the first &quot;Node&quot; section</short_desc>
          <delta_ts>2020-04-23 12:30:08 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKitGTK</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=210916</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>209942</dependson>
    
    <dependson>210346</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Pablo Saavedra">psaavedra</reporter>
          <assigned_to name="Pablo Saavedra">psaavedra</assigned_to>
          <cc>annulen</cc>
    
    <cc>aperez</cc>
    
    <cc>bugs-noreply</cc>
    
    <cc>clopez</cc>
    
    <cc>darin</cc>
    
    <cc>mcrha</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1640248</commentid>
    <comment_count>0</comment_count>
    <who name="Pablo Saavedra">psaavedra</who>
    <bug_when>2020-04-10 10:26:25 -0700</bug_when>
    <thetext>Related to https://bugs.webkit.org/show_bug.cgi?id=209942
See details in https://bugs.webkit.org/show_bug.cgi?id=209942#c18


The lowWatermarkPages() in Source/WebKit/UIProcess/linux/MemoryPressureMonitor.cpp is only searching for the “low” value inside the first “Node” section, without taking into account the kind of the memory zone.

Shouldn&apos;t we be searching for the “Normal” zone node, instead of the first one seen? In my laptop here the first zone is a DMA memory area:

  Node 0, zone      DMA
    per-node stats
        nr_inactive_anon 277959
        nr_active_anon 863174
        ...
    pages free      3951
          min       13 
          low       16
          high      19
          ...

… and picking “16” as the “low” value seems wrong. We will want to fix this to find the node which describes the “Normal” zone:

  Node 0, zone     Normal
    pages free     252746
          min      14907
          low      26572
          high     31069
          ...

Related question: What if there are more multiple nodes which describe nodes of “Normal” type? Should the “low” values be added together in that case?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1640660</commentid>
    <comment_count>1</comment_count>
    <who name="Pablo Saavedra">psaavedra</who>
    <bug_when>2020-04-12 02:52:13 -0700</bug_when>
    <thetext>&quot;I believe that the special zones (DMA, DMA32, and on 32-bit machines, Normal) will only be present on one node, generally node 0. All other nodes will generally have only Normal (on 64-bit kernels) or HighMem (on 32-bit kernels) memory.&quot;

from: https://utcc.utoronto.ca/~cks/space/blog/linux/KernelMemoryZones


Also, this function is only called from calculateMemoryAvailable()


```
// If MemAvailable was not present in /proc/meminfo, because it&apos;s an old kernel version,        
// we can do the same calculation with the information we have from meminfo and the low watermaks.
// See https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773                                                                       
static size_t calculateMemoryAvailable(size_t memoryFree, size_t activeFile, size_t inactiveFile, size_t slabReclaimable, FILE* zoneInfoFile)
{   
    if (memoryFree == notSet || activeFile == notSet || inactiveFile == notSet || slabReclaimable == notSet)
        return notSet;                                                                          
                                                                                                
    size_t lowWatermark = lowWatermarkPages(zoneInfoFile);                                      
    if (lowWatermark == notSet)
        return notSet;           
```


MemAvailable is included in /proc/meminfo since version 3.14 of the kernel; it was added by commit 34e431b0a (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0a)


```
+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.
``

Therefore, the lowWatermark is the sum of the low watermarks across all zones.

However, the Linux kernel maintainers decided the End of Life for 3.14 LTS on September 11, 2016. Maybe is time time to delete this code.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1643361</commentid>
    <comment_count>2</comment_count>
    <who name="Pablo Saavedra">psaavedra</who>
    <bug_when>2020-04-19 23:47:09 -0700</bug_when>
    <thetext>(In reply to Pablo Saavedra from comment #1)

&gt; 
&gt; MemAvailable is included in /proc/meminfo since version 3.14 of the kernel;
&gt; it was added by commit 34e431b0a
&gt; (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/
&gt; ?id=34e431b0a)
&gt; 
&gt; 
&gt; ```
&gt; +MemAvailable: An estimate of how much memory is available for starting new
&gt; +              applications, without swapping. Calculated from MemFree,
&gt; +              SReclaimable, the size of the file LRU lists, and the low
&gt; +              watermarks in each zone.
&gt; +              The estimate takes into account that the system needs some
&gt; +              page cache to function well, and that not all reclaimable
&gt; +              slab will be reclaimable, due to items being in use. The
&gt; +              impact of those factors will vary from system to system.
&gt; ``
&gt; 
&gt; Therefore, the lowWatermark is the sum of the low watermarks across all
&gt; zones.
&gt; 
&gt; However, the Linux kernel maintainers decided the End of Life for 3.14 LTS
&gt; on September 11, 2016. Maybe is time time to delete this code.

Based on https://bugs.webkit.org/show_bug.cgi?id=210346#c3:

```
We would like to decide whether we want to keep supporting kernels
older than 3.14 — but I think it&apos;s better to play safe and keep the
code for now.

If (or when) we decide to remove it, we can use a new bug for that.
```

... let&apos;s keep this as it is and just fix the code to have in account all the eventual Nodes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1643379</commentid>
    <comment_count>3</comment_count>
      <attachid>396954</attachid>
    <who name="Pablo Saavedra">psaavedra</who>
    <bug_when>2020-04-20 00:13:32 -0700</bug_when>
    <thetext>Created attachment 396954
patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1643412</commentid>
    <comment_count>4</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2020-04-20 03:22:57 -0700</bug_when>
    <thetext>Committed r260359: &lt;https://trac.webkit.org/changeset/260359&gt;

All reviewed patches have been landed. Closing bug and clearing flags on attachment 396954.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1644751</commentid>
    <comment_count>5</comment_count>
    <who name="Milan Crha">mcrha</who>
    <bug_when>2020-04-23 06:36:53 -0700</bug_when>
    <thetext>This change is leaking file handles. I see constant additions of the triple:

  /proc/meminfo
  /proc/zoneinfo
  /proc/18738/cgroup

in `lsof -p PID`. It lasts up to the top opened files limit is reached.

You should, in MemoryPressureMonitor::start(), fclose() those which had been opened, both in the &apos;continue&apos; and in the end of the while() (not only after it, which handles the &apos;break&apos; path).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1644752</commentid>
    <comment_count>6</comment_count>
    <who name="Milan Crha">mcrha</who>
    <bug_when>2020-04-23 06:40:41 -0700</bug_when>
    <thetext>s/up to the top/until the/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1644776</commentid>
    <comment_count>7</comment_count>
    <who name="Pablo Saavedra">psaavedra</who>
    <bug_when>2020-04-23 08:33:27 -0700</bug_when>
    <thetext>(In reply to Milan Crha from comment #5)
&gt; This change is leaking file handles. I see constant additions of the triple:
&gt; 
&gt;   /proc/meminfo
&gt;   /proc/zoneinfo
&gt;   /proc/18738/cgroup
&gt; 
&gt; in `lsof -p PID`. It lasts up to the top opened files limit is reached.
&gt; 
&gt; You should, in MemoryPressureMonitor::start(), fclose() those which had been
&gt; opened, both in the &apos;continue&apos; and in the end of the while() (not only after
&gt; it, which handles the &apos;break&apos; path).


Fixup in a couple of minutes. Thanks for take a look it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1644781</commentid>
    <comment_count>8</comment_count>
    <who name="Milan Crha">mcrha</who>
    <bug_when>2020-04-23 08:42:37 -0700</bug_when>
    <thetext>You are welcome. I just faced &quot;out of file descriptors&quot; abort here, otherwise I&apos;d probably not notice at all.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1644785</commentid>
    <comment_count>9</comment_count>
    <who name="Pablo Saavedra">psaavedra</who>
    <bug_when>2020-04-23 08:58:13 -0700</bug_when>
    <thetext>New bug created to link with the new patch https://bugs.webkit.org/show_bug.cgi?id=210916</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1644790</commentid>
    <comment_count>10</comment_count>
    <who name="Milan Crha">mcrha</who>
    <bug_when>2020-04-23 09:10:25 -0700</bug_when>
    <thetext>Thanks. I guess you can close this one.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1644910</commentid>
    <comment_count>11</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2020-04-23 12:30:08 -0700</bug_when>
    <thetext>(In reply to Milan Crha from comment #10)
&gt; Thanks. I guess you can close this one.

Yes, we&apos;ll handle the fix in bug #210916 — and thanks a lot to you
for noticing and reporting the issue =)</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>396954</attachid>
            <date>2020-04-20 00:13:32 -0700</date>
            <delta_ts>2020-04-20 03:22:58 -0700</delta_ts>
            <desc>patch</desc>
            <filename>bug-210345-20200420091304.patch</filename>
            <type>text/plain</type>
            <size>3825</size>
            <attacher name="Pablo Saavedra">psaavedra</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjYwMzUzCmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViS2l0L0No
YW5nZUxvZyBiL1NvdXJjZS9XZWJLaXQvQ2hhbmdlTG9nCmluZGV4IGU5ZDdiOTZlOGU2O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gPSBmYWxzZTsKIApAQCAtODMsMTEg
KzEyMiwxMyBAQCBzdGF0aWMgc2l6ZV90IGxvd1dhdGVybWFya1BhZ2VzKEZJTEUqIHpvbmVJbmZv
RmlsZSkKICAgICAgICAgciA9IGZzY2FuZih6b25lSW5mb0ZpbGUsICIlIiBTVFJJTkdJRlkoWk9O
RUlORk9fVE9LRU5fQlVGRkVSX1NJWkUpICJzIiwgYnVmZmVyKTsKICAgICAgICAgaWYgKHIgPT0g
MSAmJiBpbk5vcm1hbFpvbmUgJiYgIXN0cmNtcChidWZmZXIsICJsb3ciKSkgewogICAgICAgICAg
ICAgciA9IGZzY2FuZih6b25lSW5mb0ZpbGUsICIlenUiLCAmbG93KTsKLSAgICAgICAgICAgIGlm
IChyID09IDEpCi0gICAgICAgICAgICAgICAgYnJlYWs7CisgICAgICAgICAgICBpZiAociA9PSAx
KSB7CisgICAgICAgICAgICAgICAgc3VtTG93ICs9IGxvdzsKKyAgICAgICAgICAgICAgICBjb250
aW51ZTsKKyAgICAgICAgICAgIH0KICAgICAgICAgfQogICAgIH0KLSAgICByZXR1cm4gbG93Owor
ICAgIHJldHVybiBzdW1Mb3c7CiB9CiAKIHN0YXRpYyBpbmxpbmUgc2l6ZV90IHN5c3RlbVBhZ2VT
aXplKCkK
</data>

          </attachment>
      

    </bug>

</bugzilla>