[VD] Add more logs to detect OOM issue 96/315596/6
authorchenhuasheng <hsheng.chen@samsung.com>
Tue, 3 Dec 2024 09:40:37 +0000 (17:40 +0800)
committerBot Blink <blinkbot@samsung.com>
Thu, 5 Dec 2024 02:35:21 +0000 (02:35 +0000)
ref : https://archive.tizen.org/gerrit/#/c/296991/

Change-Id: I925c125168cb2bf9ded11f64730e29c7d90f0412
Signed-off-by: chenhuasheng <hsheng.chen@samsung.com>
base/allocator/partition_allocator/src/partition_alloc/oom.cc
base/files/scoped_file.cc
base/memory/platform_shared_memory_mapper_posix.cc
content/child/child_thread_impl.cc
gpu/ipc/common/gpu_memory_buffer_impl_shared_memory.cc
third_party/blink/renderer/controller/memory_usage_monitor.cc
third_party/blink/renderer/controller/memory_usage_monitor.h

index 1d6956830da479958f7f6541d1b6058c02eac4ef..d9d8790947d1e54bd189eb97b8f2d854bf67bbdb 100644 (file)
 #include <array>
 #endif  // BUILDFLAG(IS_WIN)
 
+#if BUILDFLAG(IS_TIZEN_TV)
+#include <stdio.h>
+#include "base/logging.h"
+namespace {
+static void DumpMemoryUsage() {
+  FILE* fd;
+  char buff[256];
+  fd = fopen("/proc/self/vd_memstat", "r");
+  if (!fd) {
+    LOG(ERROR) << "can't open /proc/self/vd_memstat ";
+    return;
+  }
+  if (fgets(buff, sizeof(buff), fd))
+    LOG(WARNING) << buff;
+  if (fgets(buff, sizeof(buff), fd))
+    LOG(WARNING) << buff;
+  if (fgets(buff, sizeof(buff), fd))
+    LOG(WARNING) << buff;
+  fclose(fd);
+}
+}  // namespace
+#endif
+
 namespace partition_alloc {
 
 size_t g_oom_size = 0U;
@@ -43,7 +66,10 @@ PA_NOINLINE void OnNoMemoryInternal(size_t size) {
 #else
   size_t tmp_size = size;
   internal::base::debug::Alias(&tmp_size);
-
+#if BUILDFLAG(IS_TIZEN_TV)
+  DumpMemoryUsage();
+  LOG(WARNING) << "OOM size:" << size;
+#endif
   // Note: Don't add anything that may allocate here. Depending on the
   // allocator, this may be called from within the allocator (e.g. with
   // PartitionAlloc), and would deadlock as our locks are not recursive.
index f9826970ac3841e161b68797f0de44aa36e1b84e..8234f74a891b63e50dcb26c4da2b49cb6e10ebb5 100644 (file)
@@ -46,7 +46,8 @@ void ScopedFDCloseTraits::Free(int fd) {
 
 #if BUILDFLAG(IS_TIZEN)
   if (0 != ret)
-    LOG(ERROR) << "Failed to close file descriptor! fd=" << fd;
+    LOG(ERROR) << "Failed to close file descriptor! fd=" << fd
+               << " errmsg:" << strerror(errno);
 #else
   PCHECK(0 == ret);
 #endif
index 19725e01825ba45582c7e0a95012fdd9332c2b10..f2178efb3d294ca7912acf8b7dbc45f3304087db 100644 (file)
@@ -21,6 +21,10 @@ absl::optional<span<uint8_t>> PlatformSharedMemoryMapper::Map(
            MAP_SHARED, handle.fd, checked_cast<off_t>(offset));
 
   if (address == MAP_FAILED) {
+#if BUILDFLAG(IS_TIZEN_TV)
+    LOG(ERROR) << "mmap " << handle.fd << " failed. errmsg:" << strerror(errno)
+               << " size:" << size << " offset:" << offset;
+#endif
     DPLOG(ERROR) << "mmap " << handle.fd << " failed";
     return absl::nullopt;
   }
@@ -29,8 +33,13 @@ absl::optional<span<uint8_t>> PlatformSharedMemoryMapper::Map(
 }
 
 void PlatformSharedMemoryMapper::Unmap(span<uint8_t> mapping) {
-  if (munmap(mapping.data(), mapping.size()) < 0)
+  if (munmap(mapping.data(), mapping.size()) < 0) {
+#if BUILDFLAG(IS_TIZEN_TV)
+    LOG(ERROR) << "munmap failed. errmsg:" << strerror(errno)
+               << " size:" << mapping.size();
+#endif
     DPLOG(ERROR) << "munmap";
+  }
 }
 
 }  // namespace base
index 339cc7199f4484cee6170fcbadfc87f84cd9c601..ccb6aebee3089de4c57e1c49cf99ebf809699b81 100644 (file)
 extern "C" void __llvm_profile_set_file_object(FILE* File, int EnableMerge);
 #endif
 
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "third_party/blink/renderer/controller/memory_usage_monitor.h"
+#endif
+
 namespace content {
 namespace {
 
@@ -938,6 +942,10 @@ bool ChildThreadImpl::IsInBrowserProcess() const {
 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_TIZEN_TV)
 void ChildThreadImpl::OnMemoryPressureFromBrowserReceived(
     base::MemoryPressureListener::MemoryPressureLevel level) {
+  blink::MemoryUsage mem_usage =
+      blink::MemoryUsageMonitor::Instance().GetCurrentMemoryUsage();
+  LOG(ERROR) << mem_usage;
+
   TRACE_EVENT0("v8", "ChildThreadImpl::OnMemoryPressureFromBrowserReceived");
   // Generate no memory pressure signals when --single-process is specified.
   // Because we expect a signal for the browser process has been already
index 7b844ccbc54a01f4e1560f0c91827d08e17efebf..4f29bc66d7cbc30c98c5400e2d9962d78a7b312b 100644 (file)
@@ -242,8 +242,13 @@ bool GpuMemoryBufferImplSharedMemory::Map() {
     // map offset + buffer_size here but this can be avoided using MapAt().
     size_t map_size = offset_ + buffer_size;
     shared_memory_mapping_ = shared_memory_region_.MapAt(0, map_size);
-    if (!shared_memory_mapping_.IsValid())
+    if (!shared_memory_mapping_.IsValid()) {
+#if BUILDFLAG(IS_TIZEN_TV)
+      LOG(WARNING) << "shared_memory_mapping_ is invalid!!! OOM map_size:"
+                   << map_size;
+#endif
       base::TerminateBecauseOutOfMemory(map_size);
+    }
   }
   return true;
 }
index d2b0d2fe49246d04d6b4df54473785ecad55c9eb..d4f8d06489e0f7e5a8f9780c968eb74dcd3e38e2 100644 (file)
@@ -18,6 +18,20 @@ namespace {
 constexpr base::TimeDelta kPingInterval = base::Seconds(1);
 }
 
+constexpr int MB = 1024 * 1024;
+std::ostream& operator<<(std::ostream& out, const MemoryUsage& memory_usage) {
+  return out << "v8_bytes:" << memory_usage.v8_bytes / MB
+             << "MB partition_alloc_bytes:"
+             << memory_usage.partition_alloc_bytes / MB
+             << "MB blink_gc_bytes:" << memory_usage.blink_gc_bytes / MB
+             << "MB private_footprint_bytes:"
+             << memory_usage.private_footprint_bytes / MB
+             << "MB swap_bytes:" << memory_usage.swap_bytes / MB
+             << "MB vm_size_bytes:" << memory_usage.vm_size_bytes / MB
+             << "MB peak_resident_bytes:"
+             << memory_usage.peak_resident_bytes / MB << "MB";
+}
+
 MemoryUsageMonitor::MemoryUsageMonitor() {
   MainThreadScheduler* scheduler =
       Thread::MainThread()->Scheduler()->ToMainThreadScheduler();
index 68d77ab820ab6c6d9040cc918925b15252fee2d8..9c51862d3aa5505e5032f4446b30d1eba7ad3dee 100644 (file)
@@ -29,6 +29,8 @@ struct MemoryUsage {
   double peak_resident_bytes = std::numeric_limits<double>::quiet_NaN();
 };
 
+std::ostream& operator<<(std::ostream& out, const MemoryUsage& memory_usage);
+
 // Periodically checks the memory usage and notifies its observers. Monitoring
 // automatically starts/stops depending on whether an observer exists.
 class CONTROLLER_EXPORT MemoryUsageMonitor {