From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754059Ab3IWMGY (ORCPT ); Mon, 23 Sep 2013 08:06:24 -0400 Received: from mga02.intel.com ([134.134.136.20]:58705 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753783Ab3IWMGV (ORCPT ); Mon, 23 Sep 2013 08:06:21 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.90,962,1371106800"; d="scan'208";a="407649334" From: "Kirill A. Shutemov" To: Andrea Arcangeli , Andrew Morton Cc: Al Viro , Hugh Dickins , Wu Fengguang , Jan Kara , Mel Gorman , linux-mm@kvack.org, Andi Kleen , Matthew Wilcox , "Kirill A. Shutemov" , Hillf Danton , Dave Hansen , Ning Qu , Alexander Shishkin , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv6 14/22] thp, mm: allocate huge pages in grab_cache_page_write_begin() Date: Mon, 23 Sep 2013 15:05:42 +0300 Message-Id: <1379937950-8411-15-git-send-email-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: <1379937950-8411-1-git-send-email-kirill.shutemov@linux.intel.com> References: <1379937950-8411-1-git-send-email-kirill.shutemov@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Try to allocate huge page if flags has AOP_FLAG_TRANSHUGE. If, for some reason, it's not possible allocate a huge page at this possition, it returns NULL. Caller should take care of fallback to small pages. Signed-off-by: Kirill A. Shutemov --- include/linux/fs.h | 1 + mm/filemap.c | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 26801f0bb1..42ccdeddd9 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -282,6 +282,7 @@ enum positive_aop_returns { #define AOP_FLAG_NOFS 0x0004 /* used by filesystem to direct * helper code (eg buffer layer) * to clear GFP_FS from alloc */ +#define AOP_FLAG_TRANSHUGE 0x0008 /* allocate transhuge page */ /* * oh the beauties of C type declarations. diff --git a/mm/filemap.c b/mm/filemap.c index 3421bcaed4..410879a801 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2322,18 +2322,37 @@ struct page *grab_cache_page_write_begin(struct address_space *mapping, gfp_t gfp_mask; struct page *page; gfp_t gfp_notmask = 0; + bool must_use_thp = (flags & AOP_FLAG_TRANSHUGE) && + IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE_PAGECACHE); gfp_mask = mapping_gfp_mask(mapping); + if (must_use_thp) { + BUG_ON(index & HPAGE_CACHE_INDEX_MASK); + BUG_ON(!(gfp_mask & __GFP_COMP)); + } if (mapping_cap_account_dirty(mapping)) gfp_mask |= __GFP_WRITE; if (flags & AOP_FLAG_NOFS) gfp_notmask = __GFP_FS; repeat: page = find_lock_page(mapping, index); - if (page) + if (page) { + if (must_use_thp && !PageTransHuge(page)) { + unlock_page(page); + page_cache_release(page); + return NULL; + } goto found; + } - page = __page_cache_alloc(gfp_mask & ~gfp_notmask); + if (must_use_thp) { + page = alloc_pages(gfp_mask & ~gfp_notmask, HPAGE_PMD_ORDER); + if (page) + count_vm_event(THP_WRITE_ALLOC); + else + count_vm_event(THP_WRITE_ALLOC_FAILED); + } else + page = __page_cache_alloc(gfp_mask & ~gfp_notmask); if (!page) return NULL; status = add_to_page_cache_lru(page, mapping, index, -- 1.8.4.rc3