Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933396AbcK2L1P (ORCPT ); Tue, 29 Nov 2016 06:27:15 -0500 Received: from mga07.intel.com ([134.134.136.100]:4800 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757313AbcK2LX7 (ORCPT ); Tue, 29 Nov 2016 06:23:59 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,568,1473145200"; d="scan'208";a="906679074" 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: [PATCHv5 05/36] thp: try to free page's buffers before attempt split Date: Tue, 29 Nov 2016 14:22:33 +0300 Message-Id: <20161129112304.90056-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161129112304.90056-1-kirill.shutemov@linux.intel.com> References: <20161129112304.90056-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: 2487 Lines: 74 We want page to be isolated from the rest of the system before spliting it. We rely on page count to be 2 for file pages to make sure nobody uses the page: one pin to caller, one to radix-tree. Filesystems with backing storage can have page count increased if it has buffers. Let's try to free them, before attempt split. And remove one guarding VM_BUG_ON_PAGE(). Signed-off-by: Kirill A. Shutemov --- include/linux/buffer_head.h | 1 + mm/huge_memory.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index d67ab83823ad..fd4134ce9c54 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -400,6 +400,7 @@ extern int __set_page_dirty_buffers(struct page *page); #else /* CONFIG_BLOCK */ static inline void buffer_init(void) {} +static inline int page_has_buffers(struct page *page) { return 0; } static inline int try_to_free_buffers(struct page *page) { return 1; } static inline int inode_has_buffers(struct inode *inode) { return 0; } static inline void invalidate_inode_buffers(struct inode *inode) {} diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 91dbab9644be..a15d566b14f6 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -2111,7 +2112,6 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) VM_BUG_ON_PAGE(is_huge_zero_page(page), page); VM_BUG_ON_PAGE(!PageLocked(page), page); - VM_BUG_ON_PAGE(!PageSwapBacked(page), page); VM_BUG_ON_PAGE(!PageCompound(page), page); if (PageAnon(head)) { @@ -2140,6 +2140,23 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) goto out; } + /* Try to free buffers before attempt split */ + if (!PageSwapBacked(head) && PagePrivate(page)) { + /* + * We cannot trigger writeback from here due possible + * recursion if triggered from vmscan, only wait. + * + * Caller can trigger writeback it on its own, if safe. + */ + wait_on_page_writeback(head); + + if (page_has_buffers(head) && !try_to_release_page(head, + GFP_KERNEL)) { + ret = -EBUSY; + goto out; + } + } + /* Addidional pin from radix tree */ extra_pins = 1; anon_vma = NULL; -- 2.10.2