Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965908AbcJYAS5 (ORCPT ); Mon, 24 Oct 2016 20:18:57 -0400 Received: from mga03.intel.com ([134.134.136.65]:64008 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933302AbcJYAO1 (ORCPT ); Mon, 24 Oct 2016 20:14:27 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,543,1473145200"; d="scan'208";a="777123243" From: "Kirill A. Shutemov" To: "Theodore Ts'o" , Andreas Dilger , Jan Kara , Andrew Morton Cc: Alexander Viro , Hugh Dickins , Andrea Arcangeli , Dave Hansen , Vlastimil Babka , Matthew Wilcox , Ross Zwisler , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-block@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv4 19/43] brd: make it handle huge pages Date: Tue, 25 Oct 2016 03:13:18 +0300 Message-Id: <20161025001342.76126-20-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161025001342.76126-1-kirill.shutemov@linux.intel.com> References: <20161025001342.76126-1-kirill.shutemov@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2057 Lines: 75 Do not assume length of bio segment is never larger than PAGE_SIZE. With huge pages it's HPAGE_PMD_SIZE (2M on x86-64). Signed-off-by: Kirill A. Shutemov --- drivers/block/brd.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/block/brd.c b/drivers/block/brd.c index 0c76d4016eeb..4214163350d2 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -202,12 +202,15 @@ static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n) size_t copy; copy = min_t(size_t, n, PAGE_SIZE - offset); + n -= copy; if (!brd_insert_page(brd, sector)) return -ENOSPC; - if (copy < n) { + while (n) { sector += copy >> SECTOR_SHIFT; if (!brd_insert_page(brd, sector)) return -ENOSPC; + copy = min_t(size_t, n, PAGE_SIZE); + n -= copy; } return 0; } @@ -242,6 +245,7 @@ static void copy_to_brd(struct brd_device *brd, const void *src, size_t copy; copy = min_t(size_t, n, PAGE_SIZE - offset); + n -= copy; page = brd_lookup_page(brd, sector); BUG_ON(!page); @@ -249,10 +253,11 @@ static void copy_to_brd(struct brd_device *brd, const void *src, memcpy(dst + offset, src, copy); kunmap_atomic(dst); - if (copy < n) { + while (n) { src += copy; sector += copy >> SECTOR_SHIFT; - copy = n - copy; + copy = min_t(size_t, n, PAGE_SIZE); + n -= copy; page = brd_lookup_page(brd, sector); BUG_ON(!page); @@ -274,6 +279,7 @@ static void copy_from_brd(void *dst, struct brd_device *brd, size_t copy; copy = min_t(size_t, n, PAGE_SIZE - offset); + n -= copy; page = brd_lookup_page(brd, sector); if (page) { src = kmap_atomic(page); @@ -282,10 +288,11 @@ static void copy_from_brd(void *dst, struct brd_device *brd, } else memset(dst, 0, copy); - if (copy < n) { + while (n) { dst += copy; sector += copy >> SECTOR_SHIFT; - copy = n - copy; + copy = min_t(size_t, n, PAGE_SIZE); + n -= copy; page = brd_lookup_page(brd, sector); if (page) { src = kmap_atomic(page); -- 2.9.3