Adaptive tcmalloc Release Rate to Mitigate Fragmentation and Prevent OOM

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Workload Scheduling
    • None
    • 3
    • TBD
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • 0

      Dynamically adjusting the tcmalloc memory release rate at runtime based on total system memory usage. When memory usage exceeds 80% or 90% of system capacity, we increase the rate at which tcmalloc releases unused memory to the OS. This strategy helps in:

      • Reducing resident memory usage (RSS)
      • Mitigating fragmentation issues often seen 
      • Preventing Out-Of-Memory (OOM) crashes caused by tcmalloc holding fragmented memory

      By tuning the release behavior based on real-time usage, we can improve system stability without compromising performance under normal load.

       

       

      void adjustReleaseRate() {
          size_t heap = 0;
          MallocExtension::instance()->GetNumericProperty("generic.heap_size", &heap);
          struct sysinfo info;
          sysinfo(&info);
          double usage = (double)heap / (info.totalram * info.mem_unit);
          MallocExtension::SetMemoryReleaseRate(usage > 0.8 ? 20.0 : 1.0);
      }
      

       

            Assignee:
            Unassigned
            Reporter:
            Rajesh Patil
            Votes:
            0 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: