From owner-svn-src-user@freebsd.org Sat Feb 10 22:35:47 2018 Return-Path: Delivered-To: svn-src-user@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 2FA33F0296D for ; Sat, 10 Feb 2018 22:35:47 +0000 (UTC) (envelope-from jeff@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 DA9A376336; Sat, 10 Feb 2018 22:35:46 +0000 (UTC) (envelope-from jeff@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 D58911A3BC; Sat, 10 Feb 2018 22:35:46 +0000 (UTC) (envelope-from jeff@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1AMZkRX075905; Sat, 10 Feb 2018 22:35:46 GMT (envelope-from jeff@FreeBSD.org) Received: (from jeff@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1AMZkIG075904; Sat, 10 Feb 2018 22:35:46 GMT (envelope-from jeff@FreeBSD.org) Message-Id: <201802102235.w1AMZkIG075904@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jeff set sender to jeff@FreeBSD.org using -f From: Jeff Roberson Date: Sat, 10 Feb 2018 22:35:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r329112 - user/jeff/numa/sys/kern X-SVN-Group: user X-SVN-Commit-Author: jeff X-SVN-Commit-Paths: user/jeff/numa/sys/kern X-SVN-Commit-Revision: 329112 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Feb 2018 22:35:47 -0000 Author: jeff Date: Sat Feb 10 22:35:46 2018 New Revision: 329112 URL: https://svnweb.freebsd.org/changeset/base/329112 Log: Restructure bq_insert so it is not called with a lock held. This allows us to switch locks in this function in certain cases (B_AGE). Found by: pho Modified: user/jeff/numa/sys/kern/vfs_bio.c Modified: user/jeff/numa/sys/kern/vfs_bio.c ============================================================================== --- user/jeff/numa/sys/kern/vfs_bio.c Sat Feb 10 22:34:47 2018 (r329111) +++ user/jeff/numa/sys/kern/vfs_bio.c Sat Feb 10 22:35:46 2018 (r329112) @@ -1009,7 +1009,6 @@ bufinit(void) unmapped_buf = (caddr_t)kva_alloc(MAXPHYS); /* finally, initialize each buffer header and stick on empty q */ - BQ_LOCK(&bqempty); for (i = 0; i < nbuf; i++) { bp = &buf[i]; bzero(bp, sizeof *bp); @@ -1025,7 +1024,6 @@ bufinit(void) BUF_LOCKINIT(bp); bq_insert(&bqempty, bp, false); } - BQ_UNLOCK(&bqempty); /* * maxbufspace is the absolute maximum amount of buffer space we are @@ -1398,9 +1396,7 @@ binsfree(struct buf *bp, int qindex) bq = &bd->bd_cleanq; } else bq = &bqdirty; - BQ_LOCK(bq); bq_insert(bq, bp, true); - BQ_UNLOCK(bq); return; } @@ -1469,12 +1465,21 @@ buf_import(void *arg, void **store, int cnt, int domai static void buf_release(void *arg, void **store, int cnt) { + struct bufqueue *bq; + struct buf *bp; int i; - BQ_LOCK(&bqempty); - for (i = 0; i < cnt; i++) - bq_insert(&bqempty, store[i], false); - BQ_UNLOCK(&bqempty); + bq = &bqempty; + BQ_LOCK(bq); + for (i = 0; i < cnt; i++) { + bp = store[i]; + /* Inline bq_insert() to batch locking. */ + TAILQ_INSERT_TAIL(&bq->bq_queue, bp, b_freelist); + bp->b_flags &= ~(B_AGE | B_REUSE); + bq->bq_len++; + bp->b_qindex = bq->bq_index; + } + BQ_UNLOCK(bq); } /* @@ -1785,26 +1790,32 @@ bq_insert(struct bufqueue *bq, struct buf *bp, bool un { struct bufdomain *bd; - BQ_ASSERT_LOCKED(bq); if (bp->b_qindex != QUEUE_NONE) panic("bq_insert: free buffer %p onto another queue?", bp); bd = &bdclean[bp->b_domain]; if (bp->b_flags & B_AGE) { /* Place this buf directly on the real queue. */ - if (bq->bq_index == QUEUE_CLEAN && bq != &bd->bd_cleanq) { - BQ_LOCK(&bd->bd_cleanq); - BQ_UNLOCK(bq); + if (bq->bq_index == QUEUE_CLEAN) bq = &bd->bd_cleanq; - } + BQ_LOCK(bq); TAILQ_INSERT_HEAD(&bq->bq_queue, bp, b_freelist); - } else + } else { + BQ_LOCK(bq); TAILQ_INSERT_TAIL(&bq->bq_queue, bp, b_freelist); + } bp->b_flags &= ~(B_AGE | B_REUSE); bq->bq_len++; bp->b_qindex = bq->bq_index; bp->b_cpu = bq->bq_cpu; + /* + * Unlock before we notify so that we don't wakeup a waiter that + * fails a trylock on the buf and sleeps again. + */ + if (unlock) + BUF_UNLOCK(bp); + if (bp->b_qindex == QUEUE_CLEAN) { /* * Flush the per-cpu queue and notify any waiters. @@ -1813,13 +1824,7 @@ bq_insert(struct bufqueue *bq, struct buf *bp, bool un bq->bq_len >= bd->bd_lim)) bd_flush(bd, bq); } - - /* - * Unlock before we notify so that we don't wakeup a waiter that - * fails a trylock on the buf and sleeps again. - */ - if (unlock) - BUF_UNLOCK(bp); + BQ_UNLOCK(bq); } /*