[M108 Migration] Add discardable memory and purge delay switch 06/288106/4
authorBakka Uday Kiran <b.kiran@samsung.com>
Fri, 10 Feb 2023 11:56:22 +0000 (17:26 +0530)
committerBot Blink <blinkbot@samsung.com>
Mon, 13 Feb 2023 14:37:52 +0000 (14:37 +0000)
This commit enables to manually configure discardable
memory and purge delay from command line.

Reference: https://review.tizen.org/gerrit/c/280812

Change-Id: I941092fb926cb2ec9bfdc87c5eaa2127e01e7d00
Signed-off-by: Bakka Uday Kiran <b.kiran@samsung.com>
base/base_switches.cc
base/base_switches.h
components/discardable_memory/service/discardable_shared_memory_manager.cc
components/discardable_memory/service/discardable_shared_memory_manager.h
content/browser/renderer_host/render_process_host_impl.cc
tizen_src/ewk/efl_integration/command_line_efl.cc

index a4c6baf..ac811c0 100644 (file)
@@ -150,6 +150,11 @@ const char kLimitMemoryAllocationInScheduleDelayedWork[] =
 const char kEnableOffscreenRendering[] = "enable-offscreen-rendering";
 #endif
 
+#if BUILDFLAG(IS_TIZEN)
+const char kDiscardableMemoryLimit[] = "discardable-memory-limit";
+const char kDiscardableMemoryPurgeDelay[] = "discardable-memory-purge-delay";
+#endif
+
 #if BUILDFLAG(IS_POSIX)
 // Used for turning on Breakpad crash reporting in a debug environment where
 // crash reporting is typically compiled but disabled.
index 29a95cf..7b0d90f 100644 (file)
@@ -53,6 +53,11 @@ extern const char kLimitMemoryAllocationInScheduleDelayedWork[];
 extern const char kEnableOffscreenRendering[];
 #endif
 
+#if BUILDFLAG(IS_TIZEN)
+extern const char kDiscardableMemoryLimit[];
+extern const char kDiscardableMemoryPurgeDelay[];
+#endif
+
 #if BUILDFLAG(IS_POSIX)
 extern const char kEnableCrashReporterForTesting[];
 #endif
index 2090746..cfabfe0 100644 (file)
 #include "base/metrics/histogram_macros.h"
 #endif
 
+#if BUILDFLAG(IS_TIZEN)
+#include "base/base_switches.h"
+#endif
+
 namespace discardable_memory {
 namespace {
 
@@ -242,6 +246,26 @@ DiscardableSharedMemoryManager::DiscardableSharedMemoryManager()
   DCHECK(!g_instance)
       << "A DiscardableSharedMemoryManager already exists in this process.";
   g_instance = this;
+
+#if BUILDFLAG(IS_TIZEN)
+  std::string switch_value =
+      base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+          switches::kDiscardableMemoryLimit);
+  size_t discardable_mem_limit;
+  if (base::StringToSizeT(switch_value, &discardable_mem_limit))
+    memory_limit_ = discardable_mem_limit * 1024 * 1024;
+
+  std::string delay_value =
+      base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+          switches::kDiscardableMemoryPurgeDelay);
+  int discardable_mem_purge_delay;
+  if (base::StringToInt(delay_value, &discardable_mem_purge_delay))
+    purge_delay_ = base::Milliseconds(discardable_mem_purge_delay);
+
+  LOG(INFO) << "DiscardableMemoryLimit : " << memory_limit_ / 1024 << "KB";
+  LOG(INFO) << "DiscardableMemoryPurgeDelay : " << purge_delay_;
+#endif
+
   DCHECK_NE(memory_limit_, 0u);
   enforce_memory_policy_callback_ =
       base::BindRepeating(&DiscardableSharedMemoryManager::EnforceMemoryPolicy,
@@ -569,7 +593,12 @@ void DiscardableSharedMemoryManager::ReduceMemoryUsageUntilWithinLimit(
       break;
 
     // Stop eviction attempts when the LRU segment is currently in use.
+#if BUILDFLAG(IS_TIZEN)
+    if (segments_.front()->memory()->last_known_usage() + purge_delay_ >=
+        current_time)
+#else
     if (segments_.front()->memory()->last_known_usage() >= current_time)
+#endif
       break;
 
     std::pop_heap(segments_.begin(), segments_.end(), CompareMemoryUsageTime);
index 09ea873..26e8e57 100644 (file)
@@ -186,6 +186,10 @@ class DISCARDABLE_MEMORY_EXPORT DiscardableSharedMemoryManager
 
   base::WeakPtrFactory<DiscardableSharedMemoryManager> weak_ptr_factory_{this};
 
+#if BUILDFLAG(IS_TIZEN)
+  base::TimeDelta purge_delay_;
+#endif
+
   // WeakPtrFractory for generating weak pointers used in the mojo thread.
   base::WeakPtrFactory<DiscardableSharedMemoryManager>
       mojo_thread_weak_ptr_factory_{this};
index e2ff206..64796df 100644 (file)
@@ -3439,6 +3439,10 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
 #if BUILDFLAG(IS_EFL)
     autofill::switches::kDisableAutofill,
 #endif
+#if BUILDFLAG(IS_TIZEN)
+    switches::kDiscardableMemoryLimit,
+    switches::kDiscardableMemoryPurgeDelay,
+#endif
   };
   renderer_cmd->CopySwitchesFrom(browser_cmd, kSwitchNames,
                                  std::size(kSwitchNames));
index 3e21479..eddd778 100644 (file)
@@ -76,7 +76,15 @@ content::MainFunctionParams CommandLineEfl::GetDefaultPortParams() {
 #endif
 
 #if BUILDFLAG(IS_TIZEN)
-#if !defined(EWK_BRINGUP)  // FIXME:m85 bringup
+  // For optimizing discardable memory. [limit:MB, delay:ms]
+  if (!p_command_line->HasSwitch(switches::kDiscardableMemoryLimit))
+    p_command_line->AppendSwitchASCII(switches::kDiscardableMemoryLimit, "20");
+
+  if (!p_command_line->HasSwitch(switches::kDiscardableMemoryPurgeDelay)) {
+    p_command_line->AppendSwitchASCII(switches::kDiscardableMemoryPurgeDelay,
+                                      "500");
+  }
+#if !defined(EWK_BRINGUP)
   p_command_line->AppendSwitchASCII(
       switches::kAcceleratedCanvas2dMSAASampleCount, "4");
   p_command_line->AppendSwitch(switches::kEnableGestureTapHighlight);