From patchwork Tue Mar 5 06:57:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 15226 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 0C68323E24 for ; Tue, 5 Mar 2013 06:58:46 +0000 (UTC) Received: from mail-ve0-f181.google.com (mail-ve0-f181.google.com [209.85.128.181]) by fiordland.canonical.com (Postfix) with ESMTP id 9E77CA18CCD for ; Tue, 5 Mar 2013 06:58:45 +0000 (UTC) Received: by mail-ve0-f181.google.com with SMTP id d10so5382086vea.40 for ; Mon, 04 Mar 2013 22:58:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-auditid:from:to:date:message-id:x-mailer:in-reply-to :references:x-brightmail-tracker:cc:subject:x-beenthere :x-mailman-version:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-gm-message-state; bh=Rmtu8+GCmw9q0SGbECaFWHLJyRXOZ4ciMDyUdcIuCr8=; b=hvJjdp2nWwzUoBmV173TETWyFuHsH99cW/lPUtS87XS5n790jxfc2K78zXNAJqcuky Yky9LGFA3yrv3lZ85KzEGOa0A8HBSutvGrlN/I96mva47VnyC/svHUqrqu+Ub45KMn+v 951nPUdM5ZjMEBSL3UwbGnPe41nfG6KB5Kl6MAVlL0Uhxo5CkB/v3cTi/ddBDu+30rRq oNwlexZQFuYyxXdYRikJp3fvoGhPk+0WWHAili8QtCR8aoWqZM4V37iuK13sY/Dcr4oz 4ULxCc95LFL3HhT3vzBtAYm9S11MdaJjI59CHDprP8/ccQkpUeJbjkoiBvBPjVA2WFQv pipw== X-Received: by 10.52.93.235 with SMTP id cx11mr7735502vdb.51.1362466725080; Mon, 04 Mar 2013 22:58:45 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.127.98 with SMTP id nf2csp96898veb; Mon, 4 Mar 2013 22:58:44 -0800 (PST) X-Received: by 10.14.214.66 with SMTP id b42mr67480371eep.34.1362466723698; Mon, 04 Mar 2013 22:58:43 -0800 (PST) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id w41si38695954eel.249.2013.03.04.22.58.43; Mon, 04 Mar 2013 22:58:43 -0800 (PST) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1UClpi-0004Cu-9Z; Tue, 05 Mar 2013 06:58:42 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1UClpg-0004Cl-7r for linaro-mm-sig@lists.linaro.org; Tue, 05 Mar 2013 06:58:40 +0000 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MJ600MM1E137MT0@mailout4.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 05 Mar 2013 15:58:38 +0900 (KST) X-AuditID: cbfee61a-b7f7d6d000000f4e-3d-5135979d7aa5 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 2D.5D.03918.D9795315; Tue, 05 Mar 2013 15:58:37 +0900 (KST) Received: from localhost.localdomain ([106.116.147.30]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MJ600A49E14LIB0@mmp2.samsung.com>; Tue, 05 Mar 2013 15:58:37 +0900 (KST) From: Marek Szyprowski To: linux-mm@kvack.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Date: Tue, 05 Mar 2013 07:57:57 +0100 Message-id: <1362466679-17111-4-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1362466679-17111-1-git-send-email-m.szyprowski@samsung.com> References: <1362466679-17111-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrNLMWRmVeSWpSXmKPExsVy+t9jQd25000DDS7eMLaYs34Nm8XfScfY LTbOWM9qcbbpDbvFlysPmSwu75rDZnFvzX9Wi7VH7rJb/D7YyW6x4HgLq8Wyr+/ZHbg9fv+a xOjRu/crq8emVZ1sHps+TWL3ODHjN4vH7X+PmT3W/XnF5NG3ZRWjx+dNcgGcUVw2Kak5mWWp Rfp2CVwZsx6vYiv4rlvx6O4ZtgbGNtUuRk4OCQETiaXXzjJB2GISF+6tZ+ti5OIQEpjOKPF6 yV52CKedSWLjsSdgVWwChhJdb7vYQGwRgTCJP43bWEGKmAWOM0n8ubgWKMHBISyQJNG+QhCk hkVAVaL9+z6wXl4BD4kXr+eAlUgIKEjMmWQDEuYU8JR4svwjC4gtBFQyb9tnpgmMvAsYGVYx iqYWJBcUJ6XnGuoVJ+YWl+al6yXn525iBAfpM6kdjCsbLA4xCnAwKvHwMhw1CRRiTSwrrsw9 xCjBwawkwitWZxooxJuSWFmVWpQfX1Sak1p8iFGag0VJnJfx1JMAIYH0xJLU7NTUgtQimCwT B6dUA6Nuq/pW04f3Ay3ttxrHG1Wpc+Qa8n9ZMX9ru+Dy1Buq+i+UvOc3bT/zhOnenyMt8S6O 3z+YGfjYffG2vvRLlmmb5vGmyauvvZyQsuroV4Hda5LWy5rv/eGReuX8vetZkefvfsvQuKoy t7jj2TFlE08OA42ZCxfFzJJzXhpV8CEzZvoiEYedR3yUWIozEg21mIuKEwFd9qQ8TgIAAA== Cc: Arnd Bergmann , Bartlomiej Zolnierkiewicz , Mel Gorman , Michal Nazarewicz , Minchan Kim , Kyungmin Park , Andrew Morton Subject: [Linaro-mm-sig] [RFC/PATCH 3/5] mm: get_user_pages: use NON-MOVABLE pages when FOLL_DURABLE flag is set X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQlQxfzqhHQkX4rRdzCZCuZFi1jMxI2eenbFweVYD0oTgaiQgc6dCrSdbw5kHMEYOnSKD0fu Ensure that newly allocated pages, which are faulted in in FOLL_DURABLE mode comes from non-movalbe pageblocks, to workaround migration failures with Contiguous Memory Allocator. Signed-off-by: Marek Szyprowski Signed-off-by: Kyungmin Park --- include/linux/highmem.h | 12 ++++++++++-- include/linux/mm.h | 2 ++ mm/memory.c | 24 ++++++++++++++++++------ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/include/linux/highmem.h b/include/linux/highmem.h index 7fb31da..cf0b9d8 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -168,7 +168,8 @@ __alloc_zeroed_user_highpage(gfp_t movableflags, #endif /** - * alloc_zeroed_user_highpage_movable - Allocate a zeroed HIGHMEM page for a VMA that the caller knows can move + * alloc_zeroed_user_highpage_movable - Allocate a zeroed HIGHMEM page for + * a VMA that the caller knows can move * @vma: The VMA the page is to be allocated for * @vaddr: The virtual address the page will be inserted into * @@ -177,11 +178,18 @@ __alloc_zeroed_user_highpage(gfp_t movableflags, */ static inline struct page * alloc_zeroed_user_highpage_movable(struct vm_area_struct *vma, - unsigned long vaddr) + unsigned long vaddr) { return __alloc_zeroed_user_highpage(__GFP_MOVABLE, vma, vaddr); } +static inline struct page * +alloc_zeroed_user_highpage(gfp_t gfp, struct vm_area_struct *vma, + unsigned long vaddr) +{ + return __alloc_zeroed_user_highpage(gfp, vma, vaddr); +} + static inline void clear_highpage(struct page *page) { void *kaddr = kmap_atomic(page); diff --git a/include/linux/mm.h b/include/linux/mm.h index 9806e54..c11f58f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -165,6 +165,7 @@ extern pgprot_t protection_map[16]; #define FAULT_FLAG_RETRY_NOWAIT 0x10 /* Don't drop mmap_sem and wait when retrying */ #define FAULT_FLAG_KILLABLE 0x20 /* The fault task is in SIGKILL killable region */ #define FAULT_FLAG_TRIED 0x40 /* second try */ +#define FAULT_FLAG_NO_CMA 0x80 /* don't use CMA pages */ /* * vm_fault is filled by the the pagefault handler and passed to the vma's @@ -1633,6 +1634,7 @@ static inline struct page *follow_page(struct vm_area_struct *vma, #define FOLL_HWPOISON 0x100 /* check page is hwpoisoned */ #define FOLL_NUMA 0x200 /* force NUMA hinting page fault */ #define FOLL_MIGRATION 0x400 /* wait for page to replace migration entry */ +#define FOLL_DURABLE 0x800 /* get the page reference for a long time */ typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr, void *data); diff --git a/mm/memory.c b/mm/memory.c index 42dfd8e..2b9c2dd 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1816,6 +1816,9 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, int ret; unsigned int fault_flags = 0; + if (gup_flags & FOLL_DURABLE) + fault_flags = FAULT_FLAG_NO_CMA; + /* For mlock, just skip the stack guard page. */ if (foll_flags & FOLL_MLOCK) { if (stack_guard_page(vma, start)) @@ -2495,7 +2498,7 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo */ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long address, pte_t *page_table, pmd_t *pmd, - spinlock_t *ptl, pte_t orig_pte) + spinlock_t *ptl, pte_t orig_pte, unsigned int flags) __releases(ptl) { struct page *old_page, *new_page = NULL; @@ -2505,6 +2508,10 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma, struct page *dirty_page = NULL; unsigned long mmun_start = 0; /* For mmu_notifiers */ unsigned long mmun_end = 0; /* For mmu_notifiers */ + gfp_t gfp = GFP_HIGHUSER_MOVABLE; + + if (IS_ENABLED(CONFIG_CMA) && (flags & FAULT_FLAG_NO_CMA)) + gfp &= ~__GFP_MOVABLE; old_page = vm_normal_page(vma, address, orig_pte); if (!old_page) { @@ -2668,11 +2675,11 @@ gotten: goto oom; if (is_zero_pfn(pte_pfn(orig_pte))) { - new_page = alloc_zeroed_user_highpage_movable(vma, address); + new_page = alloc_zeroed_user_highpage(gfp, vma, address); if (!new_page) goto oom; } else { - new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address); + new_page = alloc_page_vma(gfp, vma, address); if (!new_page) goto oom; cow_user_page(new_page, old_page, address, vma); @@ -3032,7 +3039,7 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma, } if (flags & FAULT_FLAG_WRITE) { - ret |= do_wp_page(mm, vma, address, page_table, pmd, ptl, pte); + ret |= do_wp_page(mm, vma, address, page_table, pmd, ptl, pte, flags); if (ret & VM_FAULT_ERROR) ret &= VM_FAULT_ERROR; goto out; @@ -3187,6 +3194,11 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma, struct vm_fault vmf; int ret; int page_mkwrite = 0; + gfp_t gfp = GFP_HIGHUSER_MOVABLE; + + if (IS_ENABLED(CONFIG_CMA) && (flags & FAULT_FLAG_NO_CMA)) + gfp &= ~__GFP_MOVABLE; + /* * If we do COW later, allocate page befor taking lock_page() @@ -3197,7 +3209,7 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma, if (unlikely(anon_vma_prepare(vma))) return VM_FAULT_OOM; - cow_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address); + cow_page = alloc_page_vma(gfp, vma, address); if (!cow_page) return VM_FAULT_OOM; @@ -3614,7 +3626,7 @@ int handle_pte_fault(struct mm_struct *mm, if (flags & FAULT_FLAG_WRITE) { if (!pte_write(entry)) return do_wp_page(mm, vma, address, - pte, pmd, ptl, entry); + pte, pmd, ptl, entry, flags); entry = pte_mkdirty(entry); } entry = pte_mkyoung(entry);