Excessive getpid() in Firefox
Conrad Meyer
cem at freebsd.org
Tue Jan 31 04:29:30 UTC 2017
Hi,
(I'm not subscribed to the list, so please CC me in replies.)
Several people reported seeing excessive getpid(2) calls in Firefox
(thousands per second). Mark Johnston did a quick dtrace profile,
which pointed to libnss3.so`PK11_DigestFinal+0xf6.
I dug a little in the NSS source code. While there is nothing too
obvious in PK11_DigestFinal itself, I located a probable culprit: the
fork detection logic in "softtokens." The codebase can detect forks
using either pthread_atfork(3) or repeatedly checking getpid(2).
Unfortunately, today it only uses the more efficient pthread_atfork(3)
approach on glibc-based operating systems.
The good news is that FreeBSD implements pthread_atfork(3), and (as
suggested as required by a nearby code comment) deregisters callbacks
located in dlclose(3)ed shared objects. So it should be possible to
enable CHECK_FORK_PTHREAD for FreeBSD in NSS, eliminating one source
of slowdown in NSS and Firefox.
I've filed a Mozilla bug tracking this here:
https://bugzilla.mozilla.org/show_bug.cgi?id=1335284
Note that I haven't actually tested Firefox with this change, so I
wouldn't go ahead and commit anything just yet. Konstantin suggested
I email this list in case there is some interest in testing / driving
this change at Mozilla.
Thanks,
Conrad
More information about the freebsd-gecko
mailing list