From patchwork Wed May 9 08:38:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10388683 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 E50B160353 for ; Wed, 9 May 2018 08:40:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9E2928E2E for ; Wed, 9 May 2018 08:40:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE93828E34; Wed, 9 May 2018 08:40:03 +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 5962628E35 for ; Wed, 9 May 2018 08:40:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 124BD6B04AB; Wed, 9 May 2018 04:40:01 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0FDC66B04AD; Wed, 9 May 2018 04:40:01 -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 016BD6B04AE; Wed, 9 May 2018 04:40:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f71.google.com (mail-pl0-f71.google.com [209.85.160.71]) by kanga.kvack.org (Postfix) with ESMTP id AF7116B04AB for ; Wed, 9 May 2018 04:40:00 -0400 (EDT) Received: by mail-pl0-f71.google.com with SMTP id t5-v6so3386781ply.13 for ; Wed, 09 May 2018 01:40:00 -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=bv9JdQvGk1rX6hm8ghLJINqBiyHwHcOJVUf8SjkxpQs=; b=h6C8DNwIT2DmZSRv10J8oW5T1XNLeev0W0mAzrxm58+FladMzfGk0w4GjHy10sPdLe 2RGGDI10Pg1UbkeAUc4caIdbfrpbDAOXoMspEjXB9lwTGlmn6VAPOHW9olko3O9hYzE3 nl+reHLtamEFETmdgEpbLT9NV0Ajxv+DknqcfME9bF0Fm5YvBAPcRlNijyyfpBdK1e9b g2u7SWuRTQ9bWwRd2A1dYcHEsJwCP3OMH4a+toaA5t1RVEYxY4hjAjwX9XReJ6qwj85C vz9CydVOsp3JbtRJJqCFtiJy82coXEFUfxUr3aa5G/NYsvqerQgMQl2s1JL+r/WwwOF8 rZog== 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: ALQs6tBu2WhNsTcGM7j6zmj9RHkqJnBU/+/p6+4ebGRAoM2V6EWRy3+O J2Dg96gzXhCS8FVPonP4gdJE5JPJ74jSKjvFymd5Or/bBEDIB4ngXP9/ej1fBozqlRt3X1LpiSc DD+0NvfS7Pdf54OxbqjkL1d43L6HQKscHoRA7KafxvKzCkdaR5ayZ/5hrsgo5TdNdwg== X-Received: by 2002:a63:7207:: with SMTP id n7-v6mr32494356pgc.195.1525855200403; Wed, 09 May 2018 01:40:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZptJbAIh/hnhXFa1UWXPohQDhRHjft9b10HXHaxpLOoD0Gjl+QKBD5iZHzQMEXLdP/Ochz2 X-Received: by 2002:a63:7207:: with SMTP id n7-v6mr32494334pgc.195.1525855199629; Wed, 09 May 2018 01:39:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525855199; cv=none; d=google.com; s=arc-20160816; b=Q9yH1IhT3c06Wy0g2EF39S6HlBmeH8OecaNqEV8ogq77zizVPh80KIIxv5qgSMUFRG omw+of17bfpLoARbI9oSV0UG0QkDt7IOxDfDvtNCP283TeQeqnatUCRtEjM5zkgzd+lu sLPfdjjC1L+K1REFM5xsJHmRu48nEPHMAkeLR94ztjJWSwwcN02dX8J0RzzVnLedCKOX egKSKs/7qmpw+abEiRNODlh77bmbi26UuJf5XarL+EeXYWgiuwzi8fNhSzC3VVeyGI4o 2bDjz935R1yFdcG2ebS8SiPeu6axe0i2s/vdgbmNeKUGf4VJ122tBG4Hn9oZy7T1zKnm fJ3g== 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=bv9JdQvGk1rX6hm8ghLJINqBiyHwHcOJVUf8SjkxpQs=; b=FkcuqkUTVn0NVu9Dek/SlvSf+WDjU6PqZ4gRIt6KQ/+2nn8cyYAdC4UvPIxL3g5cQu 0uYdFGbYG3ldNZyVRS2h0GUVhv1m13rhRr5CdEmZ/mbAvsGxovnhybiXLCawwPES4XJi NMauh7Zo5i7zpnEgLJPExXjdXGY7RkApKta6+1aAa1LkyQY2uKok/y/W80EQL1Nc5ZEa ezSqsUkNXkdmAFIQiaNv0oSa0wvOTFQKXUg6RVbB+Hg8o3SmSyVIQIbR3VdRslMv6Oqh vNRMw99LI1MFraz7WjszuOQn1SKCzls6bIsnENkPb7owWnnUurqsYRROHuA3wi5iS3WZ FZzw== 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.39.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 May 2018 01:39:59 -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:39:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,381,1520924400"; d="scan'208";a="52769729" Received: from yhuang-gentoo.sh.intel.com ([10.239.193.148]) by fmsmga004.fm.intel.com with ESMTP; 09 May 2018 01:39:55 -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 16/21] mm, THP, swap: Free PMD swap mapping when zap_huge_pmd() Date: Wed, 9 May 2018 16:38:41 +0800 Message-Id: <20180509083846.14823-17-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 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 --- 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 6f3129c068bc..154316bb34bb 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2010,7 +2010,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); @@ -2023,17 +2023,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 (thp_swap_supported() && + !non_swap_entry(entry)) + free_swap_and_cache(entry, true); + 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 { @@ -2041,7 +2051,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_FILEPAGES, -HPAGE_PMD_NR); } - +unlock: spin_unlock(ptl); if (flush_needed) tlb_remove_page_size(tlb, page, HPAGE_PMD_SIZE);