<?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>180861</bug_id>
          
          <creation_ts>2017-12-15 02:47:18 -0800</creation_ts>
          <short_desc>[GTK][WPE] Enable WebProcess memory monitor</short_desc>
          <delta_ts>2018-04-18 16:01:43 -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>WebKit2</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=180862</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=183773</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>Gtk, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Carlos Garcia Campos">cgarcia</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>bugs-noreply</cc>
    
    <cc>clopez</cc>
    
    <cc>mcatanzaro</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1382111</commentid>
    <comment_count>0</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2017-12-15 02:47:18 -0800</bug_when>
    <thetext>For some reason this is only enabled in mac. We want to enable it also in GTK and WPE ports. This runs every 30 seconds to release memory or even kill the process if necessary. Carlos López has realized that in some applications using video tags, the memory grows a lot and it&apos;s never released. It seems it&apos;s not memory leaked, but simply large memory allocations (I guess it&apos;s gst allocating video frames) that make the heap grow. The memory pressure calls malloc_trim that releases all that memory keeping the web process footprint stable. Since enabling this can make the web process to be killed, we need to expose the web process termination reason in the API. I&apos;ll file another bug for this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1382112</commentid>
    <comment_count>1</comment_count>
      <attachid>329481</attachid>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2017-12-15 02:50:08 -0800</bug_when>
    <thetext>Created attachment 329481
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1382161</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-12-15 08:52:24 -0800</bug_when>
    <thetext>What is the memory limit?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1382479</commentid>
    <comment_count>3</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2017-12-16 03:36:38 -0800</bug_when>
    <thetext>(In reply to Michael Catanzaro from comment #2)
&gt; What is the memory limit?

It depends. There are several limits:

 - thresholdForMemoryKill: this is the one checked to decide whether to kill the process. This is calculated depending on the number of page/tabs in the web process and depending on whether the web process is currently active or not. If the limit is reached, a release memory is done and if after that the limit is still reached then the web process asks the UI to kill it. See:

    size_t baseThreshold;
    if (processState == WebsamProcessState::Active)
        baseThreshold = 4 * GB;
    else
        baseThreshold = 2 * GB;
    if (tabCount &lt;= 1)
        return baseThreshold;
    return baseThreshold + (std::min(tabCount - 1, 4u) * 1 * GB);

 - UsagePolicyBasedOnFootprint: this is to decide whether to try to free some memory or not depending on the web process current memory footprint. If the policy is set to Unrestricted nothing happens, if Conservative then non-critical memory is released and Strict tries to release all possible memory. See:

    switch (policy) {
    case MemoryUsagePolicy::Conservative:
        return 1 * GB;
    case MemoryUsagePolicy::Strict:
	return 1.5 * GB;
    case MemoryUsagePolicy::Unrestricted:
    default:
        ASSERT_NOT_REACHED();
        return 0;
    }

We might want to make this configurable, though. In a device with 1GB of RAM these values don&apos;t make sense.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1382484</commentid>
    <comment_count>4</comment_count>
    <who name="Carlos Alberto Lopez Perez">clopez</who>
    <bug_when>2017-12-16 06:57:44 -0800</bug_when>
    <thetext>(In reply to Carlos Garcia Campos from comment #3)
&gt;  - UsagePolicyBasedOnFootprint: this is to decide whether to try to free
&gt; some memory or not depending on the web process current memory footprint. If
&gt; the policy is set to Unrestricted nothing happens, if Conservative then
&gt; non-critical memory is released and Strict tries to release all possible
&gt; memory. See:
&gt; 
&gt;     switch (policy) {
&gt;     case MemoryUsagePolicy::Conservative:
&gt;         return 1 * GB;
&gt;     case MemoryUsagePolicy::Strict:
&gt; 	return 1.5 * GB;
&gt;     case MemoryUsagePolicy::Unrestricted:
&gt;     default:
&gt;         ASSERT_NOT_REACHED();
&gt;         return 0;
&gt;     }
&gt; 
&gt; We might want to make this configurable, though. In a device with 1GB of RAM
&gt; these values don&apos;t make sense.

Instead of making this configurable, we can have a dynamic thresold that depends on the amount of RAM of the device. A simple rule may be:


baseThresholdForPolicy == std::min(3 * GB, totalSystemRAM)

switch (policy) {
     case MemoryUsagePolicy::Conservative:
         return baseThresholdForPolicy / 2;
     case MemoryUsagePolicy::Strict:
 	return baseThresholdForPolicy / 3;
     case MemoryUsagePolicy::Unrestricted:
     default:
         ASSERT_NOT_REACHED();
         return 0;
}

This should give the same values it is already giving if the device has 3GB or more, otherwise it will give values that depend on the amount of RAM and should always make sense.


WDYT?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1382485</commentid>
    <comment_count>5</comment_count>
    <who name="Carlos Alberto Lopez Perez">clopez</who>
    <bug_when>2017-12-16 07:01:21 -0800</bug_when>
    <thetext>(In reply to Carlos Alberto Lopez Perez from comment #4)

&gt; Instead of making this configurable, we can have a dynamic thresold that
&gt; depends on the amount of RAM of the device. A simple rule may be:
&gt; 
&gt; 
&gt; baseThresholdForPolicy == std::min(3 * GB, totalSystemRAM)
&gt; 
&gt; switch (policy) {
&gt;      case MemoryUsagePolicy::Conservative:
&gt;          return baseThresholdForPolicy / 2;
                                    ^ 3
&gt;      case MemoryUsagePolicy::Strict:
&gt;  	return baseThresholdForPolicy / 3;
                                    ^  2
&gt;      case MemoryUsagePolicy::Unrestricted:
&gt;      default:
&gt;          ASSERT_NOT_REACHED();
&gt;          return 0;
&gt; }
&gt; 

Ups, I got confused with the values above. The 2 and the 3 should be exchanged.

@@ -2,9 +2,9 @@
 
 switch (policy) {
      case MemoryUsagePolicy::Conservative:
-         return baseThresholdForPolicy / 2;
+         return baseThresholdForPolicy / 3;
      case MemoryUsagePolicy::Strict:
- 	return baseThresholdForPolicy / 3;
+ 	return baseThresholdForPolicy / 2;
      case MemoryUsagePolicy::Unrestricted:
      default:
          ASSERT_NOT_REACHED();</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1382584</commentid>
    <comment_count>6</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2017-12-17 01:30:45 -0800</bug_when>
    <thetext>(In reply to Carlos Alberto Lopez Perez from comment #4)
&gt; (In reply to Carlos Garcia Campos from comment #3)
&gt; &gt;  - UsagePolicyBasedOnFootprint: this is to decide whether to try to free
&gt; &gt; some memory or not depending on the web process current memory footprint. If
&gt; &gt; the policy is set to Unrestricted nothing happens, if Conservative then
&gt; &gt; non-critical memory is released and Strict tries to release all possible
&gt; &gt; memory. See:
&gt; &gt; 
&gt; &gt;     switch (policy) {
&gt; &gt;     case MemoryUsagePolicy::Conservative:
&gt; &gt;         return 1 * GB;
&gt; &gt;     case MemoryUsagePolicy::Strict:
&gt; &gt; 	return 1.5 * GB;
&gt; &gt;     case MemoryUsagePolicy::Unrestricted:
&gt; &gt;     default:
&gt; &gt;         ASSERT_NOT_REACHED();
&gt; &gt;         return 0;
&gt; &gt;     }
&gt; &gt; 
&gt; &gt; We might want to make this configurable, though. In a device with 1GB of RAM
&gt; &gt; these values don&apos;t make sense.
&gt; 
&gt; Instead of making this configurable, we can have a dynamic thresold that
&gt; depends on the amount of RAM of the device.

Sounds like a good idea, please file a new bug report for that and include akling in the CC.

&gt; A simple rule may be:
&gt; 
&gt; 
&gt; baseThresholdForPolicy == std::min(3 * GB, totalSystemRAM)
&gt; 
&gt; switch (policy) {
&gt;      case MemoryUsagePolicy::Conservative:
&gt;          return baseThresholdForPolicy / 2;
&gt;      case MemoryUsagePolicy::Strict:
&gt;  	return baseThresholdForPolicy / 3;
&gt;      case MemoryUsagePolicy::Unrestricted:
&gt;      default:
&gt;          ASSERT_NOT_REACHED();
&gt;          return 0;
&gt; }
&gt; 
&gt; This should give the same values it is already giving if the device has 3GB
&gt; or more, otherwise it will give values that depend on the amount of RAM and
&gt; should always make sense.
&gt; 
&gt; 
&gt; WDYT?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1382722</commentid>
    <comment_count>7</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2017-12-18 00:25:16 -0800</bug_when>
    <thetext>Committed r226018: &lt;https://trac.webkit.org/changeset/226018&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1382723</commentid>
    <comment_count>8</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2017-12-18 00:26:19 -0800</bug_when>
    <thetext>&lt;rdar://problem/36101218&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1415762</commentid>
    <comment_count>9</comment_count>
    <who name="Carlos Alberto Lopez Perez">clopez</who>
    <bug_when>2018-04-18 16:01:43 -0700</bug_when>
    <thetext>*** Bug 175133 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>329481</attachid>
            <date>2017-12-15 02:50:08 -0800</date>
            <delta_ts>2017-12-15 08:46:32 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>wk-memory-pressure.diff</filename>
            <type>text/plain</type>
            <size>2074</size>
            <attacher name="Carlos Garcia Campos">cgarcia</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9XZWJLaXQvQ2hhbmdlTG9nIGIvU291cmNlL1dlYktpdC9DaGFu
Z2VMb2cKaW5kZXggYjVjOTU3MzQyN2YuLjFlNjZhNDBkZmFlIDEwMDY0NAotLS0gYS9Tb3VyY2Uv
V2ViS2l0L0NoYW5nZUxvZworKysgYi9Tb3VyY2UvV2ViS2l0L0NoYW5nZUxvZwpAQCAtMSwzICsx
LDE5IEBACisyMDE3LTEyLTE1ICBDYXJsb3MgR2FyY2lhIENhbXBvcyAgPGNnYXJjaWFAaWdhbGlh
LmNvbT4KKworICAgICAgICBbR1RLXVtXUEVdIEVuYWJsZSBXZWJQcm9jZXNzIG1lbW9yeSBtb25p
dG9yCisgICAgICAgIGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0xODA4
NjEKKworICAgICAgICBSZXZpZXdlZCBieSBOT0JPRFkgKE9PUFMhKS4KKworICAgICAgICBGb3Ig
c29tZSByZWFzb24gdGhpcyBpcyBvbmx5IGVuYWJsZWQgaW4gbWFjLiBXZSB3YW50IHRvIGVuYWJs
ZSBpdCBhbHNvIGluIEdUSyBhbmQgV1BFIHBvcnRzLiBUaGlzIHJ1bnMgZXZlcnkgMzAKKyAgICAg
ICAgc2Vjb25kcyB0byByZWxlYXNlIG1lbW9yeSBvciBldmVuIGtpbGwgdGhlIHByb2Nlc3MgaWYg
bmVjZXNzYXJ5LiBDYXJsb3MgTMOzcGV6IGhhcyByZWFsaXplZCB0aGF0IGluIHNvbWUKKyAgICAg
ICAgYXBwbGljYXRpb25zIHVzaW5nIHZpZGVvIHRhZ3MsIHRoZSBtZW1vcnkgZ3Jvd3MgYSBsb3Qg
YW5kIGl0J3MgbmV2ZXIgcmVsZWFzZWQuIEl0IHNlZW1zIGl0J3Mgbm90IG1lbW9yeSBsZWFrZWQs
CisgICAg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W1ldGVycyYmIHBhcmFtZXRl
cnMpCiAgICAgICAgIG1lbW9yeVByZXNzdXJlSGFuZGxlci5zZXRMb3dNZW1vcnlIYW5kbGVyKFtd
IChDcml0aWNhbCBjcml0aWNhbCwgU3luY2hyb25vdXMgc3luY2hyb25vdXMpIHsKICAgICAgICAg
ICAgIFdlYkNvcmU6OnJlbGVhc2VNZW1vcnkoY3JpdGljYWwsIHN5bmNocm9ub3VzKTsKICAgICAg
ICAgfSk7Ci0jaWYgUExBVEZPUk0oTUFDKSAmJiBfX01BQ19PU19YX1ZFUlNJT05fTUFYX0FMTE9X
RUQgPj0gMTAxMjAwCisjaWYgKFBMQVRGT1JNKE1BQykgJiYgX19NQUNfT1NfWF9WRVJTSU9OX01B
WF9BTExPV0VEID49IDEwMTIwMCkgfHwgUExBVEZPUk0oR1RLKSB8fCBQTEFURk9STShXUEUpCiAg
ICAgICAgIG1lbW9yeVByZXNzdXJlSGFuZGxlci5zZXRTaG91bGRVc2VQZXJpb2RpY01lbW9yeU1v
bml0b3IodHJ1ZSk7CiAgICAgICAgIG1lbW9yeVByZXNzdXJlSGFuZGxlci5zZXRNZW1vcnlLaWxs
Q2FsbGJhY2soW3RoaXNdICgpIHsKICAgICAgICAgICAgIFdlYkNvcmU6OmxvZ01lbW9yeVN0YXRp
c3RpY3NBdFRpbWVPZkRlYXRoKCk7Cg==
</data>
<flag name="review"
          id="348561"
          type_id="1"
          status="+"
          setter="mcatanzaro"
    />
          </attachment>
      

    </bug>

</bugzilla>