From patchwork Sun Apr 17 21:29:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8863791 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DF8779F441 for ; Sun, 17 Apr 2016 21:32:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0A21420145 for ; Sun, 17 Apr 2016 21:32:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1EF3920149 for ; Sun, 17 Apr 2016 21:32:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751694AbcDQVbO (ORCPT ); Sun, 17 Apr 2016 17:31:14 -0400 Received: from mail-yw0-f195.google.com ([209.85.161.195]:34127 "EHLO mail-yw0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751676AbcDQVbK (ORCPT ); Sun, 17 Apr 2016 17:31:10 -0400 Received: by mail-yw0-f195.google.com with SMTP id h6so21372329ywc.1; Sun, 17 Apr 2016 14:31:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NxGDeuKqZFf1dypM7533b9K0BIaSetIPbc8JWJV2rcE=; b=IFqZWE91k0ftZElHDIBjkPAwnv1+6Q+gNKM7BvQGeCPHdLvSygHmWDoQOrYg1ujEPm DV2MJKh30NShTxQbMn9OX+YVY8iXWPDsD2DJkJNCr5XFuGgrOZB4fCdv1Id+hJ5M7PTz Zsgr0uLBuddoS7Oaeow4q9LDEHMVZSEfZH6Qr27fZ74RgpTsIxtuzX7cXbq4LpRCHA53 uwGcBTkLYlLDnTjAsrx0yceGIn13AxTbLD0RkoK78GqYpm/ZAJJQu/PzIiYwwf2v2+jM SN/v+rn6bpqPQ5igUNP5O3YwR6B/Fgn3DWdc4UW665nbrQvMalvKqVcHdynzHEITxVpE JuwA== X-Gm-Message-State: AOPr4FWNL5W0zJ5+hEmmlHVUNdXfICMwaF/1MaApduCQ6WLcDGMHfUPoZVKdaoPifRr3Fg== X-Received: by 10.129.128.193 with SMTP id q184mr17564343ywf.220.1460928669638; Sun, 17 Apr 2016 14:31:09 -0700 (PDT) Received: from localhost ([107.13.171.182]) by smtp.gmail.com with ESMTPSA id b2sm13893717ywb.51.2016.04.17.14.31.08 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sun, 17 Apr 2016 14:31:09 -0700 (PDT) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Al Viro , Ming Lei Subject: [PATCH v5 4/8] iov_iter: use bvec iterator to implement iterate_bvec() Date: Mon, 18 Apr 2016 05:29:53 +0800 Message-Id: <1460928615-20894-5-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1460928615-20894-1-git-send-email-ming.lei@canonical.com> References: <1460928615-20894-1-git-send-email-ming.lei@canonical.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP bvec has one native/mature iterator for long time, so not necessary to use the reinvented wheel for iterating bvecs in lib/iov_iter.c. Two ITER_BVEC test cases are run: - xfstest(-g auto) on loop dio/aio, no regression found - swap file works well under extreme stress(stress-ng --all 64 -t 800 -v), and lots of OOMs are triggerd, and the whole system still survives Signed-off-by: Ming Lei Reviewed-by: Christoph Hellwig --- lib/iov_iter.c | 45 +++++++++++++++------------------------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 5fecddc..8e30ea5 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -56,37 +56,24 @@ n = wanted; \ } -#define iterate_bvec(i, n, __v, __p, skip, STEP) { \ - size_t wanted = n; \ - __p = i->bvec; \ - __v.bv_len = min_t(size_t, n, __p->bv_len - skip); \ - if (likely(__v.bv_len)) { \ - __v.bv_page = __p->bv_page; \ - __v.bv_offset = __p->bv_offset + skip; \ - (void)(STEP); \ - skip += __v.bv_len; \ - n -= __v.bv_len; \ - } \ - while (unlikely(n)) { \ - __p++; \ - __v.bv_len = min_t(size_t, n, __p->bv_len); \ - if (unlikely(!__v.bv_len)) \ +#define iterate_bvec(i, n, __v, __bi, skip, STEP) { \ + struct bvec_iter __start; \ + __start.bi_size = n; \ + __start.bi_bvec_done = skip; \ + __start.bi_idx = 0; \ + for_each_bvec(__v, i->bvec, __bi, __start) { \ + if (!__v.bv_len) \ continue; \ - __v.bv_page = __p->bv_page; \ - __v.bv_offset = __p->bv_offset; \ (void)(STEP); \ - skip = __v.bv_len; \ - n -= __v.bv_len; \ } \ - n = wanted; \ } #define iterate_all_kinds(i, n, v, I, B, K) { \ size_t skip = i->iov_offset; \ if (unlikely(i->type & ITER_BVEC)) { \ - const struct bio_vec *bvec; \ struct bio_vec v; \ - iterate_bvec(i, n, v, bvec, skip, (B)) \ + struct bvec_iter __bi; \ + iterate_bvec(i, n, v, __bi, skip, (B)) \ } else if (unlikely(i->type & ITER_KVEC)) { \ const struct kvec *kvec; \ struct kvec v; \ @@ -101,15 +88,13 @@ #define iterate_and_advance(i, n, v, I, B, K) { \ size_t skip = i->iov_offset; \ if (unlikely(i->type & ITER_BVEC)) { \ - const struct bio_vec *bvec; \ + const struct bio_vec *bvec = i->bvec; \ struct bio_vec v; \ - iterate_bvec(i, n, v, bvec, skip, (B)) \ - if (skip == bvec->bv_len) { \ - bvec++; \ - skip = 0; \ - } \ - i->nr_segs -= bvec - i->bvec; \ - i->bvec = bvec; \ + struct bvec_iter __bi; \ + iterate_bvec(i, n, v, __bi, skip, (B)) \ + i->bvec = __bvec_iter_bvec(i->bvec, __bi); \ + i->nr_segs -= i->bvec - bvec; \ + skip = __bi.bi_bvec_done; \ } else if (unlikely(i->type & ITER_KVEC)) { \ const struct kvec *kvec; \ struct kvec v; \