From patchwork Fri May 29 02:57:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 11577519 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4572F1392 for ; Fri, 29 May 2020 02:59:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 08C8F2075F for ; Fri, 29 May 2020 02:59:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="OluEwY8n" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 08C8F2075F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 549AA800CC; Thu, 28 May 2020 22:58:32 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AA66C800C6; Thu, 28 May 2020 22:58:31 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4464E800CE; Thu, 28 May 2020 22:58:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0170.hostedemail.com [216.40.44.170]) by kanga.kvack.org (Postfix) with ESMTP id 5D68C800C9 for ; Thu, 28 May 2020 22:58:30 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 25A7D3AA7 for ; Fri, 29 May 2020 02:58:30 +0000 (UTC) X-FDA: 76868248380.19.cry54_ffadd1d4350e Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 028021ACEA2 for ; Fri, 29 May 2020 02:58:29 +0000 (UTC) X-Spam-Summary: 2,0,0,6f2b166280e9b3e4,d41d8cd98f00b204,willy@infradead.org,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1542:1711:1730:1747:1777:1792:2393:2553:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3872:4250:4321:5007:6119:6261:6653:6691:7576:7875:10004:11026:11473:11658:11914:12043:12114:12291:12296:12297:12438:12555:12895:13894:14096:14181:14394:14721:21080:21451:21524:21627:21990:30054:30090,0,RBL:198.137.202.133:@infradead.org:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:0,LUA_SUMMARY:none X-HE-Tag: cry54_ffadd1d4350e X-Filterd-Recvd-Size: 3904 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Fri, 29 May 2020 02:58:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=432shkXra2Q82xS7AlMDJKErtAEp0TEP0/wbg8xsW6c=; b=OluEwY8nD2Sz1fCPP1NDnLLcB0 dFJ0KSRyiNEGNpBDMe8Gq9JnONL0JNWCqyGAuuCS1FOc4azNtaTqh75A2ef8Xp45A41xom4Z3YHvn Wf0Ru2cSwUjg2FCIWdUdhgHanbGsShW+lA8dvnT7jPdkesWDQisov6TEnA2/wiFB1B5FushwnGNK3 sTPiaL/wabSOftV1i4Um76Ng71z88ixtLPVRROqicgFQvvJz2YD8AfgcWcVPQ5aMXGBsLoyMGELpA dbPgzVP3byeQwcPImqiebZo5yC56HDv2nchfhTQPeMEhhLz6OG93ZfHr/qDJ8j6iuO+FZl3ppTm4p 2IhqJoOQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jeVE3-0008Qn-0w; Fri, 29 May 2020 02:58:27 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 12/39] bio: Add bio_for_each_thp_segment_all Date: Thu, 28 May 2020 19:57:57 -0700 Message-Id: <20200529025824.32296-13-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200529025824.32296-1-willy@infradead.org> References: <20200529025824.32296-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 028021ACEA2 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: "Matthew Wilcox (Oracle)" Iterate once for each THP page instead of once for each base page. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/bio.h | 13 +++++++++++++ include/linux/bvec.h | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/linux/bio.h b/include/linux/bio.h index c1c0f9ea4e63..4cc883fd8d63 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -131,12 +131,25 @@ static inline bool bio_next_segment(const struct bio *bio, return true; } +static inline bool bio_next_thp_segment(const struct bio *bio, + struct bvec_iter_all *iter) +{ + if (iter->idx >= bio->bi_vcnt) + return false; + + bvec_thp_advance(&bio->bi_io_vec[iter->idx], iter); + return true; +} + /* * drivers should _never_ use the all version - the bio may have been split * before it got to the driver and the driver won't own all of it */ #define bio_for_each_segment_all(bvl, bio, iter) \ for (bvl = bvec_init_iter_all(&iter); bio_next_segment((bio), &iter); ) +#define bio_for_each_thp_segment_all(bvl, bio, iter) \ + for (bvl = bvec_init_iter_all(&iter); \ + bio_next_thp_segment((bio), &iter); ) static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, unsigned bytes) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index a81c13ac1972..e08bd192e0ed 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -153,4 +153,27 @@ static inline void bvec_advance(const struct bio_vec *bvec, } } +static inline void bvec_thp_advance(const struct bio_vec *bvec, + struct bvec_iter_all *iter_all) +{ + struct bio_vec *bv = &iter_all->bv; + unsigned int page_size = thp_size(bvec->bv_page); + + if (iter_all->done) { + bv->bv_page += hpage_nr_pages(bv->bv_page); + bv->bv_offset = 0; + } else { + BUG_ON(bvec->bv_offset >= page_size); + bv->bv_page = bvec->bv_page; + bv->bv_offset = bvec->bv_offset & (page_size - 1); + } + bv->bv_len = min(page_size - bv->bv_offset, + bvec->bv_len - iter_all->done); + iter_all->done += bv->bv_len; + + if (iter_all->done == bvec->bv_len) { + iter_all->idx++; + iter_all->done = 0; + } +} #endif /* __LINUX_BVEC_ITER_H */