From owner-svn-src-head@freebsd.org Fri May 25 06:11:32 2018 Return-Path: Delivered-To: svn-src-head@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 B3BE5F73B19; Fri, 25 May 2018 06:11:32 +0000 (UTC) (envelope-from agapon@gmail.com) Received: from mail-wr0-f175.google.com (mail-wr0-f175.google.com [209.85.128.175]) (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 1E89573F54; Fri, 25 May 2018 06:11:31 +0000 (UTC) (envelope-from agapon@gmail.com) Received: by mail-wr0-f175.google.com with SMTP id w3-v6so7065084wrl.12; Thu, 24 May 2018 23:11:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=gBGNskbPKaRg3fDC0z8ElxmXJ2YN85tHsQw9UYTWrcU=; b=KehrbIEeSUC6qAe0f7aoNdky8HPfinmIT800ffSVCi/YVNyE/c7OwfcbxmvBARZVQp QIKzOXoPruWW5VxNz01mhLCzXKn2xU1Q2A6xdwFwzOYqYnzKgiMF6WRb2CqB3LJiH2xH 890+6MelMfHJDYVYdkP64yQi7PtF4qa1vnABFnIa7vI4i46cQQcxQmwXT7NxGTPBgivm eNcD+hweuy5lTyKBAULt20M/6EYVtC3g0aMv9lw4Ui1euLbJP9DscDP2JPn+BcfpQYET b/2Q2GSm/S0/uwLwwJi2ZFqtE1Mu+NB8wCkOUVi5JcfvOYbgyLGawVm8yrjShJaPeE3W rKZw== X-Gm-Message-State: ALKqPwcLnRF8NVupb5pDD5Cwp1RZWwPb1u6KWJs+MAyEiEv5NmuowtTo dmtfg61rILyhDZfZXZHANC3GdUuE X-Google-Smtp-Source: ADUXVKLHvTr4/0uZPBgQc8laafJhnrXOAhGH/VFQbOF+R/T1AGYJ3bwCi8WpMBEoh3iDHGlKPAkMyg== X-Received: by 2002:a19:d9d5:: with SMTP id s82-v6mr577334lfi.18.1527228684833; Thu, 24 May 2018 23:11:24 -0700 (PDT) Received: from [192.168.0.88] (east.meadow.volia.net. [93.72.151.96]) by smtp.googlemail.com with ESMTPSA id y23-v6sm4307458ljh.88.2018.05.24.23.11.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 May 2018 23:11:24 -0700 (PDT) Subject: Re: svn commit: r334197 - head/sys/kern To: Mateusz Guzik , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org References: <20180525011551.GB19943@freefall.freebsd.org> From: Andriy Gapon Openpgp: preference=signencrypt Autocrypt: addr=avg@FreeBSD.org; prefer-encrypt=mutual; keydata= xsFNBFm4LIgBEADNB/3lT7f15UKeQ52xCFQx/GqHkSxEdVyLFZTmY3KyNPQGBtyvVyBfprJ7 mAeXZWfhat6cKNRAGZcL5EmewdQuUfQfBdYmKjbw3a9GFDsDNuhDA2QwFt8BmkiVMRYyvI7l N0eVzszWCUgdc3qqM6qqcgBaqsVmJluwpvwp4ZBXmch5BgDDDb1MPO8AZ2QZfIQmplkj8Y6Z AiNMknkmgaekIINSJX8IzRzKD5WwMsin70psE8dpL/iBsA2cpJGzWMObVTtCxeDKlBCNqM1i gTXta1ukdUT7JgLEFZk9ceYQQMJJtUwzWu1UHfZn0Fs29HTqawfWPSZVbulbrnu5q55R4PlQ /xURkWQUTyDpqUvb4JK371zhepXiXDwrrpnyyZABm3SFLkk2bHlheeKU6Yql4pcmSVym1AS4 dV8y0oHAfdlSCF6tpOPf2+K9nW1CFA8b/tw4oJBTtfZ1kxXOMdyZU5fiG7xb1qDgpQKgHUX8 7Rd2T1UVLVeuhYlXNw2F+a2ucY+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BLufFrOag1q5yUS9QbFfyqL6dftJP3Zq/xe+mr7sbWbhPVCQFrH3r26mpmy841ym dwQnNcsbIGiBASBSKksOvIDYKa2Wy8htPmWFTEOPRpFXdGQ27awcjjnB42nngyCK5ukZDHi6 w0qK5DNQQCkiweevCIC6wc3p67jl1EMFY5+z+zdTPb3h7LeVnGqW0qBQl99vVFgzLxchKcl0 R/paSFgwqXCZhAKMuUHncJuynDOP7z5LirUeFI8qsBAJi1rXpQoLJTVcW72swZ42IdPiboqx NbTMiNOiE36GqMcTPfKylCbF45JNX4nF9ElM0E+Y8gi4cizJYBRr2FBJgay0b9Cp Message-ID: Date: Fri, 25 May 2018 09:11:22 +0300 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180525011551.GB19943@freefall.freebsd.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 May 2018 06:11:33 -0000 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! :-) > Modified: > head/sys/kern/kern_mutex.c > > Modified: head/sys/kern/kern_mutex.c > =================================================================== > --- 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 = turnstile_lookup(&m->lock_object); > - MPASS(ts != 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 can > - * 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 != 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 can > + * unlock the chain lock so a new turnstile may take it's place. > + */ > + 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 and to check the calendar five times. -- Andriy Gapon