From patchwork Thu Sep 15 11:54:53 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: 9333467 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 671C2601C2 for ; Thu, 15 Sep 2016 12:10:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55D7328066 for ; Thu, 15 Sep 2016 12:10:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A97F296A2; Thu, 15 Sep 2016 12:10:18 +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 CAA1428066 for ; Thu, 15 Sep 2016 12:10:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934034AbcIOLzm (ORCPT ); Thu, 15 Sep 2016 07:55:42 -0400 Received: from mga07.intel.com ([134.134.136.100]:12138 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933268AbcIOLzj (ORCPT ); Thu, 15 Sep 2016 07:55:39 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP; 15 Sep 2016 04:55:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,339,1470726000"; d="scan'208";a="879188863" Received: from black.fi.intel.com ([10.237.72.56]) by orsmga003.jf.intel.com with ESMTP; 15 Sep 2016 04:55:32 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 84A9A70F; Thu, 15 Sep 2016 14:55:26 +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: [PATCHv3 11/41] thp: try to free page's buffers before attempt split Date: Thu, 15 Sep 2016 14:54:53 +0300 Message-Id: <20160915115523.29737-12-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160915115523.29737-1-kirill.shutemov@linux.intel.com> References: <20160915115523.29737-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 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 ebbacd14d450..006a8a42acfb 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -395,6 +395,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 020a23d6e7f8..44bf0ba3d10f 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -2012,7 +2013,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)) { @@ -2041,6 +2041,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_free_buffers(head)) { + ret = -EBUSY; + goto out; + } + } + /* Addidional pin from radix tree */ extra_pins = 1; anon_vma = NULL;