From patchwork Fri Aug 12 18:38:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A . Shutemov" X-Patchwork-Id: 9277687 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 980EB60780 for ; Fri, 12 Aug 2016 18:43:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E24B28AB6 for ; Fri, 12 Aug 2016 18:43:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 812AF28AD4; Fri, 12 Aug 2016 18:43:10 +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 1881328AB6 for ; Fri, 12 Aug 2016 18:43:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753228AbcHLSmv (ORCPT ); Fri, 12 Aug 2016 14:42:51 -0400 Received: from mga09.intel.com ([134.134.136.24]:35159 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752614AbcHLSi5 (ORCPT ); Fri, 12 Aug 2016 14:38:57 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP; 12 Aug 2016 11:38:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,512,1464678000"; d="scan'208";a="154940198" Received: from black.fi.intel.com ([10.237.72.93]) by fmsmga004.fm.intel.com with ESMTP; 12 Aug 2016 11:38:44 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 89895662; Fri, 12 Aug 2016 21:38:34 +0300 (EEST) 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: [PATCHv2 24/41] fs: make block_write_{begin, end}() be able to handle huge pages Date: Fri, 12 Aug 2016 21:38:07 +0300 Message-Id: <1471027104-115213-25-git-send-email-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1471027104-115213-1-git-send-email-kirill.shutemov@linux.intel.com> References: <1471027104-115213-1-git-send-email-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 It's more or less straight-forward. Most changes are around getting offset/len withing page right and zero out desired part of the page. Signed-off-by: Kirill A. Shutemov --- fs/buffer.c | 53 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 2739f5dae690..7f50e5a63670 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -1870,21 +1870,21 @@ void page_zero_new_buffers(struct page *page, unsigned from, unsigned to) do { block_end = block_start + bh->b_size; - if (buffer_new(bh)) { - if (block_end > from && block_start < to) { - if (!PageUptodate(page)) { - unsigned start, size; + if (buffer_new(bh) && block_end > from && block_start < to) { + if (!PageUptodate(page)) { + unsigned start, size; - start = max(from, block_start); - size = min(to, block_end) - start; + start = max(from, block_start); + size = min(to, block_end) - start; - zero_user(page, start, size); - set_buffer_uptodate(bh); - } - - clear_buffer_new(bh); - mark_buffer_dirty(bh); + zero_user(page + block_start / PAGE_SIZE, + start % PAGE_SIZE, + size); + set_buffer_uptodate(bh); } + + clear_buffer_new(bh); + mark_buffer_dirty(bh); } block_start = block_end; @@ -1950,18 +1950,20 @@ iomap_to_bh(struct inode *inode, sector_t block, struct buffer_head *bh, int __block_write_begin_int(struct page *page, loff_t pos, unsigned len, get_block_t *get_block, struct iomap *iomap) { - unsigned from = pos & (PAGE_SIZE - 1); - unsigned to = from + len; - struct inode *inode = page->mapping->host; + unsigned from, to; + struct inode *inode = page_mapping(page)->host; unsigned block_start, block_end; sector_t block; int err = 0; unsigned blocksize, bbits; struct buffer_head *bh, *head, *wait[2], **wait_bh=wait; + page = compound_head(page); + from = pos & ~hpage_mask(page); + to = from + len; BUG_ON(!PageLocked(page)); - BUG_ON(from > PAGE_SIZE); - BUG_ON(to > PAGE_SIZE); + BUG_ON(from > hpage_size(page)); + BUG_ON(to > hpage_size(page)); BUG_ON(from > to); head = create_page_buffers(page, inode, 0); @@ -2001,10 +2003,15 @@ int __block_write_begin_int(struct page *page, loff_t pos, unsigned len, mark_buffer_dirty(bh); continue; } - if (block_end > to || block_start < from) - zero_user_segments(page, - to, block_end, - block_start, from); + if (block_end > to || block_start < from) { + BUG_ON(to - from > PAGE_SIZE); + zero_user_segments(page + + block_start / PAGE_SIZE, + to % PAGE_SIZE, + (block_start % PAGE_SIZE) + blocksize, + block_start % PAGE_SIZE, + from % PAGE_SIZE); + } continue; } } @@ -2048,6 +2055,7 @@ static int __block_commit_write(struct inode *inode, struct page *page, unsigned blocksize; struct buffer_head *bh, *head; + VM_BUG_ON_PAGE(PageTail(page), page); bh = head = page_buffers(page); blocksize = bh->b_size; @@ -2114,7 +2122,8 @@ int block_write_end(struct file *file, struct address_space *mapping, struct inode *inode = mapping->host; unsigned start; - start = pos & (PAGE_SIZE - 1); + page = compound_head(page); + start = pos & ~hpage_mask(page); if (unlikely(copied < len)) { /*