From patchwork Wed May 23 08:26:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10420627 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 B4AE960224 for ; Wed, 23 May 2018 08:27:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5DED28E3F for ; Wed, 23 May 2018 08:27:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A99F28E54; Wed, 23 May 2018 08:27:37 +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 E120428E3F for ; Wed, 23 May 2018 08:27:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D84376B027A; Wed, 23 May 2018 04:27:34 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D355E6B027B; Wed, 23 May 2018 04:27:34 -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 B3A7F6B027D; Wed, 23 May 2018 04:27:34 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f71.google.com (mail-pl0-f71.google.com [209.85.160.71]) by kanga.kvack.org (Postfix) with ESMTP id 6C3976B027A for ; Wed, 23 May 2018 04:27:34 -0400 (EDT) Received: by mail-pl0-f71.google.com with SMTP id t5-v6so13860367ply.13 for ; Wed, 23 May 2018 01:27:34 -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=BBbdfD5Rfrf/O3PG0bZ4asLetoFDmwqOJJM/Pmm/xwo=; b=IGgFevhb2kVEXywYlswjAf1IUV0tHllB0p/G5Ynyd0eNvjOfGCsiKrV3lswQHJBbXG i7hcrInOl3W/Ns1oT8zC5IYuWa4r4fDrZDnRuoTs1fjGt8+D7ocvx8y9AK5NRzgQtfcH QO4rG9W87k/70SZw4JFdtqL4yfci6n5opIUWqC1vN7+NmWDUGDZIXVfcQ1SJk+Mc/Fqe Vd1yLcNfmVGdIIjaH6qTGqftTJo2gcsg0dcKBouZALF1VJy/JuGZLrXzPKCob8c6tjOP YKUti3i9SZbKn2hpZojt4SVIh011cdqmm3LywykmwuHRw/S+MmDm21BM3xVQGa0ADn2/ XX5w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: ALKqPwdMkOON1XNvnRtPXaYQ184Ho+XRlYkZNQjbNS0AcQx/tAaYN3M/ /4YpgjtH/gRyu1LiURb7wRbZh6NCuwEWA3L2BU1n/cWPWqXolcsq0SzUDHyN5juzcjE/efh4rgK OTTNz/CjVW89y8nF24yRDVaikGgL3zkFKZ96FNqSYsRi08w9dazp2Ejdv5XFSq7W/6w== X-Received: by 2002:a63:740c:: with SMTP id p12-v6mr1531616pgc.259.1527064054105; Wed, 23 May 2018 01:27:34 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr7z+68YkSV77AmECE6u2+fnIzeUDBv7AqfbP5J31JWNJjziv0lxgl3wDPRSwvuqKVmoo6q X-Received: by 2002:a63:740c:: with SMTP id p12-v6mr1531580pgc.259.1527064053265; Wed, 23 May 2018 01:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527064053; cv=none; d=google.com; s=arc-20160816; b=uSk73SgpnvooJLp535P18xn6lqlqe7452cE3MceCBg+ty0vjhxxQ5C0lMgq7UBGHHz Wzi0fUEg7CkJ0PwXgPpBGWVjqyDVueEItfw13gv5E2jEEaXLo55Lck/u5jZ8RdKEETAy P4E+iCrCIEEv9Aq6Or478PYSCrfpVO8C4Mkx9nxypwj8i+3PABr1IZjvK08jDrvEXz4P iJs519JL8ZQcx7oAGE8NUoWOhUhhWdv09hSnMsOya9BSH+ABOpIbsTZsXn/+RpD7wsMp +70zVGzjFmY2OiGb3bFYiqQqv6YCl+JUyusVXp3i2Q0tLj0cMHassW6aAC4vWtxDlUoc 685Q== 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=BBbdfD5Rfrf/O3PG0bZ4asLetoFDmwqOJJM/Pmm/xwo=; b=dCVnmnByS78g3UQacpp5SdQA7YWf92UyOolI85Igj5V1bJ3EO5ea/ImVWMfP5njkRW kmHmGjFjE6PZyQi7CjXkA7F/g/0YP774/XeAQSNNRBIRbBeC0qppBmiEcVLUjgWc3WOW LQ+p5HDb1DBAZsmrJHHWKRKRTSEZuto+Pjiop19GFBxhqnGTRTu6yDd2H+CPhQMG6ATo qbTosay7RS9x/rDdX4TEXZCfd0MOZD6hqHjQhzLvJZO+UrLXecQ3GpxL21Ndxpp5kquZ u1LxZk7yf1ZXXTwjNFgLuV7AIpbWoHMJWm75qfdSz04VqeK7/0undzPv0+k56OukaPaf 4Vbw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga05.intel.com (mga05.intel.com. [192.55.52.43]) by mx.google.com with ESMTPS id p7-v6si14354610pga.473.2018.05.23.01.27.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 01:27:33 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 192.55.52.43 as permitted sender) client-ip=192.55.52.43; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 May 2018 01:27:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,432,1520924400"; d="scan'208";a="57726315" Received: from yhuang6-ux31a.sh.intel.com ([10.239.197.97]) by fmsmga001.fm.intel.com with ESMTP; 23 May 2018 01:27:27 -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 -V3 19/21] mm, THP, swap: Support PMD swap mapping in common path Date: Wed, 23 May 2018 16:26:23 +0800 Message-Id: <20180523082625.6897-20-ying.huang@intel.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180523082625.6897-1-ying.huang@intel.com> References: <20180523082625.6897-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 597969db9e90..ddb6a2832f86 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -978,7 +978,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); } @@ -1309,7 +1309,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; @@ -1323,8 +1323,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 b70d7ba7cc13..84ba4ad8120d 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 e057b966ea68..e80d03c2412a 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2074,7 +2074,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); @@ -2160,11 +2160,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; }