From owner-svn-src-all@freebsd.org Fri Dec 27 11:23:33 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 062D01EAB6B; Fri, 27 Dec 2019 11:23:33 +0000 (UTC) (envelope-from mjg@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47kkwN67TFz411y; Fri, 27 Dec 2019 11:23:32 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CDBA5182B8; Fri, 27 Dec 2019 11:23:32 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xBRBNW5t013540; Fri, 27 Dec 2019 11:23:32 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xBRBNWow013539; Fri, 27 Dec 2019 11:23:32 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201912271123.xBRBNWow013539@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Fri, 27 Dec 2019 11:23:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356120 - head/sys/security/mac X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/security/mac X-SVN-Commit-Revision: 356120 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Dec 2019 11:23:33 -0000 Author: mjg Date: Fri Dec 27 11:23:32 2019 New Revision: 356120 URL: https://svnweb.freebsd.org/changeset/base/356120 Log: mac: use a sleepable rmlock instead of an sx lock If any non-static modules are loaded (and mac_ntpd tends to be), the lock is taken all the time al over the kernel. On platforms like arm64 this results in an avoidable significant performance degradation. Since write-locking is almost never needed, use a primitive optimized towards read-locking. Sample result of building the kernel on tmpfs 11 times: stock 11142.80s user 6704.44s system 4924% cpu 6:02.42 total patched 11118.95s user 2374.94s system 4547% cpu 4:56.71 total Modified: head/sys/security/mac/mac_framework.c Modified: head/sys/security/mac/mac_framework.c ============================================================================== --- head/sys/security/mac/mac_framework.c Fri Dec 27 11:19:57 2019 (r356119) +++ head/sys/security/mac/mac_framework.c Fri Dec 27 11:23:32 2019 (r356120) @@ -176,6 +176,7 @@ MALLOC_DEFINE(M_MACTEMP, "mactemp", "MAC temporary lab #ifndef MAC_STATIC static struct rmlock mac_policy_rm; /* Non-sleeping entry points. */ static struct sx mac_policy_sx; /* Sleeping entry points. */ +static struct rmslock mac_policy_rms; #endif struct mac_policy_list_head mac_policy_list; @@ -209,7 +210,7 @@ mac_policy_slock_sleep(void) if (!mac_late) return; - sx_slock(&mac_policy_sx); + rms_rlock(&mac_policy_rms); #endif } @@ -233,7 +234,7 @@ mac_policy_sunlock_sleep(void) if (!mac_late) return; - sx_sunlock(&mac_policy_sx); + rms_runlock(&mac_policy_rms); #endif } @@ -249,6 +250,7 @@ mac_policy_xlock(void) return; sx_xlock(&mac_policy_sx); + rms_wlock(&mac_policy_rms); rm_wlock(&mac_policy_rm); #endif } @@ -262,6 +264,7 @@ mac_policy_xunlock(void) return; rm_wunlock(&mac_policy_rm); + rms_wunlock(&mac_policy_rms); sx_xunlock(&mac_policy_sx); #endif } @@ -294,6 +297,7 @@ mac_init(void) rm_init_flags(&mac_policy_rm, "mac_policy_rm", RM_NOWITNESS | RM_RECURSE); sx_init_flags(&mac_policy_sx, "mac_policy_sx", SX_NOWITNESS); + rms_init(&mac_policy_rms, "mac_policy_rms"); #endif }