From owner-freebsd-gecko@freebsd.org Tue Jan 31 04:29:30 2017 Return-Path: Delivered-To: freebsd-gecko@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0E995CC84A3 for ; Tue, 31 Jan 2017 04:29:30 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A580A1CEC for ; Tue, 31 Jan 2017 04:29:26 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-wm0-f43.google.com with SMTP id v77so75249529wmv.0 for ; Mon, 30 Jan 2017 20:29:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:from:date:message-id :subject:to; bh=qLYtC6wd9oaNjdNMNp+7v/ysf64TpxuqwIQkGLOlvwE=; b=GgVfJXUaqr/jpt0g2CrN0jE3jDY0+HPUj3EFQI0sBLPpB2pdX49PDSh59pu5ieUl5E a2FkyleADozePKtgshZRWHyrFgwQiNhMw6qSHv1AnOV8vqXGzUvmulntePc/BhUtU74W f71jIJIrGfkUfwK0Ttegh9H2lorQcKBUuO8gdNLabmqC0g625hUEOpooR5MJ8Z47JSM7 Ixj1tacJZMi+6G4HHY8VnQitx5qncWqi98Fdq8FNi4L3GtlJLnhCR+vH9qWGQuemXsxA kw62xxxhprIubvdJcZeCQj401D8qTWFkkcivf58oV0cd/i3+yVkylw0Ljgf5wDYw3Ajr R+xg== X-Gm-Message-State: AIkVDXKfOZD1TJu1dgHtMe4GE4pR/+qwohgC3+B/9PhOy2tynUoHyr/k86uyw+Rm1AK5+A== X-Received: by 10.28.156.86 with SMTP id f83mr15551624wme.93.1485835532568; Mon, 30 Jan 2017 20:05:32 -0800 (PST) Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com. [74.125.82.47]) by smtp.gmail.com with ESMTPSA id e16sm26205896wra.36.2017.01.30.20.05.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Jan 2017 20:05:32 -0800 (PST) Received: by mail-wm0-f47.google.com with SMTP id r141so60573667wmg.1 for ; Mon, 30 Jan 2017 20:05:32 -0800 (PST) X-Received: by 10.28.6.210 with SMTP id 201mr18044731wmg.85.1485835531872; Mon, 30 Jan 2017 20:05:31 -0800 (PST) MIME-Version: 1.0 Reply-To: cem@freebsd.org Received: by 10.194.22.42 with HTTP; Mon, 30 Jan 2017 20:05:31 -0800 (PST) From: Conrad Meyer Date: Mon, 30 Jan 2017 20:05:31 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Excessive getpid() in Firefox To: freebsd-gecko@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-gecko@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gecko Rendering Engine issues List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Jan 2017 04:29:30 -0000 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