Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2223912pxa; Mon, 24 Aug 2020 08:28:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJQrTHAlp89AtgQvfO4YdqoSDuBoIyPX6WR1NwYAAfL4lhFHyhTbnnIMTJNLjmzUzJRYDw X-Received: by 2002:a17:906:1483:: with SMTP id x3mr6389658ejc.318.1598282909824; Mon, 24 Aug 2020 08:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598282909; cv=none; d=google.com; s=arc-20160816; b=FBVq7b/uHGylGUZEW9eUAIOAhEco/sG4yN7GyIXOmlwWFVlPmAPbWvvNV1IEiwVqCv Cvw1mbnOALH59ebGVawQKAEyS9wOKBVeGQUtJhQZiqBqAVs2h96YubartQRpTmNEunXw kAig7sA3ZAGl/WbOhJ7WJwEi4BfQI9vtJUfiF0wZ9V88+l2IWtgZQ/Oj9BQCIYONf3oy tkD5WJ0aarSnrSCn7uRinnNWRAsr8iCAz2O+wnSkYyTit1az9IwNB7Yvl1qcd6157STp NXfOVaz+Ja6+SPJs3sNvkja56xf8Eb///xqM7Kne/1TTNaRqXeHcLXsshCj9VVpPVBl7 UKUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dHPPYRW7Wyiha4H6WrrBOpZ59u0yhrJkqhE0Dkrp7hM=; b=E344PCKQuk812YkxyylqHjGd73B4kvwAtYDj1AXnJFy3jvgDpLqfP7xKrJPCw2Qyus C1AXjGQNsPKiN7SrW0JSXdIR72Hlg2fOsZ1O0psw9eJuBxdTVxQ9w4XGD38sL93ad2+U d90sqjWU2EFO0H4NbjXKv+I2qk47VDSVhE5ReEkhip6opQahkGod8Hlp9OqPXNsTSLga f0aGWgsUlI4B1I1q3GPcv/tggQ0FiAKKLQklMe/oRr6IwSYV+5qwUsnZgS+w+BUajRTn OU+BrfJySs00HM+BBmPejuGhV3/tVHSNrKbOFPhq/G0RJo/LrBDSmEs3Qykb8IzP1gno YNzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=KjEwPAyZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ba10si6787222edb.472.2020.08.24.08.28.07; Mon, 24 Aug 2020 08:28:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=KjEwPAyZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728002AbgHXPZh (ORCPT + 99 others); Mon, 24 Aug 2020 11:25:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727073AbgHXPRN (ORCPT ); Mon, 24 Aug 2020 11:17:13 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A63EEC061755; Mon, 24 Aug 2020 08:17:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=dHPPYRW7Wyiha4H6WrrBOpZ59u0yhrJkqhE0Dkrp7hM=; b=KjEwPAyZ8OUP/RcNmcLBjN6pV9 DYxhARYtqve1duOzKEr5Xcr8ocVEgCPy5en8ISypdz3pD0/emFMaoaK964ggJbBJd4CHSpyT3WEhu 0y6wYMVR7+fRIFcOy93o7M7VjwVQJ2xwbm+pdChAWPmGp+OmWbWtvw+aOaVa57kmuz7SRhwBIN4Fc 30r8ipYwGYpOa8V4zgtr8UIVLB1lL3cJvWUX0JclfJMAnpd40fQMPlocGCq31ZPxGn3lcZpHClZrm zqQ8gd6k7v8fIGqGlKFqh8jNJvV/8acgEr2H0EAiXuLTwto1N6KPDtw4/WKYOVuujDGyEcyB9Ml0W Dnaqwevg==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kAEDX-0004Cj-1b; Mon, 24 Aug 2020 15:17:03 +0000 From: "Matthew Wilcox (Oracle)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , "Darrick J . Wong" , linux-block@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/11] block: Add bio_for_each_thp_segment_all Date: Mon, 24 Aug 2020 16:16:53 +0100 Message-Id: <20200824151700.16097-5-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200824151700.16097-1-willy@infradead.org> References: <20200824151700.16097-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Iterate once for each THP instead of once for each base page. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/bio.h | 13 +++++++++++++ include/linux/bvec.h | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/linux/bio.h b/include/linux/bio.h index c6d765382926..a0e104910097 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -129,12 +129,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(const struct bio *bio, struct bvec_iter *iter, unsigned int bytes) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index ac0c7299d5b8..ea8a37a7515b 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -162,4 +162,31 @@ 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; + + if (iter_all->done) { + bv->bv_page += thp_nr_pages(bv->bv_page); + page_size = thp_size(bv->bv_page); + bv->bv_offset = 0; + } else { + bv->bv_page = thp_head(bvec->bv_page + + (bvec->bv_offset >> PAGE_SHIFT)); + page_size = thp_size(bv->bv_page); + bv->bv_offset = bvec->bv_offset - + (bv->bv_page - bvec->bv_page) * PAGE_SIZE; + BUG_ON(bv->bv_offset >= page_size); + } + 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 */ -- 2.28.0