From patchwork Fri Dec 7 05:41:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10717475 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 291C1109C for ; Fri, 7 Dec 2018 05:42:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 164102EC81 for ; Fri, 7 Dec 2018 05:42:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A9562EC8B; Fri, 7 Dec 2018 05:42:24 +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 687C02EC81 for ; Fri, 7 Dec 2018 05:42:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E23F76B7EB3; Fri, 7 Dec 2018 00:42:20 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D0BD56B7EB5; Fri, 7 Dec 2018 00:42:20 -0500 (EST) 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 BD56A6B7EB6; Fri, 7 Dec 2018 00:42:20 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 70DDA6B7EB3 for ; Fri, 7 Dec 2018 00:42:20 -0500 (EST) Received: by mail-pg1-f197.google.com with SMTP id m16so1851325pgd.0 for ; Thu, 06 Dec 2018 21:42:20 -0800 (PST) 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=PneHrFIvBxeR39UtwCqcyYL55SkL1f0iPo6rjUY3mOU=; b=ZQxuEDRMkcoh9v8dSFVn1yyO7CmQBu/PCb7EPmScAAuMeI4NCS2NX3UbR5YFp3mn38 G+XFhTa4uhbqK+dToM/3Q6EzORMl5YMEwpMqTw+lt4fYzR27UIsgcuywvJr2okDdSDT6 vXRCf/6B+w8GXJR7eQtlTxOOVY7+kR/9BUhVsFUUawM9u11vjjD7HJQyAjdvxtHq0ay7 Yeyv7EmOMQLRRbRpOrV1N++JxWQ3MW3Irk9dOGrgRX77VUVeLlGtEaNrmKyX8ItP3vM1 NTGXN8VXbnmIsywdbFwgdEYi25+Pu0+jaAr9YjKC9Pmq9nAt3uqw7PuAsH+PR5lcPjs1 24rA== 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: AA+aEWYyTmsTP00Xe2HLfGpKai8ate6oPCLvXizA+5iiNZOD/l15iv09 mW3TS5oqky6wAPAh/9c0PCPFxunE9Iw1nChH7zUJUsoQXR9AYWZxbIdYyKtdObBIaVm4wwaoPWt nSIk8NU7tuPfX/3mJMtHLRtnMCZNCXBconieIJdJ1AEvHK2FCAOT3YvarbKD0/bAG7A== X-Received: by 2002:a63:d301:: with SMTP id b1mr805336pgg.61.1544161340093; Thu, 06 Dec 2018 21:42:20 -0800 (PST) X-Google-Smtp-Source: AFSGD/WdOeQuwXe9PRAIcA0IAUf/93wMGbDBTUHRiaMdw2RCHuXBxaiGeLo67IXPb7PMMGqaGmfM X-Received: by 2002:a63:d301:: with SMTP id b1mr805301pgg.61.1544161338807; Thu, 06 Dec 2018 21:42:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544161338; cv=none; d=google.com; s=arc-20160816; b=bKpfontNgI+xC9xgrrxVbhLRmssah5aD5oV36XdCL+Me0KRK/+1HFUYVyIed8b/8jL 0Ra4K/sa1RK8ZQUqhKcfAPdommfUT12IX8SzlnFMuuATZWiOqv3iS1mEvm2UwcxD1/HA xxzrRaqcQnuKeA6NU0UaLlMU09SFMklqBHGl5F83L8Lp8eJXGZHwdIZnD5YlcPFkC+gj Bvnxine6GXKOvqxJmpdEnQWS5jVX9fSyV2vyMrSXZzsE+I8xqLIfHYbi+F04u4Y5IdJ9 PQnWyozLko1Hz+yaejuthJw+ecLC56HY1DdQvEB4czxVrJXkSEO3n+zVtTV8aGrUtGmh bWCw== 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; bh=PneHrFIvBxeR39UtwCqcyYL55SkL1f0iPo6rjUY3mOU=; b=z8v43K2i0kNGEIiRg0xsFFXh+u4PveDoEFiqss9IEcLmvpUwUcHs1haF6DP5G5e3MO cb+Rrp73P421FMA+OYhPuGEZVK3hZQkIlb0IcrkKwdyMKzdxoKiP+EkJ42zy6fbENtHi uQnE4xOSVWnArUPYDeGCDkWKr0C8xi63XtxDIwNMAaVNOHSqRo9DZNEQeqfe1kxK/JPC G+odJ4/rhdw6khGcg4Zgwx/29872x3jojhR+3i4yQnRM1UrLq5XCyWsWVKkZfUjEAl+y a9wImYlIBductsWwlPdFjbXSa0mzlutHWoE8zOP4km3s+t6iPY5HEUdZhVxGoctSoKmE 84dQ== 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 cf16si2126256plb.227.2018.12.06.21.42.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Dec 2018 21:42:18 -0800 (PST) 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 fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Dec 2018 21:42:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,324,1539673200"; d="scan'208";a="105567336" Received: from yhuang-mobile.sh.intel.com ([10.239.196.133]) by fmsmga007.fm.intel.com with ESMTP; 06 Dec 2018 21:42:15 -0800 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 , Daniel Jordan Subject: [PATCH -V8 18/21] swap: Support PMD swap mapping in mincore() Date: Fri, 7 Dec 2018 13:41:18 +0800 Message-Id: <20181207054122.27822-19-ying.huang@intel.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20181207054122.27822-1-ying.huang@intel.com> References: <20181207054122.27822-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 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 Cc: Daniel Jordan --- mm/mincore.c | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/mm/mincore.c b/mm/mincore.c index aa0e542569f9..1d861fac82ee 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 (IS_ENABLED(CONFIG_THP_SWAP) && 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;