Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932936AbcCKW7k (ORCPT ); Fri, 11 Mar 2016 17:59:40 -0500 Received: from mga04.intel.com ([192.55.52.120]:60164 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932563AbcCKW7a (ORCPT ); Fri, 11 Mar 2016 17:59:30 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,321,1455004800"; d="scan'208";a="667913286" From: "Kirill A. Shutemov" To: Hugh Dickins , Andrea Arcangeli , Andrew Morton Cc: Dave Hansen , Vlastimil Babka , Christoph Lameter , Naoya Horiguchi , Jerome Marchand , Yang Shi , Sasha Levin , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv4 11/25] thp: handle file pages in mremap() Date: Sat, 12 Mar 2016 01:59:03 +0300 Message-Id: <1457737157-38573-12-git-send-email-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1457737157-38573-1-git-send-email-kirill.shutemov@linux.intel.com> References: <1457737157-38573-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: 1428 Lines: 48 We need to mirror logic in move_ptes() wrt need_rmap_locks to get proper serialization file THP. Signed-off-by: Kirill A. Shutemov --- mm/mremap.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/mm/mremap.c b/mm/mremap.c index 3fa0a467df66..88fa7ab1a8ce 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -192,17 +192,27 @@ unsigned long move_page_tables(struct vm_area_struct *vma, break; if (pmd_trans_huge(*old_pmd)) { if (extent == HPAGE_PMD_SIZE) { + struct address_space *mapping = NULL; + struct anon_vma *anon_vma = NULL; bool moved; - VM_BUG_ON_VMA(vma->vm_file || !vma->anon_vma, - vma); /* See comment in move_ptes() */ - if (need_rmap_locks) - anon_vma_lock_write(vma->anon_vma); + if (need_rmap_locks) { + if (vma->vm_file) { + mapping = vma->vm_file->f_mapping; + i_mmap_lock_write(mapping); + } + if (vma->anon_vma) { + anon_vma = vma->anon_vma; + anon_vma_lock_write(anon_vma); + } + } moved = move_huge_pmd(vma, new_vma, old_addr, new_addr, old_end, old_pmd, new_pmd); - if (need_rmap_locks) - anon_vma_unlock_write(vma->anon_vma); + if (anon_vma) + anon_vma_unlock_write(anon_vma); + if (mapping) + i_mmap_unlock_write(mapping); if (moved) { need_flush = true; continue; -- 2.7.0