From owner-svn-src-all@freebsd.org Fri May 25 13:31:46 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2AD45EB130C; Fri, 25 May 2018 13:31:46 +0000 (UTC) (envelope-from rmacklem@uoguelph.ca) Received: from CAN01-QB1-obe.outbound.protection.outlook.com (mail-eopbgr660083.outbound.protection.outlook.com [40.107.66.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client CN "mail.protection.outlook.com", Issuer "Microsoft IT TLS CA 4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AD10E8169B; Fri, 25 May 2018 13:31:45 +0000 (UTC) (envelope-from rmacklem@uoguelph.ca) Received: from YTXPR0101MB0959.CANPRD01.PROD.OUTLOOK.COM (52.132.34.15) by YTXPR0101MB0733.CANPRD01.PROD.OUTLOOK.COM (52.132.33.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.797.11; Fri, 25 May 2018 13:31:44 +0000 Received: from YTXPR0101MB0959.CANPRD01.PROD.OUTLOOK.COM ([fe80::f52d:74c4:9a70:3781]) by YTXPR0101MB0959.CANPRD01.PROD.OUTLOOK.COM ([fe80::f52d:74c4:9a70:3781%13]) with mapi id 15.20.0797.011; Fri, 25 May 2018 13:31:44 +0000 From: Rick Macklem To: Andriy Gapon , Mateusz Guzik , "src-committers@freebsd.org" , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" Subject: Re: svn commit: r334197 - head/sys/kern Thread-Topic: svn commit: r334197 - head/sys/kern Thread-Index: AQHT88XzwWsVgu1ZiEmkdTOGnPGznKQ/9twAgAB6IE8= Date: Fri, 25 May 2018 13:31:44 +0000 Message-ID: References: <20180525011551.GB19943@freefall.freebsd.org>, In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=rmacklem@uoguelph.ca; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; YTXPR0101MB0733; 7:Gb3pVWF9HvKDePWN4WRuibsqTAHT29U5JgDsz+okIpjW1FzPJSXKWQTBU8N194FqCxqr4uKTOVdxc730WGQTLxzQc2BIU6urc3+LN/ccqP0acgHTwim4BJ1QJifLgCQMYJ0UYkAE4p7YAqjj/dYAxq8YCWORbBRKgVtzAfwmb/45JHrgtH3DRhHQ4OYogNUeLi+yMKUsSZrDiSxdGO6L4LzPKp8BPdnN6KCPYheMjFKIJtbb7FkDkX/wIs89jKFU x-ms-exchange-antispam-srfa-diagnostics: SOS; x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(8989080)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(8990040)(2017052603328)(7153060)(7193020); SRVR:YTXPR0101MB0733; x-ms-traffictypediagnostic: YTXPR0101MB0733: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(56005881305849); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3231254)(944501410)(52105095)(3002001)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281529075)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123562045)(6072148)(201708071742011)(7699016); SRVR:YTXPR0101MB0733; BCL:0; PCL:0; RULEID:; SRVR:YTXPR0101MB0733; x-forefront-prvs: 06833C6A67 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(39380400002)(376002)(346002)(396003)(39860400002)(189003)(199004)(51444003)(5250100002)(446003)(53936002)(11346002)(74482002)(7696005)(2501003)(8936002)(6506007)(3280700002)(2900100001)(81156014)(81166006)(6246003)(26005)(102836004)(33656002)(97736004)(14454004)(3660700001)(478600001)(486006)(110136005)(9686003)(229853002)(8676002)(786003)(6306002)(450100002)(99286004)(316002)(59450400001)(186003)(76176011)(2201001)(966005)(86362001)(305945005)(68736007)(476003)(5660300001)(106356001)(105586002)(2906002)(25786009)(55016002)(6436002)(74316002); DIR:OUT; SFP:1101; SCL:1; SRVR:YTXPR0101MB0733; H:YTXPR0101MB0959.CANPRD01.PROD.OUTLOOK.COM; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: uoguelph.ca does not designate permitted sender hosts) x-microsoft-antispam-message-info: qoEqslnk8UH8N+Ai5nwVC81Uf39GPbBFeMj5N+WTUitwlwwDuablh098E92EGMkll3bxVnOuaS1m0xQCjE1mPjn3+XorvM/7Ndon16VmNEqe1wm8tFaKTS2r8wzErP9VEIx9bPqlcfxGhWMc+37iKuO8NQ1bUAn1k2HskBJ8+C9m8lVBRQImcR7KcbGy5TTS spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 9675ceee-182b-4d77-4436-08d5c243db5f X-OriginatorOrg: uoguelph.ca X-MS-Exchange-CrossTenant-Network-Message-Id: 9675ceee-182b-4d77-4436-08d5c243db5f X-MS-Exchange-CrossTenant-originalarrivaltime: 25 May 2018 13:31:44.1063 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: be62a12b-2cad-49a1-a5fa-85f4f3156a7d X-MS-Exchange-Transport-CrossTenantHeadersStamped: YTXPR0101MB0733 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 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, 25 May 2018 13:31:46 -0000 Andriy Gapon wrote: >On 25/05/2018 04:15, Mateusz Guzik wrote: >> Author: mjg >> Date: Thu May 25 23:58:57 2018 >> New Revision: 334197 >> URL: https://svnweb.freebsd.org/changeset/base/334197 >> >> Log: >> Implement Mostly Exclusive locks. >> >> High lock contention is one of the biggest scalability bottlenecks on >> multicore systems. Although the real fix consists of making lock >> consumers better suited for multicore operation, locking primitive >> performance is still a crucial factor in real-world systems. >> >> It turns out that a lot of the locking is overzealous - the lock is >> held longer than it needs to be and sometimes even completely >> unnecessarily in the first place. Even when lock is needed in >> principle, all relevant consumers may be only *reading* the state >> protected by the lock or modifying disjoint parts of protected data. >> >> As such, a lot of the locking can be elided. >> >> The idea boils down to trying to take the lock for a limited amount of >> time and in case of failure pretending we got it anyway. The approach >> along with practical analysis of performance win/new crash ratio is >> described in "Towards reliability-oblivious low latency locking" by >> Leland Oller. > >Great change! Looking forward to new crashes! >:-) I think that this should be enabled via a sysctl. Maybe something like: kern.enable_windows_reliability rick > Modified: > head/sys/kern/kern_mutex.c > > Modified: head/sys/kern/kern_mutex.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- sys/kern/kern_mutex.c (revision 334196) > +++ sys/kern/kern_mutex.c (working copy) > @@ -557,6 +557,9 @@ __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t > lda.spin_cnt++; > #endif > #ifdef ADAPTIVE_MUTEXES > + if (lda.spin_cnt > 16384) > + break; > + > /* > * If the owner is running on another CPU, spin until the > * owner stops running or the state of the lock changes. > @@ -1020,16 +1023,22 @@ __mtx_unlock_sleep(volatile uintptr_t *c, uintptr= _ > turnstile_chain_lock(&m->lock_object); > _mtx_release_lock_quick(m); > ts =3D turnstile_lookup(&m->lock_object); > - MPASS(ts !=3D NULL); > - if (LOCK_LOG_TEST(&m->lock_object, opts)) > - CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p contested", m); > - turnstile_broadcast(ts, TS_EXCLUSIVE_QUEUE); > - > /* > - * This turnstile is now no longer associated with the mutex. We c= an > - * unlock the chain lock so a new turnstile may take it's place. > + * We failed to previously grab the lock. Unlock fast path brings > + * us here thinking there are blocked threads, but there may be > + * none > */ > - turnstile_unpend(ts, TS_EXCLUSIVE_LOCK); > + if (ts !=3D NULL) { > + if (LOCK_LOG_TEST(&m->lock_object, opts)) > + CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p contested", m= ); > + turnstile_broadcast(ts, TS_EXCLUSIVE_QUEUE); > + > + /* > + * This turnstile is now no longer associated with the mute= x. We can > + * unlock the chain lock so a new turnstile may take it's p= lace. > + */ > + turnstile_unpend(ts, TS_EXCLUSIVE_LOCK); > + } > turnstile_chain_unlock(&m->lock_object); > } > P.S. I had to re-read the commit message twice, the actual change three times an= d to check the calendar five times. -- Andriy Gapon