From patchwork Tue Jun 16 22:28:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Toshi Kani X-Patchwork-Id: 6620821 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9501B9F399 for ; Tue, 16 Jun 2015 22:28:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CC65420786 for ; Tue, 16 Jun 2015 22:28:56 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CBAD2206A4 for ; Tue, 16 Jun 2015 22:28:54 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8C85E18295A; Tue, 16 Jun 2015 15:28:54 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from g4t3425.houston.hp.com (g4t3425.houston.hp.com [15.201.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F101F18294F for ; Tue, 16 Jun 2015 15:28:52 -0700 (PDT) Received: from g9t2301.houston.hp.com (g9t2301.houston.hp.com [16.216.185.78]) by g4t3425.houston.hp.com (Postfix) with ESMTP id 1CE0C74; Tue, 16 Jun 2015 22:28:52 +0000 (UTC) Received: from misato.fc.hp.com (misato.fc.hp.com [16.78.168.61]) by g9t2301.houston.hp.com (Postfix) with ESMTP id 2E55D5C; Tue, 16 Jun 2015 22:28:51 +0000 (UTC) From: Toshi Kani To: akpm@linux-foundation.org Subject: [PATCH] mm: Fix MAP_POPULATE and mlock() for DAX Date: Tue, 16 Jun 2015 16:28:30 -0600 Message-Id: <1434493710-11138-1-git-send-email-toshi.kani@hp.com> X-Mailer: git-send-email 1.9.3 Cc: linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, kirill.shutemov@linux.intel.com X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP DAX has the following issues in a shared or read-only private mmap'd file. - mmap(MAP_POPULATE) does not pre-fault - mlock() fails with -ENOMEM DAX uses VM_MIXEDMAP for mmap'd files, which do not have struct page associated with the ranges. Both MAP_POPULATE and mlock() call __mm_populate(), which in turn calls __get_user_pages(). Because __get_user_pages() requires a valid page returned from follow_page_mask(), MAP_POPULATE and mlock(), i.e. FOLL_POPULATE, fail in the first page. Change __get_user_pages() to proceed FOLL_POPULATE when the translation is set but its page does not exist (-EFAULT), and @pages is not requested. With that, MAP_POPULATE and mlock() set translations to the requested range and complete successfully. MAP_POPULATE still provides a major performance improvement to DAX as it will avoid page faults during initial access to the pages. mlock() continues to set VM_LOCKED to vma and populate the range. Since there is no struct page, the range is pinned without marking pages mlocked. Note, MAP_POPULATE and mlock() already work for a write-able private mmap'd file on DAX since populate_vma_page_range() breaks COW, which allocates page caches. Signed-off-by: Toshi Kani --- mm/gup.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mm/gup.c b/mm/gup.c index 6297f6b..16d536f 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -490,8 +490,20 @@ retry: } BUG(); } - if (IS_ERR(page)) + if (IS_ERR(page)) { + /* + * No page may be associated with VM_MIXEDMAP. Proceed + * FOLL_POPULATE when the translation is set but its + * page does not exist (-EFAULT), and @pages is not + * requested by the caller. + */ + if ((PTR_ERR(page) == -EFAULT) && (!pages) && + (gup_flags & FOLL_POPULATE) && + (vma->vm_flags & VM_MIXEDMAP)) + goto next_page; + return i ? i : PTR_ERR(page); + } if (pages) { pages[i] = page; flush_anon_page(vma, page, start);