From patchwork Tue Nov 20 08:54:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10690013 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 ADB8313AD for ; Tue, 20 Nov 2018 08:55:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E37B2991D for ; Tue, 20 Nov 2018 08:55:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90B2329A1B; Tue, 20 Nov 2018 08:55:56 +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 1872A2991D for ; Tue, 20 Nov 2018 08:55:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE6636B1F4A; Tue, 20 Nov 2018 03:55:43 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B23F76B1F52; Tue, 20 Nov 2018 03:55:43 -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 863646B1F53; Tue, 20 Nov 2018 03:55:43 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 3520A6B1F4A for ; Tue, 20 Nov 2018 03:55:43 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id e89so1060078pfb.17 for ; Tue, 20 Nov 2018 00:55:43 -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=uJhqIv9xRioYvD8lO5hp5GTopqjYCKDOsDnT+Xx235Q=; b=E+g4FjOaFK7u0jO/pgKj8lFmSe//YLOnl4LlAIgYq59qHHBeMEkBSXGTAcrdmhWCrE FyqZl8Q73XdysJFUULCvysl7PY5GDXmTBr396qh9szZmhiIeM6SUppDy/8uNKCh7ldfV Vof/eAjeflOzFc/OiDNp9EbbmH/niEJoadARDZ5o8/Q9wwY7+NRSz+JP9qFKdGiz6nXG Liv5QDpWo2hupnRoz6ne5eIbc9PAxGUW5NKyq/OjWjV/zgVD1VhmnRHbki7l4R+MIEYx 2/ajSU+0Ry3MkLcXZ+wlwHcU8ilRF6ILhcFDy3J5eNUB+MFTAj1nks0QqSfDIH4srEP8 vUrQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.88 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+aEWaEo9x0/djMkHbMOFJxLKnHqFTGQaK91xSGY9ENo2lr+jlEauBI Il9zpwufruXR4uGg4LV4ZrTMOxn7bURFl8vs2wCX1+k5+YK65SH1vXQ2JksqAMYjBdQn91oQ/Q1 ghPs6joDU8U3vfZJvt1DrgvsGI2+Sz9CB+2FLb9JD84Cjuh+mt6GjGAuuVLbGY6IVMQ== X-Received: by 2002:a17:902:aa0a:: with SMTP id be10mr1318699plb.266.1542704142887; Tue, 20 Nov 2018 00:55:42 -0800 (PST) X-Google-Smtp-Source: AFSGD/VTDVGIPFjSe8MzNMThrQgfRdiEYn8wOjN8JDHS30V6loutxLXRHw04IkBsGFa4h2AToGAq X-Received: by 2002:a17:902:aa0a:: with SMTP id be10mr1318645plb.266.1542704141821; Tue, 20 Nov 2018 00:55:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542704141; cv=none; d=google.com; s=arc-20160816; b=SQVRzsQesMJ24+XnZ+DmJT2jXkwT2PLmLeLdjrL/3iuJINl8n4rfcst3Su0+nYHcrw /o+Xpg51D+hFMQp4nZArDRjR2XQeydVMilVPMW7tu1DvMEX8zn5Eq1Zc94aZMbpk7iPU 3wtbbnC73zgj4qSmwv6VLFZ16kVShB0r/9kDDtibAzh9V8S0epekcQ+UNJVM/gNSMOG7 g59Jyrqe9o4DDW3fxD4wDQA55oPgS+vl4KZqBGr8G5xwKq3h/cHMrlJ1zrXtvCChQ5Cg HKkcA2R1djBuur8+cRoclSzq0E7euW+QxAqEHUwhiOwmGsLPRwWzCTO4WG2V/xOEGJDN bktA== 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=uJhqIv9xRioYvD8lO5hp5GTopqjYCKDOsDnT+Xx235Q=; b=puTGZchc0aBAQpO4CJlJoBBGX8ICIcyo0s34E58gAkgloKBtLvhsNK6EuKVOti4SUh dIl5zsrQmteq8mMPFXqpyDYqIbcTv7U9hg97RAVlUXp6LPB4pXDfovgQeFfpI+3oji6+ hz+dgAEJMTmER7YRUYep74lEMupLddn5SY992ZZXPpF4xybGSzJK77aoNx3FBWaVHsqO UCpSFSDRtQeuI6RCNz1tmTV0Xf0Ma5EPrRrc0hip4+Ej6GMw7iG/0sY2wd06fhrl5BeX iTpCpcDiO1N7E353dkNP8aoLI7XpwbYkkBRJQdhaOnU7Bdx2viNgHGtaUwTb1QCOe52b 5yyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga01.intel.com (mga01.intel.com. [192.55.52.88]) by mx.google.com with ESMTPS id r25si673627pfk.28.2018.11.20.00.55.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 00:55:41 -0800 (PST) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 192.55.52.88 as permitted sender) client-ip=192.55.52.88; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.88 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 fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2018 00:55:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,256,1539673200"; d="scan'208";a="106105904" Received: from yhuang-mobile.sh.intel.com ([10.239.197.245]) by fmsmga002.fm.intel.com with ESMTP; 20 Nov 2018 00:55:38 -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 -V7 RESEND 16/21] swap: Free PMD swap mapping when zap_huge_pmd() Date: Tue, 20 Nov 2018 16:54:44 +0800 Message-Id: <20181120085449.5542-17-ying.huang@intel.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20181120085449.5542-1-ying.huang@intel.com> References: <20181120085449.5542-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 2a49b2068902..c2b23dfb0d55 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2072,7 +2072,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); @@ -2085,17 +2085,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 { @@ -2103,7 +2113,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);