From patchwork Wed Oct 10 07:19:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10634129 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 C445869B4 for ; Wed, 10 Oct 2018 07:28:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE31B29348 for ; Wed, 10 Oct 2018 07:28:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D23BD2946B; Wed, 10 Oct 2018 07:28:15 +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 4DD7429348 for ; Wed, 10 Oct 2018 07:28:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 44F276B0276; Wed, 10 Oct 2018 03:27:45 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B77E66B027C; Wed, 10 Oct 2018 03:27:44 -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 6247E6B0278; Wed, 10 Oct 2018 03:27:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by kanga.kvack.org (Postfix) with ESMTP id A84DB6B0277 for ; Wed, 10 Oct 2018 03:27:43 -0400 (EDT) Received: by mail-pg1-f200.google.com with SMTP id h9-v6so3012578pgs.11 for ; Wed, 10 Oct 2018 00:27:43 -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=LhEa0dJbAoeFYliKrYNKBTRV9eW8yVlc0nO1Ec3CVgs=; b=FQ8aTquK+wYQy5XTdD9thmEJK+UUy7vAsbtKX+NqW16VJAnspwo4exfKf4y/ZUwWYL VoPmWjaYy2pUA20h2NgiJzWgrSkEndH3pMntcxq4BXKmD68RMpEUoSFz0qBr7ajfLNHe 6226j7MMrjWbvefxx/0fTAdSYq3887so6tW8tXZhKBdVPV8lLw8KQgNBYxsxAdULkq/Y 1oG1VD+gK8mVGWGw8U/crTifXhRd+r+IOCgWL5EUIy48R6BEve3afdhTajzRSJp5Zp4Y Fk16FDAqom3IOOaHMlAHMd8iOjezIBlgieuhaxCNqpzhHLD5DDbgs8TkxdQqRylBlCAQ +snQ== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: ABuFfojTy4AjdqIVG2NnDI6Bmm6pdE4F+th/DpXDCnqF4Vm9bvH491CA mAR+wf2PVRjXCmkSj+OhIHm8Mxqss03uBCf0mx1M1YtUFXFf+SzFWPqKhAt7zl0cYlAtwQaVEjX NpXYNqgA2LDrye6jI4Hst8g1ToW8N+6Ad/k3LpSpberr73HhunkxW5nkF7SxWYbMMyQ== X-Received: by 2002:a63:2643:: with SMTP id m64-v6mr28401321pgm.435.1539156463367; Wed, 10 Oct 2018 00:27:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV63wq7FkFhCyNorI/oal3wLHImHhRE2ZmiUvEXLf1tFYQ7pVrfLl5VevrgbdfsveRbm5HL+r X-Received: by 2002:a63:2643:: with SMTP id m64-v6mr28401262pgm.435.1539156462261; Wed, 10 Oct 2018 00:27:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539156462; cv=none; d=google.com; s=arc-20160816; b=gflAJeLIB2Fu3HuP9qzBnKWmMGikJK/LS58GWS80DOgVruhZ/j8vM6/n6AY7myyJBQ MAguSjYxxkWG9scCJN9sFG2kS1qfdSB/S9dY50NJLMT7odiNzq2walKVTAlIjPYe2Ven g2DNAdJKO5P1vUZ0SuENZQ2kl9LAx5WJx/Vr/lTprGWP7dZXZ4r4f3+0XxxRO5DJoX1U SIcn4u5jOGzjssy9bkjXUdcXg+WgsTTwO+4DnQ0Rpd/8ilDY5l3EbjBmpbclhJUqaViR h0l156bORqjeieNktqHmE1uHXpZcSaMqJ5gSuCA1LMxWg9sJgTRrjUvXB1jSviW82aC9 8XfQ== 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=LhEa0dJbAoeFYliKrYNKBTRV9eW8yVlc0nO1Ec3CVgs=; b=TeMgCAsCOsxIsjMpzqaiWPpuQTq+UiiAe/8WOiuWIruc0+kmU2zOPzKiR/bNtM8jgq nPBXXoP8oYmFlR9cIqyr1hCSRI3VEt/GCThdlKkx3f/9QwFR1flDQI9VSU/Nn0cEp7xV O+qTisGg8YYLBp/3tFMzVX2Rlr9mVB21RDfBimzPqw0WhemSIxP50lJRNCgSEIkEQWnf MtTrry6s3ov4pvblrmf2rRwSoJvs7Z+f6uUfzdmXEQd1BYQE0Wtt9oqwGAj2SO0YzJpG 3xzYQs/Ycq8EQNFBOO7b2LNLQ9Pp2W2zqlF7/XS1sSxF2a1N6VWnpcRSP7G98hfwebo/ F6WQ== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga06.intel.com (mga06.intel.com. [134.134.136.31]) by mx.google.com with ESMTPS id n84-v6si21364295pfg.127.2018.10.10.00.27.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Oct 2018 00:27:42 -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; 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 orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Oct 2018 00:27:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,363,1534834800"; d="scan'208";a="93870236" Received: from yhuang-mobile.sh.intel.com ([10.239.198.87]) by fmsmga002.fm.intel.com with ESMTP; 10 Oct 2018 00:19:39 -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 -V6 16/21] swap: Free PMD swap mapping when zap_huge_pmd() Date: Wed, 10 Oct 2018 15:19:19 +0800 Message-Id: <20181010071924.18767-17-ying.huang@intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181010071924.18767-1-ying.huang@intel.com> References: <20181010071924.18767-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 74c8621619cb..b9c766683ee1 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2066,7 +2066,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); @@ -2079,17 +2079,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 { @@ -2097,7 +2107,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);