From owner-svn-src-head@freebsd.org Wed Mar 28 03:15:43 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 A6C1DF537C3; Wed, 28 Mar 2018 03:15:43 +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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5603071A3D; Wed, 28 Mar 2018 03:15:43 +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 50B8225317; Wed, 28 Mar 2018 03:15:43 +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 w2S3Fhim060309; Wed, 28 Mar 2018 03:15:43 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w2S3FhNU060308; Wed, 28 Mar 2018 03:15:43 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201803280315.w2S3FhNU060308@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Wed, 28 Mar 2018 03:15:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r331659 - head/sys/sys X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/sys X-SVN-Commit-Revision: 331659 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 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: Wed, 28 Mar 2018 03:15:43 -0000 Author: mjg Date: Wed Mar 28 03:15:42 2018 New Revision: 331659 URL: https://svnweb.freebsd.org/changeset/base/331659 Log: seq: disable preemption around seq_write_* This is a long standing performance bug which happened to not cause trouble in practice due to rather limited use of these primitives. The read side expects the writer to finish soon(tm) hence it loops with one pause in-between. But it is possible the writer gets preempted in which case the waiting can take a long time, especially so if it got preempted by the reader. In principle this may never clean itself up. In the current kernel seq is only used to obtain stable fp + capabilities state. In order for looping at least once to occur there has to be a concurrent writer modifying the fd slot for the very fd we are trying to read. That is, for any looping to occur in the first place the program has to be multithreaded and be doing something fishy to begin with. As such, the indefinite looping is rather hard to run into unless you really try (and I did not). Modified: head/sys/sys/seq.h Modified: head/sys/sys/seq.h ============================================================================== --- head/sys/sys/seq.h Wed Mar 28 03:11:50 2018 (r331658) +++ head/sys/sys/seq.h Wed Mar 28 03:15:42 2018 (r331659) @@ -79,6 +79,7 @@ static __inline void seq_write_begin(seq_t *seqp) { + critical_enter(); MPASS(!seq_in_modify(*seqp)); *seqp += 1; atomic_thread_fence_rel(); @@ -90,6 +91,7 @@ seq_write_end(seq_t *seqp) atomic_store_rel_int(seqp, *seqp + 1); MPASS(!seq_in_modify(*seqp)); + critical_exit(); } static __inline seq_t