From patchwork Wed May 9 08:38:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10388689 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 5ACA960353 for ; Wed, 9 May 2018 08:40:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C3A228E81 for ; Wed, 9 May 2018 08:40:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 469B628EB2; Wed, 9 May 2018 08:40:12 +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 5921F28EA3 for ; Wed, 9 May 2018 08:40:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 396216B04AF; Wed, 9 May 2018 04:40:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 346AF6B04B1; Wed, 9 May 2018 04:40:07 -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 177706B04B2; Wed, 9 May 2018 04:40:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f72.google.com (mail-pg0-f72.google.com [74.125.83.72]) by kanga.kvack.org (Postfix) with ESMTP id C87096B04AF for ; Wed, 9 May 2018 04:40:06 -0400 (EDT) Received: by mail-pg0-f72.google.com with SMTP id f19-v6so19459161pgv.4 for ; Wed, 09 May 2018 01:40:06 -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=HWBhY/zwhz0Qfy3X4HdeCi7YEqSRFqvakCXGwSOpDhk=; b=TuU/wGxhPBoFE8rJ5l048Inxal8mwOf0WurcX5ur1Qr8Hc08cdThYIwHDsveLlybib L20ginAyfYC4SCs/rY2eQMTfkK/G8LE20ZAezDnnxeMG10TIJpvGy4sTr/6HKmcW8vPs VdLxhoHmcXeMXW5mU6sAvGJFxJbeZIy9oZjxOSalIRdb8LDCic38z0jz8ZxFBvKEatGX dKUo/0tSzJ6YyHh9fnNqLByPAPwZediP8Q3Nr+N1R1l8tuUQnbSuEnkRPxR7JWl0Zmlx WZtTYJPQSOqbjk8nq8vJjAcoR5xfwpPbnIRja/aJEcbmnwd7kJ8LzEAA5sLK3Du8vBJm UZqg== 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: ALQs6tBEdpgbdNTfCzebUsYRQo7lVwFQw7i9jXGHgiGNgc/wDMR5Fj3Y OzqpOm+9v2i5la39nROzXrnxuDxo7ommlmdiU0+j0qHWT/2d0JS0hhYyhI589jshMFpe+7J7rOE nCR9qEu1tz5h/QugKKhw/ymNeBowqz8TzOWHf9XyqnM16XasLPKXwvpDoZDovVeVPSA== X-Received: by 2002:a17:902:598d:: with SMTP id p13-v6mr44821476pli.191.1525855206514; Wed, 09 May 2018 01:40:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqD8yYbMh7gKtGFbq4mPhNeAcllyPLc6ZHTIMEDm9+sfx8RT9+6G96W9IYgDsdrIQp7VnYS X-Received: by 2002:a17:902:598d:: with SMTP id p13-v6mr44821434pli.191.1525855205703; Wed, 09 May 2018 01:40:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525855205; cv=none; d=google.com; s=arc-20160816; b=YW9ptlU8+haHlBiSNtGI2gXG+gI2w7i19oIVfAE3H5EwRm0p9Dw7xCoyXRBeA6SaUS afHoYFDE35I/5U3gcqgQnEHhXyTEI0bYm7piz/YXpn9FDYn2rindSVuKHz5gT7oQgroz 8sGHjXQwpMFUy9Gaf8xWBjP3vf11NU9kYrKkb2gdskocHJUCrZOMXL1nyXGxoGjeJgW7 TG35WwBivnz99UcBWNOJHNmHIpaylj9JgzZPpkByd+HoxcRUAO6U2d8R1yi0ec5XkofX 1qq5u8dMLYeLmblBw/JXUHQU9hIljUxFk76fQ9Dqloi0b3Rt+n9vW6hSA+lyhfbc1gTu mbEg== 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=HWBhY/zwhz0Qfy3X4HdeCi7YEqSRFqvakCXGwSOpDhk=; b=s7mcdit1ECC1JczSKTdXjw+gg9rSSBlTbqnXkl3aV85ng9I71fOpub8XbwBQ/A/TsQ +lW4Q4NGqxTTzjy31SIFZb7eCCaJzYYspe8YxH70codekxtGgOKLi1J9X4yVoi2m9VhY jQnAUGyNNJsE1kUJUIcIk4FMQX8juN3mw+nT56OUe58QZ3sKBlkPzNLmbGBPD5OTcLsh Z9bL/oSgcn0CVeTJMU0/vhIQvjIkFuL1PDhq7W+29F2IaqQtBcGQT6kKedUAWvZnyP7g AvYotSrzCMIB6SoT0pSNd67RpZn3XRSN0gkrWtz8A+O7sJP/7Ry0QyzDmdzarN3L5Gl8 XHuw== 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.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 May 2018 01:40:05 -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:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,381,1520924400"; d="scan'208";a="52769819" Received: from yhuang-gentoo.sh.intel.com ([10.239.193.148]) by fmsmga004.fm.intel.com with ESMTP; 09 May 2018 01:40:02 -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 18/21] mm, THP, swap: Support PMD swap mapping in mincore() Date: Wed, 9 May 2018 16:38:43 +0800 Message-Id: <20180509083846.14823-19-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 During mincore(), for PMD swap mapping, swap cache will be looked up. If the resulting page isn't compound page, the PMD swap mapping will be split and fallback to PTE swap mapping processing. 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 --- mm/mincore.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/mm/mincore.c b/mm/mincore.c index a66f2052c7b1..897dd2c187e8 100644 --- a/mm/mincore.c +++ b/mm/mincore.c @@ -48,7 +48,8 @@ static int mincore_hugetlb(pte_t *pte, unsigned long hmask, unsigned long addr, * and is up to date; i.e. that no page-in operation would be required * at this time if an application were to map and access this page. */ -static unsigned char mincore_page(struct address_space *mapping, pgoff_t pgoff) +static unsigned char mincore_page(struct address_space *mapping, pgoff_t pgoff, + bool *compound) { unsigned char present = 0; struct page *page; @@ -86,6 +87,8 @@ static unsigned char mincore_page(struct address_space *mapping, pgoff_t pgoff) #endif if (page) { present = PageUptodate(page); + if (compound) + *compound = PageCompound(page); put_page(page); } @@ -103,7 +106,8 @@ static int __mincore_unmapped_range(unsigned long addr, unsigned long end, pgoff = linear_page_index(vma, addr); for (i = 0; i < nr; i++, pgoff++) - vec[i] = mincore_page(vma->vm_file->f_mapping, pgoff); + vec[i] = mincore_page(vma->vm_file->f_mapping, + pgoff, NULL); } else { for (i = 0; i < nr; i++) vec[i] = 0; @@ -127,14 +131,36 @@ static int mincore_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, pte_t *ptep; unsigned char *vec = walk->private; int nr = (end - addr) >> PAGE_SHIFT; + swp_entry_t entry; ptl = pmd_trans_huge_lock(pmd, vma); if (ptl) { - memset(vec, 1, nr); + unsigned char val = 1; + bool compound; + + if (thp_swap_supported() && is_swap_pmd(*pmd)) { + entry = pmd_to_swp_entry(*pmd); + if (!non_swap_entry(entry)) { + val = mincore_page(swap_address_space(entry), + swp_offset(entry), + &compound); + /* + * The huge swap cluster has been + * split under us + */ + if (!compound) { + __split_huge_swap_pmd(vma, addr, pmd); + spin_unlock(ptl); + goto fallback; + } + } + } + memset(vec, val, nr); spin_unlock(ptl); goto out; } +fallback: if (pmd_trans_unstable(pmd)) { __mincore_unmapped_range(addr, end, vma, vec); goto out; @@ -150,8 +176,7 @@ static int mincore_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, else if (pte_present(pte)) *vec = 1; else { /* pte is a swap entry */ - swp_entry_t entry = pte_to_swp_entry(pte); - + entry = pte_to_swp_entry(pte); if (non_swap_entry(entry)) { /* * migration or hwpoison entries are always @@ -161,7 +186,7 @@ static int mincore_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, } else { #ifdef CONFIG_SWAP *vec = mincore_page(swap_address_space(entry), - swp_offset(entry)); + swp_offset(entry), NULL); #else WARN_ON(1); *vec = 1;