From patchwork Thu Jan 26 11:57:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A . Shutemov" X-Patchwork-Id: 9539147 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 48880601D7 for ; Thu, 26 Jan 2017 12:09:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D74227D13 for ; Thu, 26 Jan 2017 12:09:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 321DA2819A; Thu, 26 Jan 2017 12:09:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9631727D13 for ; Thu, 26 Jan 2017 12:09:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753024AbdAZL6z (ORCPT ); Thu, 26 Jan 2017 06:58:55 -0500 Received: from mga11.intel.com ([192.55.52.93]:56376 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752937AbdAZL6w (ORCPT ); Thu, 26 Jan 2017 06:58:52 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 26 Jan 2017 03:58:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,289,1477983600"; d="scan'208";a="1118089760" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 26 Jan 2017 03:58:37 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id A75B2359; Thu, 26 Jan 2017 13:58:25 +0200 (EET) 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: [PATCHv6 12/37] brd: make it handle huge pages Date: Thu, 26 Jan 2017 14:57:54 +0300 Message-Id: <20170126115819.58875-13-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170126115819.58875-1-kirill.shutemov@linux.intel.com> References: <20170126115819.58875-1-kirill.shutemov@linux.intel.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 3adc32a3153b..d2f7dc87b545 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);