Bug 240517 - [PATCH] devel/glib20: syscall flood on every time*() function call
Summary: [PATCH] devel/glib20: syscall flood on every time*() function call
Status: Closed Overcome By Events
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-gnome (Nobody)
URL: https://gitlab.gnome.org/GNOME/glib/m...
Depends on:
Reported: 2019-09-11 22:54 UTC by Ivan Rozhuk
Modified: 2020-09-23 19:17 UTC (History)
3 users (show)

See Also:
rozhuk.im: maintainer-feedback-

tzcache patch (993 bytes, patch)
2019-09-11 22:54 UTC, Ivan Rozhuk
no flags Details | Diff
fix possible mem leak (1.01 KB, patch)
2019-09-12 02:53 UTC, Ivan Rozhuk
no flags Details | Diff
optimized version (1.41 KB, patch)
2019-09-12 23:45 UTC, Ivan Rozhuk
no flags Details | Diff
patch (1.92 KB, patch)
2019-11-02 02:45 UTC, Ivan Rozhuk
rozhuk.im: maintainer-approval?
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Rozhuk 2019-09-11 22:54:48 UTC
Created attachment 207400 [details]
tzcache patch

truss show that GTK app do many times:
27100: openat(AT_FDCWD,"/etc/localtime",O_RDONLY,00) = 114 (0x72)
27100: fstat(114,{ mode=-r--r--r-- ,inode=1845941,size=1518,blksize=32768 }) = 0 (0x0)
27100: mmap(0x0,1518,PROT_READ,MAP_PRIVATE,114,0x0) = 34458873856 (0x805e8b000)
27100: close(114)				 = 0 (0x0)
27100: munmap(0x805e8b000,1518)			 = 0 (0x0)

I found article: https://blog.packagecloud.io/eng/2017/02/21/set-environment-variable-save-thousands-of-system-calls/
and try to set:
env TZ=":/etc/localtime" truss -fD geany
env TZ="Europe/Moscow" truss -fD geany
without success.

I discovered that glib time zone cache is does not work properly:
GDateTime *
g_date_time_new_from_unix_local (gint64 t)
  GDateTime *datetime;
  GTimeZone *local;

  local = g_time_zone_new_local ();
  datetime = g_date_time_new_from_unix (local, t);
  g_time_zone_unref (local);

  return datetime;

GTimeZone *
g_time_zone_new_local (void)
  return g_time_zone_new (getenv ("TZ"));

g_time_zone_new() load and add time zone to cache if arg is not NULL.
g_time_zone_unref() - remove time zone from cache.
As you can see time zone in most cases removed from cache after short time.

Patch add_ref() for time zone "getenv ("TZ")" and "UTC", all other calls g_time_zone_new() leave without changes.
After apply patch and set TZ=":/etc/localtime" / TZ="Europe/Moscow" no more syscall flood happen.
Comment 1 Ivan Rozhuk 2019-09-12 02:53:54 UTC
Created attachment 207403 [details]
fix possible mem leak
Comment 2 Ivan Rozhuk 2019-09-12 23:45:31 UTC
Created attachment 207446 [details]
optimized version
Comment 3 Ivan Rozhuk 2019-11-02 02:45:58 UTC
Created attachment 208785 [details]

Back ported from master: https://gitlab.gnome.org/GNOME/glib/commit/f343ec5f82ddb6dfc7ce209cb8d49b0d02c914db
Comment 4 Ivan Rozhuk 2020-02-19 16:29:46 UTC
Comment 5 Ivan Rozhuk 2020-04-16 07:57:28 UTC
maintainer timeout
Comment 6 Ivan Rozhuk 2020-09-23 19:17:36 UTC
In upstream, upstream in base.