From patchwork Wed May 9 08:38:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10388691 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AA3B560353 for ; Wed, 9 May 2018 08:40:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AEEF28EB6 for ; Wed, 9 May 2018 08:40:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80EF028EAB; Wed, 9 May 2018 08:40:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39B3128EAC for ; Wed, 9 May 2018 08:40:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B1F16B04B1; Wed, 9 May 2018 04:40:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 913AA6B04B3; Wed, 9 May 2018 04:40:10 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DE266B04B4; Wed, 9 May 2018 04:40:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f72.google.com (mail-pl0-f72.google.com [209.85.160.72]) by kanga.kvack.org (Postfix) with ESMTP id 31C956B04B1 for ; Wed, 9 May 2018 04:40:10 -0400 (EDT) Received: by mail-pl0-f72.google.com with SMTP id bd7-v6so3380681plb.20 for ; Wed, 09 May 2018 01:40:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=mc/pHQaex1QP6SHg4Xp6U29ut1zQZrcrgeTefK+M6H0=; b=bkx0HH/rAtToUkm5MiwU8DHeWxv3wS/wqWuROwBynzdsDTpsZoNKa30UYOtKCi+1u/ fJXS+C/vHZWK4wAyrOD8GBu/YcmnZjVXaNQGqkAYu/fWVFDgAzaffXaVB+VwpHLjdqCF HDqV0YSHwzWsbw0AJ1STL/6JJpj2uz25UgAya1QpNTYD1/eqDgPkV79ir/UMTxB9JsaX FpaL+Ufloj6+6XCTSt+VtXbq67TUoBnxiNyILd6g1OGyfbnpYIcV6v2/3nbgenWpd71j VwxbXEtmn8jBLdqoZm2srYtshS8fdjRb0trYH519tmfVxOQM0KGJPEZO72Hb5Rhm5FUK dF7g== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com X-Gm-Message-State: ALQs6tCy5tr+CRoRs3BBbg0CdcZEOfDBBr7CIDUxem8A7LEw6i5IiB5M UTiY7iHi192xmrpHQfz7DI+Sp++h8W/n/E7hBkwX9BPf8JI4Z8z1+bEX0Y2AD680oOYLGWqFtRM RrjlIhSnXQtk1GEE7cu6/Nv/OP0iqK2gN82hwtyX+mQT5d6tINid8bihcUIy2Eq6igg== X-Received: by 2002:a17:902:407:: with SMTP id 7-v6mr44947189ple.47.1525855209890; Wed, 09 May 2018 01:40:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoyNdls0Q/YvOSJnic0k3aPEWSETQEFQyzTCdt2Y+1Td+N65mCGeEVn+n0EY7eO9SgZ1IRJ X-Received: by 2002:a17:902:407:: with SMTP id 7-v6mr44947148ple.47.1525855209163; Wed, 09 May 2018 01:40:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525855209; cv=none; d=google.com; s=arc-20160816; b=rfCzHH847ZbinwmDgC+1p8TYLYCGhaO+VNhbrLfolKoNBUOGHqBiaIvDAgtclxqBIt 5+8hoLnktWDXG/WcQF//ikqxtSkTztVRFskl8fvJRO0Mj/nZ512el20xeuEHxhmZ5T3n 5P+GkHda/RZ1YdfMqhbiQ10E1xakXqZaNgT7smZPBFgwaL6W9FTtprZGQWXpJs57701L aYsvu0rjY36hWymC1FGn9XNaGWxhPt3yE7USHFxDaRyU/sS/cWUr6bVV/ReN+SuxGhfI BGkuEeB5FNMNbse8tEDOCcxjcjGhYitYMT+FtQUGzs1880Hi91AzTdokuudQStobY9XZ OCjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=mc/pHQaex1QP6SHg4Xp6U29ut1zQZrcrgeTefK+M6H0=; b=YYT3m5/uX2Wb0NErMS5qyqXmITibeYRCKLb+ePkIaYNOGsFqwK5MGmEWvyiZCwCTNZ vi1qjqV9KuQoV7IFuWYt4YinSXsSebEBkhBT5/DpU7kiM/Kxbb2HgpZe2hp1WlxFYIBq um8/Ofg0pRveKXNW4CeMmF26IHEREH4j3VDphp7OgE4Hbdm+dQyfGUQ2rsHzuWBCdUlZ GJ5ve5EN6D+nUkNZF5nUkF7rCGCJH/ZD32b150Bslyjh6O6N9kPP/0yLjUuFPDN+dL5w 3zwZelyO/SdUunQDxJmuJxk7SzQBmmhexF1Peh4COUqUYi5lpY6NX3z9vtGqtp99rjXz nsIg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com Received: from mga06.intel.com (mga06.intel.com. [134.134.136.31]) by mx.google.com with ESMTPS id z9-v6si21682595plk.94.2018.05.09.01.40.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 May 2018 01:40:09 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) client-ip=134.134.136.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=ying.huang@intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2018 01:40:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,381,1520924400"; d="scan'208";a="52769873" Received: from yhuang-gentoo.sh.intel.com ([10.239.193.148]) by fmsmga004.fm.intel.com with ESMTP; 09 May 2018 01:40:05 -0700 From: "Huang, Ying" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , "Kirill A. Shutemov" , Andrea Arcangeli , Michal Hocko , Johannes Weiner , Shaohua Li , Hugh Dickins , Minchan Kim , Rik van Riel , Dave Hansen , Naoya Horiguchi , Zi Yan Subject: [PATCH -mm -V2 19/21] mm, THP, swap: Support PMD swap mapping in common path Date: Wed, 9 May 2018 16:38:44 +0800 Message-Id: <20180509083846.14823-20-ying.huang@intel.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180509083846.14823-1-ying.huang@intel.com> References: <20180509083846.14823-1-ying.huang@intel.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Huang Ying Original code is only for PMD migration entry, it is revised to support PMD swap mapping. Signed-off-by: "Huang, Ying" Cc: "Kirill A. Shutemov" Cc: Andrea Arcangeli Cc: Michal Hocko Cc: Johannes Weiner Cc: Shaohua Li Cc: Hugh Dickins Cc: Minchan Kim Cc: Rik van Riel Cc: Dave Hansen Cc: Naoya Horiguchi Cc: Zi Yan --- fs/proc/task_mmu.c | 8 ++++---- mm/gup.c | 34 ++++++++++++++++++++++------------ mm/huge_memory.c | 6 +++--- mm/mempolicy.c | 2 +- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index a20c6e495bb2..b061b9003a24 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -977,7 +977,7 @@ static inline void clear_soft_dirty_pmd(struct vm_area_struct *vma, pmd = pmd_clear_soft_dirty(pmd); set_pmd_at(vma->vm_mm, addr, pmdp, pmd); - } else if (is_migration_entry(pmd_to_swp_entry(pmd))) { + } else if (is_swap_pmd(pmd)) { pmd = pmd_swp_clear_soft_dirty(pmd); set_pmd_at(vma->vm_mm, addr, pmdp, pmd); } @@ -1307,7 +1307,7 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, frame = pmd_pfn(pmd) + ((addr & ~PMD_MASK) >> PAGE_SHIFT); } -#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION +#if defined(CONFIG_ARCH_ENABLE_THP_MIGRATION) || defined(CONFIG_THP_SWAP) else if (is_swap_pmd(pmd)) { swp_entry_t entry = pmd_to_swp_entry(pmd); unsigned long offset = swp_offset(entry); @@ -1318,8 +1318,8 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, flags |= PM_SWAP; if (pmd_swp_soft_dirty(pmd)) flags |= PM_SOFT_DIRTY; - VM_BUG_ON(!is_pmd_migration_entry(pmd)); - page = migration_entry_to_page(entry); + if (is_pmd_migration_entry(pmd)) + page = migration_entry_to_page(entry); } #endif diff --git a/mm/gup.c b/mm/gup.c index cf43ff4168b6..43c64a2493da 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -216,6 +216,7 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, spinlock_t *ptl; struct page *page; struct mm_struct *mm = vma->vm_mm; + swp_entry_t entry; pmd = pmd_offset(pudp, address); /* @@ -243,18 +244,21 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, if (!pmd_present(pmdval)) { if (likely(!(flags & FOLL_MIGRATION))) return no_page_table(vma, flags); - VM_BUG_ON(thp_migration_supported() && - !is_pmd_migration_entry(pmdval)); - if (is_pmd_migration_entry(pmdval)) + entry = pmd_to_swp_entry(pmdval); + if (thp_migration_supported() && is_migration_entry(entry)) { pmd_migration_entry_wait(mm, pmd); - pmdval = READ_ONCE(*pmd); - /* - * MADV_DONTNEED may convert the pmd to null because - * mmap_sem is held in read mode - */ - if (pmd_none(pmdval)) + pmdval = READ_ONCE(*pmd); + /* + * MADV_DONTNEED may convert the pmd to null because + * mmap_sem is held in read mode + */ + if (pmd_none(pmdval)) + return no_page_table(vma, flags); + goto retry; + } + if (thp_swap_supported() && !non_swap_entry(entry)) return no_page_table(vma, flags); - goto retry; + VM_BUG_ON(1); } if (pmd_devmap(pmdval)) { ptl = pmd_lock(mm, pmd); @@ -276,11 +280,17 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, return no_page_table(vma, flags); } if (unlikely(!pmd_present(*pmd))) { + entry = pmd_to_swp_entry(*pmd); spin_unlock(ptl); if (likely(!(flags & FOLL_MIGRATION))) return no_page_table(vma, flags); - pmd_migration_entry_wait(mm, pmd); - goto retry_locked; + if (thp_migration_supported() && is_migration_entry(entry)) { + pmd_migration_entry_wait(mm, pmd); + goto retry_locked; + } + if (thp_swap_supported() && !non_swap_entry(entry)) + return no_page_table(vma, flags); + VM_BUG_ON(1); } if (unlikely(!pmd_trans_huge(*pmd))) { spin_unlock(ptl); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 154316bb34bb..4c2b1f3be038 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2077,7 +2077,7 @@ static inline int pmd_move_must_withdraw(spinlock_t *new_pmd_ptl, static pmd_t move_soft_dirty_pmd(pmd_t pmd) { #ifdef CONFIG_MEM_SOFT_DIRTY - if (unlikely(is_pmd_migration_entry(pmd))) + if (unlikely(is_swap_pmd(pmd))) pmd = pmd_swp_mksoft_dirty(pmd); else if (pmd_present(pmd)) pmd = pmd_mksoft_dirty(pmd); @@ -2163,11 +2163,11 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, preserve_write = prot_numa && pmd_write(*pmd); ret = 1; -#ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION +#if defined(CONFIG_ARCH_ENABLE_THP_MIGRATION) || defined(CONFIG_THP_SWAP) if (is_swap_pmd(*pmd)) { swp_entry_t entry = pmd_to_swp_entry(*pmd); - VM_BUG_ON(!is_pmd_migration_entry(*pmd)); + VM_BUG_ON(!thp_swap_supported() && !is_migration_entry(entry)); if (is_write_migration_entry(entry)) { pmd_t newpmd; /* diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 9ac49ef17b4e..180d7c08f6cc 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -436,7 +436,7 @@ static int queue_pages_pmd(pmd_t *pmd, spinlock_t *ptl, unsigned long addr, struct queue_pages *qp = walk->private; unsigned long flags; - if (unlikely(is_pmd_migration_entry(*pmd))) { + if (unlikely(is_swap_pmd(*pmd))) { ret = 1; goto unlock; }