Project

General

Profile

Actions

Feature #12830

open

Release memory back to the OS

Added by Dries Mys 4 months ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
07/14/2024
Due date:
% Done:

0%

Estimated time:

Description

As Wt is often used as a long running process, it would be useful to implement some logic to return memory back to the OS.

This is especially useful if the (physical) server running the Wt application is used for multiple Wt applications and/or for other processes. This will not reduce the peak memory used by the Wt application, but will reduce the average memory usage. If not all processes running on the same (physical) server reach their peak at the same time, it will improve the server performance and/or limit the memory cost.

The most performant approach may be to use a custom memory allocator, such as tcmalloc or jemalloc.

Another (simpler) option on Linux is to use the malloc_trim function to release unused memory to the OS.

A simple heuristic may be to call malloc_trim every time the number of sessions has been halved, i.e.

static int maxSessions = 0;
void onSessionConstructed (int currentSessions)
{
  if (currentSessions > maxSessions)
    maxSessions = currentSessions;  
}

void onSessionDestructed (int currentSessions)
{
  if (currentSessions <= maxSessions / 2) {
    malloc_trim(0);
    maxSessions = currentSessions;
  }
}

No data to display

Actions

Also available in: Atom PDF