From patchwork Mon Sep 3 07:22:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10585585 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 4A49413AC for ; Mon, 3 Sep 2018 07:23:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32CCE291E4 for ; Mon, 3 Sep 2018 07:23:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2764E29203; Mon, 3 Sep 2018 07:23:32 +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 F0107291E4 for ; Mon, 3 Sep 2018 07:23:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CB1616B66C4; Mon, 3 Sep 2018 03:23:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C3B0D6B66C5; Mon, 3 Sep 2018 03:23:08 -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 B06366B66C6; Mon, 3 Sep 2018 03:23:08 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 6ACBE6B66C4 for ; Mon, 3 Sep 2018 03:23:08 -0400 (EDT) Received: by mail-pl1-f199.google.com with SMTP id a10-v6so10255112pls.23 for ; Mon, 03 Sep 2018 00:23:08 -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=bT5SC8EGqEOhgRJjdQnX8eMGPmoDA3XI4e3ERUDYS1k=; b=bcVJRycEsvRugj0J4AibGTXs/b6nZ3i0GkCxjamA8XzV/+GoAw7WCVmDtemT0VndfL 2zki0v8TBl0SLEI6O9glrMiKsXmXBwU8MaxsVzATp9PI1BFyumkcwlw7J2mYZN9x9c0L V2NvtzsxLyQZgAMmPdobv/nbPdMCwUsBoGtMOwGz6kIsNqiLxMdW3DloMlyFcAJP1ayx ve0uipCUZ4Ki2PtEIM4gbJtUVKXack5K5krhnwVwABCVZ7Qp8RSEcf7no5DV2worsAab Lud622XGI34A3qOZ0jx8ujt44UnF7ABDuKSEPvFhG2mUFWBRVne6+O4Hkfv5Y7+UH9sv VA8Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 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: APzg51CA7Kbi0xLsq/st2C19zzkr6I+ycQZLeucJIYBPZRyQhH/aI+Bt zLKAfYg6EAjWubUWlGFYDQrRn8yLiMNQGwrWYpVdEDrFV6I6OzgoK9/qm6WrDkvZ1ydSHz9m5hZ 5hP5SO5/TAZa7hM166GcerrWKM7n+pDCocshdyb6rNxDY7hotjcdm4I+BJgcZhj+hrw== X-Received: by 2002:a17:902:b68d:: with SMTP id c13-v6mr22386053pls.139.1535959388125; Mon, 03 Sep 2018 00:23:08 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbfGAE9pr6MBjYXrxNFWEZMtEtP58h7Jzl6zx50eFq4a292qd6qS4nHJf8NmI+8a8w1fpRm X-Received: by 2002:a17:902:b68d:: with SMTP id c13-v6mr22386024pls.139.1535959387496; Mon, 03 Sep 2018 00:23:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535959387; cv=none; d=google.com; s=arc-20160816; b=ymqDMmvoUXmFCyiDaH2o6CxzReaClI0fuvUY+YOVpI4IN+cyOQ+qy94o8a7YPT/t0E 7hwiuBORPe1eGXSPPfaZJ8HnLJf2312mX9zwgcaWlf/sYDBp9SztkZ9WdKEV+0XJJF7h cIT28WLahNzlCyZf0kCLgaNR+A12COsSgPx6dVaaV1JRP+wzwD3M2jFRn8PL5PRlQLx6 toDLx4Mjx/BVbpXbSuM1NR1zqf9DQ22roY+oM0Fe4CzkgGbsGzmalyIrmAFZG5TYNuLz kWflh+NLDjeWEXwE3ydgjweyrhOWnCuDfOeS06a2gv0RwCYJcpZeGqdChE1ChtCrlKlv ICEw== 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=bT5SC8EGqEOhgRJjdQnX8eMGPmoDA3XI4e3ERUDYS1k=; b=CzR31dzyychW+V9rVE5kAjtju1yujGkDoYKSnYr3xZv6z1fNoembR2MybkHYvUMEae vcmLeilfNABZBnm1As08bA+Cb7llK7aBSfdXYHULJlyvFUXLbO1YkJdTD5TiGj3wJFzh Jj/Lxw3Rq9WBPIMyePVU76zbLptaRn8wPUHlesDwVZ2mnwhaNPWV3yhPLagMVX4cd5iC Zqjgx7InfDj4rnx2jdO6o9LNONDhN7c3RGKYoXp4R/YOP6zEdExinK1nx0ZGtIXl7ZjR hY/P5J6qmGUX3202ns3Up8nyNKAZIUB3cpxqICUS0JF+lupzTgPOJstpfT9X3Q7ST8xl YYoQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id az1-v6si9327648plb.513.2018.09.03.00.23.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 00:23:07 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 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 orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Sep 2018 00:23:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,324,1531810800"; d="scan'208";a="70146989" Received: from yhuang-mobile.sh.intel.com ([10.239.196.86]) by orsmga008.jf.intel.com with ESMTP; 03 Sep 2018 00:23:04 -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 -V5 18/21] swap: Support PMD swap mapping in mincore() Date: Mon, 3 Sep 2018 15:22:11 +0800 Message-Id: <20180903072214.24602-19-ying.huang@intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180903072214.24602-1-ying.huang@intel.com> References: <20180903072214.24602-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;