From patchwork Fri Jun 22 03:51:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10481169 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 8E6B860383 for ; Fri, 22 Jun 2018 03:56:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80CBC28F91 for ; Fri, 22 Jun 2018 03:56:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75A6B28F98; Fri, 22 Jun 2018 03:56:11 +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=unavailable 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 01EEF28F91 for ; Fri, 22 Jun 2018 03:56:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBC176B027E; Thu, 21 Jun 2018 23:55:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C44266B0280; Thu, 21 Jun 2018 23:55:57 -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 AE5DA6B0281; Thu, 21 Jun 2018 23:55:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f71.google.com (mail-pg0-f71.google.com [74.125.83.71]) by kanga.kvack.org (Postfix) with ESMTP id 62C4C6B027E for ; Thu, 21 Jun 2018 23:55:57 -0400 (EDT) Received: by mail-pg0-f71.google.com with SMTP id n3-v6so2106307pgp.21 for ; Thu, 21 Jun 2018 20:55:57 -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=jv0bXo/88j1GmtIcTWYUDzZ+BgpJykyIu9VHJ6oEk6M=; b=ASCik9ZXfsCgCpZKTKtYC7NJd3Ff7ebPsvCA7xE3AVtTuB0AUWd8A9VNO9OEww/LO0 znu7oHzJB9n8rR9Jcd5b81AeQGHwm0Fw57jVjAkHDDev5o1I7iElRJmPNUTcxdm1fPKE tA09pbTI4YE5q0hvte59X3Hrh+NVxHz3Xn+6wVyRooBPgrZawFs6WpjpsOyTFWckJMoR bQRJ3AWbsjJ9UZ+/4AKYZZknl7DYNaGzzdWcbtWPm5rz2PEomzYCJSx8Y26mTE6UD8bc HS17HIdGuTz4khnExeN3+czCiR1V2p0GzvCRx4dv7oJxosGh1OSTZJn6u+OwXkXB7bAk LLPg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 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: APt69E1h/w3Sb/q9UIjwOqaUWpEnO6tS/K1vf3gDBtqNWymyd0eazhMn Qm1gg/j48sm5X1XU4coCM8yoWVw6Uk89TSxTfgZvclCcVdYMtGzgehNAWH94x2AS1TGASsiuz// n9MbeIDJKn0sfgiupj2LK8WH2aHuzg03UsrAvXI2DMA6/axnPrupoXEj10cJ+A96jJQ== X-Received: by 2002:a17:902:8210:: with SMTP id x16-v6mr10579601pln.307.1529639757106; Thu, 21 Jun 2018 20:55:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJNGk+F7vmC2FBQMFrmd7FzjuqLN0kKJ/yZwwqsvxQVXP1XXUZ1kY6NlgAfJ7dINvH1jOqz X-Received: by 2002:a17:902:8210:: with SMTP id x16-v6mr10579582pln.307.1529639756502; Thu, 21 Jun 2018 20:55:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529639756; cv=none; d=google.com; s=arc-20160816; b=ZzZkgVdC3yMFLllAn1IhXh+CtyW3uKqDR69XQoAz2bOANP3vkNqr4tm95pOXD7edSO /Acrb2sD9NGuLcCYrwl7W+oyDeENlk51FFisBtWxRp7DbkSiTwCyMzIGsjpMRXQfu+MK D21+lf3RaEGRi+bbYVK9C0Ijm/sSicHlYPY1haAsCed5kkTI6macp027owIw9CGN1aZS inIbGKkscjVO6k24YMQhC/mq+imqyKvW/lM88NYc9vdpTbCSFUAju1QIdyRO8mKzw4nt fTcbJDvs7FoDxralOv0ACDWvyxbepfUPm2j+IedhIR1Vj/FQMSBwbhJyWm4UltFsTDQt LyGQ== 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=jv0bXo/88j1GmtIcTWYUDzZ+BgpJykyIu9VHJ6oEk6M=; b=v9aIZiH6I6uvHamnp26w3AotTloFEQH6proBtcppMhfmPvjlkfO1FOjEUgcBRVYYri +c7nZZLRYNDKSQ2u4QcBq8v1/3Zse5YQc+ghpaHxAiXa2GpwtYtu3WQVsGgzs2EtUipP AQCqJRWSAZs5BvrgBV9ZqjoezvTnYMRA+ybkjjJ2UErXRpKzZnDm96eB6Idd0v/qagEx 8yXelaqotL9mJOSh7/MAzZ1F5to83pxQrpFvfpxui+Cel7AlHjKcGY7pbzRLEwJQJKth of2oyAhMmCHr00Z0EC4hDe2qE5SZ83oaucTbu+JIUM+Hdk7QmQ3MP13RhZMxYa0/jVNz FHjA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id a12-v6si7022827plt.474.2018.06.21.20.55.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jun 2018 20:55:56 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.100 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 fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jun 2018 20:55:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,255,1526367600"; d="scan'208";a="65335182" Received: from wanpingl-mobl.ccr.corp.intel.com (HELO yhuang6-ux31a.ccr.corp.intel.com) ([10.254.212.200]) by fmsmga004.fm.intel.com with ESMTP; 21 Jun 2018 20:55:49 -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 -mm -v4 16/21] mm, THP, swap: Free PMD swap mapping when zap_huge_pmd() Date: Fri, 22 Jun 2018 11:51:46 +0800 Message-Id: <20180622035151.6676-17-ying.huang@intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180622035151.6676-1-ying.huang@intel.com> References: <20180622035151.6676-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 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 38c247a38f67..6b9ca1c14500 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2007,7 +2007,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); @@ -2020,17 +2020,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 { @@ -2038,7 +2048,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);