blob: f4a95b8b371d335f77268eb3e82775f24778c4fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
From 791b1a33424897549f487eb75a80f13c4f94437a Mon Sep 17 00:00:00 2001
From: Giovanni Campagna <gcampagna@src.gnome.org>
Date: Fri, 11 Apr 2014 18:38:57 +0200
Subject: Ratelimit RSS-triggered GCs
When loading a lot of data in memory (for example in the shell
opening the overview, which loads all the desktop files and icons)
the RSS can increase a lot, so we would trigger GCs continously
without any hope of freeing memory, so ratelimit full GCs to at
most one every 5 frames.
https://bugzilla.gnome.org/show_bug.cgi?id=728048
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -1176,6 +1176,7 @@
}
static gulong linux_rss_trigger;
+static gint64 last_gc_time;
#endif
/**
@@ -1193,6 +1194,13 @@
/* We initiate a GC if VM or RSS has grown by this much */
gulong vmsize;
gulong rss_size;
+ gint64 now;
+
+ /* We rate limit GCs to at most one per 5 frames.
+ One frame is 16666 microseconds (1000000/60)*/
+ now = g_get_monotonic_time();
+ if (now - last_gc_time < 5 * 16666)
+ return;
_linux_get_self_process_size (&vmsize, &rss_size);
@@ -1209,6 +1217,7 @@
if (rss_size > linux_rss_trigger) {
linux_rss_trigger = (gulong) MIN(G_MAXULONG, rss_size * 1.25);
JS_GC(JS_GetRuntime(context));
+ last_gc_time = now;
} else if (rss_size < (0.75 * linux_rss_trigger)) {
/* If we've shrunk by 75%, lower the trigger */
linux_rss_trigger = (rss_size * 1.25);
|