From patchwork Wed Oct 10 07:19:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10634127 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 AA3D569B1 for ; Wed, 10 Oct 2018 07:28:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C431294F6 for ; Wed, 10 Oct 2018 07:28:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90ADA296AF; Wed, 10 Oct 2018 07:28:06 +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 04E81294F6 for ; Wed, 10 Oct 2018 07:28:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 87AE86B027A; Wed, 10 Oct 2018 03:27:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4CAD16B0279; Wed, 10 Oct 2018 03:27:44 -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 0EEFA6B027E; Wed, 10 Oct 2018 03:27:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id 96E066B0279 for ; Wed, 10 Oct 2018 03:27:43 -0400 (EDT) Received: by mail-pl1-f197.google.com with SMTP id y7-v6so3176307plp.16 for ; Wed, 10 Oct 2018 00:27:43 -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=7axeIJc6D6MV3ztEZZQeXxD/d0S8djj9mhUCanNCdp4=; b=Oqh2jri44DoCYp4IWDyma4J50vGegcrjYUFn4eIOSSAreY9iqO66MqtuBFuFP6nMF1 AyJ/tRjqO2zx7TRqt9AdygmZBbq4BaCcZK8rmeXoDcXIHf0plhDDte8T5949HPPWSCcR X8U4HlM8yB74Hctd6Vxw2qVQDNj9Ayapoj5+ckWHm9jUauzWF5qTkV/BWhFBkte6btAl yQuVFGsRTVbWaAEp71lx7soGyLSUg9YtAeBk4o8F580VUtRgvrU3g1CTBszh+cPi2TUm /2XWqdBhJw3aVoglktJT2gmH9pg2kgu/x9lqXgbKH9C4qvTshGjADgLkdgTllCP0XUOr pyww== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: ABuFfogQh/poijSc9dQXklBkbUwKW/4+QmoCMMIL25I5Dv14oaOQoImP K6anky83I5N1eUsC1FFXzV6jLrhSy1dMfOmBLWrLqYKDBpub7aNYoK1gXNBQ/+Agvr4ls5j9PM4 SM4dF/Tvpg4P3legN+P0kprMZLl96ty2qYCz/LCl6jju24EmvcB67SCx4PsjWVCM5YQ== X-Received: by 2002:a62:4151:: with SMTP id o78-v6mr33808912pfa.66.1539156463304; Wed, 10 Oct 2018 00:27:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV63TEL4EUc5DuvrfAFkxcSEaOi3MhLK9dcaztU79lGAorE8LKeEDxKU41/kT1eAm9MqNMUJm X-Received: by 2002:a62:4151:: with SMTP id o78-v6mr33808862pfa.66.1539156462558; Wed, 10 Oct 2018 00:27:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539156462; cv=none; d=google.com; s=arc-20160816; b=vXv073DwzQOZX66NLsD1qeit6BTIXgjTTgL2/xurZJLgLM3DsZWFFLr6PQOI/4m4OU KjLDe0jnGX2J+gz+XBZjBkaDJLIpaQZbw8uUfstCy3SV6vVK87jILjFA+DmgRxzbSoeC Y30rwNYz+E2f0YVCEdTnI27nT1MiNdFM/y45ERrHRb1b6HguJyRz/subibFVdrAY1ZXn rlTUhiKdynVOuBtbI0tmgbWE8Wm0kwEIwhxb5Cb1I9mW/eGZbD/t5fRrkpLLyaExQeg5 gepsIrtUbekzKjK/QgdYqzsTvce3HCv162TG0/bhssaikiVZz9XS7Y0HwYKmPEfJKXVS 3W6A== 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=7axeIJc6D6MV3ztEZZQeXxD/d0S8djj9mhUCanNCdp4=; b=BVnPH00xah/vwFWQ61ygs2gvI0vOH5HXu816YDoza1v+7bjNfes6pjwIKaJCe5JaOu FBhD3vzn5vm4UMh3AR+TE/t/WBJ+wg1yz1j9DMuO/xonWnrMyJsJVoY9a4PEeR0PuHnA 0/1eLcMjbaMmF5JVZ1nFO/cRkzvJObCnkc6jaVf0PTFQPS4DwMAJMJKnEOvijND9OkI0 c9jN9tP5RrBif4Edo9oFhebCRCLuAxxcoxYEKJeqXIpkG9URUlzk129Fvvyk4nRdl6cN N0B1UpqJnfTJoSeUKW3i/BP5B3dE0Bko/LPgsQyBmcX+QOKw7pKTrYxvUYqXRD+6qyZm PS8w== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga06.intel.com (mga06.intel.com. [134.134.136.31]) by mx.google.com with ESMTPS id u4-v6si2721941pgi.554.2018.10.10.00.27.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Oct 2018 00:27:42 -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; 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 fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Oct 2018 00:27:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,363,1534834800"; d="scan'208";a="93870240" Received: from yhuang-mobile.sh.intel.com ([10.239.198.87]) by fmsmga002.fm.intel.com with ESMTP; 10 Oct 2018 00:19:45 -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 , Daniel Jordan Subject: [PATCH -V6 18/21] swap: Support PMD swap mapping in mincore() Date: Wed, 10 Oct 2018 15:19:21 +0800 Message-Id: <20181010071924.18767-19-ying.huang@intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181010071924.18767-1-ying.huang@intel.com> References: <20181010071924.18767-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;