From nobody Mon Jun 26 23:41:16 2023 X-Original-To: threads@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QqkrD41tHz4g6F8 for ; Mon, 26 Jun 2023 23:41:16 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QqkrD0WLjz42Rp for ; Mon, 26 Jun 2023 23:41:16 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1687822876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qNxZaCPxAQEDloTO0qak+aivg4ocFsnH9AM7T4rsOII=; b=cqp0jpZmwmMZR4NHec7miOKcz8kPT2NS+DJzYYfylAFyB4qV9BId2830gKfaWrmUc6Vz/0 ay6qaHxmk8hA2t4ZRTK8IPNpU+vcJe5GbszzfG6HKxpDHz1z6gcZ9IrnF0Dmu8hgoIe5qw bSJNiWgxBqKRfYTzB990EB6oIsQvvuz8p7HVk4q+5uCMYd3n1/1hpdAb55+g4uQRs+x/t2 deJFJ2FeN+irDO/sGZdkCcYgml8aE06iPLh89ew212y7El73UGQwVZxk3w+KtEVxYLKRYn 695sSJdk+drorDWEg1AYz5pq2+uORdROJLL8S55fXZ69fQXBUoJongckt4xa9w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1687822876; a=rsa-sha256; cv=none; b=LxV0JZgHCFRrNX8kFarIFQNtivJdFeG3M90A8oiA9MEDMet2IyWE+Ja2Q4B4yogi3oarCv +DeOrqS+6sjwzvnWBzaFNVSkQZwu85lUFCFzcnuk+msFnktFBKmLQ+dIe1gvvCGvBtUgDZ wI7cqRQNjOVtNsCC7DJWKzdH04Tf/BbgJ/j6IaLvlrEQ3B42jsffawroy428zLD/tNoPFb IGKSc/yzTmG8gJRdBeYQqITwCeN+dGpE8LSVXJjsSE17pxv+6oaZYEG+qGORks4gCYmoD4 gQ8vAoLcvCyaiv7sYT8W+VVDTXiIBO4RXUdzy9CymrUGlg2evUILsRI4cxx1/g== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QqkrC6kRHzVQf for ; Mon, 26 Jun 2023 23:41:15 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 35QNfFDs098789 for ; Mon, 26 Jun 2023 23:41:15 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 35QNfFvQ098788 for threads@FreeBSD.org; Mon, 26 Jun 2023 23:41:15 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: threads@FreeBSD.org Subject: [Bug 272238] [PATCH] false sharing with pthread rw and spin locks leads to severe perf degradation Date: Mon, 26 Jun 2023 23:41:16 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: threads X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: greg@codeconcepts.com X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: threads@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Threading List-Archive: https://lists.freebsd.org/archives/freebsd-threads List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org MIME-Version: 1.0 X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D272238 Bug ID: 272238 Summary: [PATCH] false sharing with pthread rw and spin locks leads to severe perf degradation Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: threads Assignee: threads@FreeBSD.org Reporter: greg@codeconcepts.com Created attachment 243025 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D243025&action= =3Dedit Patch to ameliorate false sharing with pthread rw and spin locks. If an application allocates two or more pthread rwlocks (or spin locks) and then heavily accesses them from different CPUs it's quite likely that the application will experience severe performance degradation due to false sharing. The problem is that these locks are small (36 and 32 bytes, respectively) a= nd allocated on the heap via jemalloc(3). Depending upon the state of the allocator they may wind up within the same or straddling adjacent cache lin= es. For example, if I initialize four rwlocks and hammer on them from four different CPUs (one lock per CPU, such each lock is always uncontended) the= n on my dual E2697a 2.6GHz server I get about 10.52 million lock+inc+unlock calls per second. With the attached patch, which rounds up the allocations to CACHE_LINE_SIZE= , I get 47.68 million calls per second. Similarly, for pthread spin locks I get about 4.53 and 50.94 million calls per second, respectively. Overall, I am seeing roughly a 4.5x improvement with pthread rwlocks, and an 11.2x improvement with pthread spin locks. The patch is very simple and ignores adajacent cacheline prefetch as seen on amd64 hardware. Developed and test on: FreeBSD sm1.cc.codeconcepts.com 14.0-CURRENT FreeBSD 14.0-CURRENT #4 n263748-b95d2237af40: Mon Jun 26 17:08:50 CDT 2023=20=20=20=20 greg@sm1.cc.codeconcepts.com:/usr/obj/usr/src/amd64.amd64/sys/SM1 amd64 Passes the kyua test: kyua test -k /usr/tests/lib/libthr/Kyuafile --=20 You are receiving this mail because: You are the assignee for the bug.=