From patchwork Tue Sep 25 07:13:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10613531 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 A8D8113A4 for ; Tue, 25 Sep 2018 07:14:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9662329B17 for ; Tue, 25 Sep 2018 07:14:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88BEA29B1C; Tue, 25 Sep 2018 07:14:38 +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 EB5C529B12 for ; Tue, 25 Sep 2018 07:14:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07A438E0079; Tue, 25 Sep 2018 03:14:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EF3208E0072; Tue, 25 Sep 2018 03:14:22 -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 CFB458E007A; Tue, 25 Sep 2018 03:14:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id 85A718E0072 for ; Tue, 25 Sep 2018 03:14:22 -0400 (EDT) Received: by mail-pf1-f198.google.com with SMTP id z1-v6so2245082pfn.14 for ; Tue, 25 Sep 2018 00:14:22 -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=XmoJX+vXP1LKOFlSybL31F0ffOJIU8Y7oseMCNiHoTc=; b=IVhMSxUSw21a1pjoGcb49PtA+yMZwfZNbvbq1+IHuUig+ZPHsWaZNwJQ54PfLs7AHc 5osR6Ah66Yj/nlsozucMaxXvog9jZi5OdUYWIPeywHoL3+1Jq+zDXV0l8pEwZV9IXvj5 HvCv2Lqk8scnf8AoQ+y4/jzoDK9bf0taXIJcFrKMwr22tqYRdPpcx2oBCTY6JiHAEUfJ lJSmsWTpWYWMMyk7ksByvmVAGGRat0CSUOZCnD55gAadTXFvTLU/Vo9qvPO8xkxcujjX a2dmDOV9ebHPEU9XT7L10eYAagfn/16HVH54ilz2JHQ7rgnCXLR4t4d5gD90In/cgKUX Mmvw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.115 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: ABuFfojwQnW+i19kJoFZObprOlDS6pEME7qWrPxaS6HuH/4Lh792o3xn 6bgZCxAxlXQlYf9w6o9ox5G73NjKi/LI9vsQ3se08XvZ+oSTiRzDiUZiFVVkBYxeeDW20OLTdYi /Ymg0CFjsmM/4GWe+InP9hZ/awTjuT1zuVDmkesWIP2oGcBA4brq2LXjpFCzd9mfP8w== X-Received: by 2002:a17:902:4d46:: with SMTP id o6-v6mr2173249plh.59.1537859662243; Tue, 25 Sep 2018 00:14:22 -0700 (PDT) X-Google-Smtp-Source: ACcGV63pPYHxHSrE5DVpK9nem/+PIy4f76BHWsaH2Ku2aBZ+WuZhOmitVgW/RdjWpBFxSngd3Bnj X-Received: by 2002:a17:902:4d46:: with SMTP id o6-v6mr2173184plh.59.1537859661435; Tue, 25 Sep 2018 00:14:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537859661; cv=none; d=google.com; s=arc-20160816; b=n27+smVopVwUqSFA7pQGZ+V0MS1dVK/qCtiH+Z6fKf0AzFsi0pnkSCtNBtjwZDt4Jn 1Mc96Warh6yr+WjrhgBeym6EShzqz8ws2CxB+m1fHEkkaSdBuSiiRduoNnDST3GJ1bXf gzyX+TpZ0gCnIFPbVXXk2C12Vpcz1+NQv9VvtIZm23gJdDQ3+1dHvVphPUJ6+viAQ3fy NQkAmmpl0BMbOqQm0rRrJyTxGTvET1l6+ef1zNOVaQUtieO+1nUO11y/F85Fs1nYkhtV x1/ayuQqJGopd/WUpYE+i9tJZnCmDQhFGkhXtdR6Nkkaehql/Do47URCkt42sIGcnqoR 1n3Q== 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=XmoJX+vXP1LKOFlSybL31F0ffOJIU8Y7oseMCNiHoTc=; b=N3uEmwshLTCUxbf81EjxN46lQE/I95tpLO76B5T9CmyHKdIyg2br6/Czwvu/hIMmhg gZpKKoHa16d9sRiTtl9vaMp2bQhfSB9kZ4E1D0PMsD3ewQSeEYihlQQAbMi1elByEwiI 5UcZw63izzdeGHu5DV4YSfRwmegXMcsi4p/AgKKvCoCEewm+bPmrKhE2AqAF1SgfZP55 haefnhfXle7lCYFpuU8ZgHjeDLZeHRqinLDjYWK/rYAoeAfXFfa8UxWlJyBE/8p470+P VeL43HoAdkfftuaz+7vVcfvuQ3cDtnoNpTdiKGzgH9Sw0p+HBbslolaMuwuhw1xZhUp8 yyjA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga14.intel.com (mga14.intel.com. [192.55.52.115]) by mx.google.com with ESMTPS id a1-v6si1378544pgw.9.2018.09.25.00.14.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Sep 2018 00:14:21 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 192.55.52.115 as permitted sender) client-ip=192.55.52.115; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.115 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 fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2018 00:14:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,301,1534834800"; d="scan'208";a="89093660" Received: from yhuang-mobile.sh.intel.com ([10.239.198.87]) by fmsmga002.fm.intel.com with ESMTP; 25 Sep 2018 00:14:17 -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 RESEND 16/21] swap: Free PMD swap mapping when zap_huge_pmd() Date: Tue, 25 Sep 2018 15:13:43 +0800 Message-Id: <20180925071348.31458-17-ying.huang@intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180925071348.31458-1-ying.huang@intel.com> References: <20180925071348.31458-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 c569e5e8ee17..accbd54d0ed4 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2019,7 +2019,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); @@ -2032,17 +2032,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 { @@ -2050,7 +2060,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);