Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936538AbdCJMLV (ORCPT ); Fri, 10 Mar 2017 07:11:21 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:45062 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935968AbdCJMLS (ORCPT ); Fri, 10 Mar 2017 07:11:18 -0500 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Josef Bacik" , "Jens Axboe" Date: Fri, 10 Mar 2017 11:46:23 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 244/370] nbd: only set MSG_MORE when we have more to send In-Reply-To: X-SA-Exim-Connect-IP: 82.70.136.246 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1751 Lines: 52 3.16.42-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik commit d61b7f972dab2a7d187c38254845546dfc8eed85 upstream. A user noticed that write performance was horrible over loopback and we traced it to an inversion of when we need to set MSG_MORE. It should be set when we have more bvec's to send, not when we are on the last bvec. This patch made the test go from 20 iops to 78k iops. Signed-off-by: Josef Bacik Fixes: 429a787be679 ("nbd: fix use-after-free of rq/bio in the xmit path") Signed-off-by: Jens Axboe [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- drivers/block/nbd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -239,7 +239,7 @@ static inline int sock_send_bvec(struct /* always call with the tx_lock held */ static int nbd_send_req(struct nbd_device *nbd, struct request *req) { - int result, flags; + int result; struct nbd_request request; unsigned long size = blk_rq_bytes(req); struct bio *bio; @@ -270,7 +270,6 @@ static int nbd_send_req(struct nbd_devic if (nbd_cmd(req) != NBD_CMD_WRITE) return 0; - flags = 0; bio = req->bio; while (bio) { struct bio *next = bio->bi_next; @@ -279,9 +278,8 @@ static int nbd_send_req(struct nbd_devic bio_for_each_segment(bvec, bio, iter) { bool is_last = !next && bio_iter_last(bvec, iter); + int flags = is_last ? 0 : MSG_MORE; - if (is_last) - flags = MSG_MORE; dprintk(DBG_TX, "%s: request %p: sending %d bytes data\n", nbd->disk->disk_name, req, bvec.bv_len); result = sock_send_bvec(nbd, &bvec, flags);