Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754082Ab3IWMG1 (ORCPT ); Mon, 23 Sep 2013 08:06:27 -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 S1754049Ab3IWMGY (ORCPT ); Mon, 23 Sep 2013 08:06:24 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.90,962,1371106800"; d="scan'208";a="382188957" 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 01/22] mm: implement zero_huge_user_segment and friends Date: Mon, 23 Sep 2013 15:05:29 +0300 Message-Id: <1379937950-8411-2-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 Content-Length: 2930 Lines: 96 Let's add helpers to clear huge page segment(s). They provide the same functionallity as zero_user_segment and zero_user, but for huge pages. Signed-off-by: Kirill A. Shutemov --- include/linux/mm.h | 18 ++++++++++++++++++ mm/memory.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 8b6e55ee88..a7b7e62930 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1809,9 +1809,27 @@ extern void dump_page(struct page *page); extern void clear_huge_page(struct page *page, unsigned long addr, unsigned int pages_per_huge_page); +extern void zero_huge_user_segment(struct page *page, + unsigned start, unsigned end); +static inline void zero_huge_user(struct page *page, + unsigned start, unsigned len) +{ + zero_huge_user_segment(page, start, start + len); +} extern void copy_user_huge_page(struct page *dst, struct page *src, unsigned long addr, struct vm_area_struct *vma, unsigned int pages_per_huge_page); +#else +static inline void zero_huge_user_segment(struct page *page, + unsigned start, unsigned end) +{ + BUILD_BUG(); +} +static inline void zero_huge_user(struct page *page, + unsigned start, unsigned len) +{ + BUILD_BUG(); +} #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */ #ifdef CONFIG_DEBUG_PAGEALLOC diff --git a/mm/memory.c b/mm/memory.c index ca00039471..e5f74cd634 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4291,6 +4291,42 @@ void clear_huge_page(struct page *page, } } +void zero_huge_user_segment(struct page *page, unsigned start, unsigned end) +{ + int i; + unsigned start_idx, end_idx; + unsigned start_off, end_off; + + BUG_ON(end < start); + + might_sleep(); + + if (start == end) + return; + + start_idx = start >> PAGE_SHIFT; + start_off = start & ~PAGE_MASK; + end_idx = (end - 1) >> PAGE_SHIFT; + end_off = ((end - 1) & ~PAGE_MASK) + 1; + + /* + * if start and end are on the same small page we can call + * zero_user_segment() once and save one kmap_atomic(). + */ + if (start_idx == end_idx) + return zero_user_segment(page + start_idx, start_off, end_off); + + /* zero the first (possibly partial) page */ + zero_user_segment(page + start_idx, start_off, PAGE_SIZE); + for (i = start_idx + 1; i < end_idx; i++) { + cond_resched(); + clear_highpage(page + i); + flush_dcache_page(page + i); + } + /* zero the last (possibly partial) page */ + zero_user_segment(page + end_idx, 0, end_off); +} + static void copy_user_gigantic_page(struct page *dst, struct page *src, unsigned long addr, struct vm_area_struct *vma, -- 1.8.4.rc3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/