From patchwork Fri Dec 7 05:41:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10717471 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 A575A109C for ; Fri, 7 Dec 2018 05:42:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92E852EC81 for ; Fri, 7 Dec 2018 05:42:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86DD42EC8B; Fri, 7 Dec 2018 05:42:18 +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 0FDDB2EC81 for ; Fri, 7 Dec 2018 05:42:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E73A26B7EAF; Fri, 7 Dec 2018 00:42:14 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DA97C6B7EB1; Fri, 7 Dec 2018 00:42:14 -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 C24BE6B7EB2; Fri, 7 Dec 2018 00:42:14 -0500 (EST) 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 762566B7EAF for ; Fri, 7 Dec 2018 00:42:14 -0500 (EST) Received: by mail-pl1-f197.google.com with SMTP id a10so1935983plp.14 for ; Thu, 06 Dec 2018 21:42:14 -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=Pti8ArGartXwq5/L83lWAXsZibuXRAY7eW8UI7jAzkg=; b=IpNXycP7v2iQAnoNPZVHak5aFEBTYNDS+tmvcxyTctAtlH9r6Li4eCOie0q2NA9Ua+ w8dBoxzm5FgurfkoUQApAei5thyjVF5DnEsvuSYI7s2OWQ09nrr4xbfoE7ztm0Z7wscn uXd3UHI4ngLCqjpExeGjyk4HhoyysPSmVlk9xf8bdnfGmZLEVlwEYgAZxrGG9Q1hyLq8 lPE+8UpAVYsqtfVC4ybRxgL3praffcMVZxH/psnX9aOb4DcrJDXbNvX93NLeVGOEHcsw WYqLcaMK4uFjG02BduIzN1WPz7CpmfClyVfZHrKs8Xh0/9r6ms3fXcInaFv4AtLEaG1+ 3y+A== 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+aEWZes+yXx0JI8UOXip/E+9fC9JhR8mHcvDNkJNWCpkndAcvQsBN9 K/x3RVPUR3yHp8TlzqFr2YiYCMBu54ja2uYkejmtDsAbdOkxFlsrtML64+IfJGJPlKtqnUNvaM/ FC46SYDZ27irF3gdWxazXmi4U84J9QNsPqwW5n8P/+KrpIJdfCOURRLEDwpFpUfwQnw== X-Received: by 2002:a62:1e45:: with SMTP id e66mr949982pfe.152.1544161334148; Thu, 06 Dec 2018 21:42:14 -0800 (PST) X-Google-Smtp-Source: AFSGD/W4DX1sGB72wfMo/1eUAaheAT+/OWoUqUlxhtl332hCcEOVske8y5maoDCYfJm5v4DHXoB7 X-Received: by 2002:a62:1e45:: with SMTP id e66mr949947pfe.152.1544161333133; Thu, 06 Dec 2018 21:42:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544161333; cv=none; d=google.com; s=arc-20160816; b=n/whwPY3RjbgKk6+hdA9hkjvZ8jtZ6Pq237zndO/Kka8HW/ns2Hg6WRZFNIS1qK/1e 8Yz5mHmRGoWfISIA8vtd/NHqUPj3E5WhgPQdld0xtOQQtQSw411WCyyqH8gYyJcoi5CX tijZPX4mMk8tbk+PqNMmprZxrX6Jl46DtAKDFBN+NkVZcDWuzy6OSUprRXePLoMjfTEK IlJDcikHXG6tfZTUfseyzpl8f3o1v8V+/4HJBD0d99qDPQkPE6cIaydnTsGEcxNLQgOB SbeHSN8cdWubPjTlGQ+7+HxE32kzw4QOgrIf8whLf1LE/XAOceS6RZ5pTxoDlsNG/QaG 5ahA== 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=Pti8ArGartXwq5/L83lWAXsZibuXRAY7eW8UI7jAzkg=; b=gTqf2N058JOimy4fn7x8klZh+FeNFxX+TS6HwcSIKoGTJGgD7ynDw0nweDI7QBHuDZ jLTnmJyqP2sODnnEubOBYy7Kdd+IQ+A0SHZlYVdkeS6j7G8g9URHfTAP49sv8Ez589CX WMte3p4PtFPgbPZ0KKds/ZPiD7pe7goBA/7iqgqvx1nYg++5K3KFUnluMdQW7grRhZ02 w+dtqkfYpcTq66/SaRfTKYb3Io2Xi+wa5MPn4gchD/9fLLghpoHdzLHMbq7W5stoBg/Y ZoinI/N7PxpIBoy6QrLpCZdOtwOQHbfnIHuhXrskqurbjBGWXbZWOXtpmWY1xtOwuODE 0aWw== 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.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Dec 2018 21:42:13 -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:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,324,1539673200"; d="scan'208";a="105567323" Received: from yhuang-mobile.sh.intel.com ([10.239.196.133]) by fmsmga007.fm.intel.com with ESMTP; 06 Dec 2018 21:42:10 -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 16/21] swap: Free PMD swap mapping when zap_huge_pmd() Date: Fri, 7 Dec 2018 13:41:16 +0800 Message-Id: <20181207054122.27822-17-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 For a PMD swap mapping, zap_huge_pmd() will clear the PMD and call free_swap_and_cache() to decrease the swap reference count and maybe free or split the huge swap cluster and the THP in swap cache. 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/huge_memory.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 077d569da13e..5b2eb7871cd7 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2071,7 +2071,7 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, spin_unlock(ptl); if (is_huge_zero_pmd(orig_pmd)) tlb_remove_page_size(tlb, pmd_page(orig_pmd), HPAGE_PMD_SIZE); - } else if (is_huge_zero_pmd(orig_pmd)) { + } else if (pmd_present(orig_pmd) && is_huge_zero_pmd(orig_pmd)) { zap_deposited_table(tlb->mm, pmd); spin_unlock(ptl); tlb_remove_page_size(tlb, pmd_page(orig_pmd), HPAGE_PMD_SIZE); @@ -2084,17 +2084,27 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, page_remove_rmap(page, true); VM_BUG_ON_PAGE(page_mapcount(page) < 0, page); VM_BUG_ON_PAGE(!PageHead(page), page); - } else if (thp_migration_supported()) { - swp_entry_t entry; - - VM_BUG_ON(!is_pmd_migration_entry(orig_pmd)); - entry = pmd_to_swp_entry(orig_pmd); - page = pfn_to_page(swp_offset(entry)); + } else { + swp_entry_t entry = pmd_to_swp_entry(orig_pmd); + + if (thp_migration_supported() && + is_migration_entry(entry)) + page = pfn_to_page(swp_offset(entry)); + else if (IS_ENABLED(CONFIG_THP_SWAP) && + !non_swap_entry(entry)) + free_swap_and_cache(entry, HPAGE_PMD_NR); + else { + WARN_ONCE(1, +"Non present huge pmd without pmd migration or swap enabled!"); + goto unlock; + } flush_needed = 0; - } else - WARN_ONCE(1, "Non present huge pmd without pmd migration enabled!"); + } - if (PageAnon(page)) { + if (!page) { + zap_deposited_table(tlb->mm, pmd); + add_mm_counter(tlb->mm, MM_SWAPENTS, -HPAGE_PMD_NR); + } else if (PageAnon(page)) { zap_deposited_table(tlb->mm, pmd); add_mm_counter(tlb->mm, MM_ANONPAGES, -HPAGE_PMD_NR); } else { @@ -2102,7 +2112,7 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, zap_deposited_table(tlb->mm, pmd); add_mm_counter(tlb->mm, mm_counter_file(page), -HPAGE_PMD_NR); } - +unlock: spin_unlock(ptl); if (flush_needed) tlb_remove_page_size(tlb, page, HPAGE_PMD_SIZE);