From patchwork Wed May 23 08:26:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10420619 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 7F96C60327 for ; Wed, 23 May 2018 08:27:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CC1028E3F for ; Wed, 23 May 2018 08:27:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60E7028E54; Wed, 23 May 2018 08:27:28 +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 F22B528E3F for ; Wed, 23 May 2018 08:27:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 178696B0272; Wed, 23 May 2018 04:27:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1513B6B0273; Wed, 23 May 2018 04:27:19 -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 E9BF56B0274; Wed, 23 May 2018 04:27:18 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f199.google.com (mail-pf0-f199.google.com [209.85.192.199]) by kanga.kvack.org (Postfix) with ESMTP id 978056B0272 for ; Wed, 23 May 2018 04:27:18 -0400 (EDT) Received: by mail-pf0-f199.google.com with SMTP id p189-v6so12807161pfp.2 for ; Wed, 23 May 2018 01:27:18 -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=xl8TmbcNdPvAJxMtkZII7M3vTWYgGCvFlTrsDqOKsqU=; b=bA8o2yByYSF21m8r4ylXJIPTaMeh+BaLrPsrlDflNiQk2goEQOA+WwG0CEabNI2b3i ys6BdiOu4AZaQ/erbYJSnUMJZ1MlRD9OLc0ovC7Z7wWOLGfarO0q2O3a5BVhHkrvFd2L WoWpJ0V/zODRFwTwN0Wag/cjC95AqR9F50uavqoWpoXIJ6m8LmsNUtJ72HxSF85xCFgb IcFbi6KPBKkL4xiH+ePhl1p1/FK3SUiz72aAlt20bDgtBj2hI5eHqbLl3iVC2aU7yDVC HC9L6ml8BdrMXKqvxbjPoCoeGbmj0ase+6BWY963OzINdTRf1e1SnYUTUGKiA2CLhtox omTw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.151 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: ALKqPwdKGEsa10kp4bUyQDaSgutZPt2KH0jbOZFIy8u2l7GEOsdy3LNg W+99xmx6MGbrgahrAiYaBl+qCx3arETb7fx4bmsuyUkZwQSMe2gybBrcUaiC3cbT+DELV9FRj8P AWeg74tazpNMTZRLFPZU1+d8kp+NA3MOX2h+uOGI5HS8aWF/TdfI3vw9cldmuwCFziw== X-Received: by 2002:a17:902:341:: with SMTP id 59-v6mr2006583pld.324.1527064038327; Wed, 23 May 2018 01:27:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoxgaSV+eQURrRVS2n/B6UpPG28xvvhZNzuSFGlMocCvSy9vR7/ZcildrwV4ge78EbtrLus X-Received: by 2002:a17:902:341:: with SMTP id 59-v6mr2006557pld.324.1527064037726; Wed, 23 May 2018 01:27:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527064037; cv=none; d=google.com; s=arc-20160816; b=BO6s4pvKv56oMEA4XKp3Wk1TUKg62xXDcBUevN0vZ7nBUr0KwbZeCLEK37eL8Zbvup ewwcFiH+eQ1JT7SiXvav0xfs9nV48QQ0qsO7RfevoYj9PUXBbinUMXIEo3x08W3ZH9da Ha7XxheRy+/mYRkiEy4D6gfHqARDMJkytskOk2xkT0cGP1QvIur91SixdSdnQvS+lRAo Z0oJEj+VspjUfu4OFgcTtIKclJ8NRAgLK9EQYKDTsRAn5iu5ceh/uhH3oO0W5x6ID/5E utLJhKbth1j5jXQ56PnuFOHi7tDYGo0hXdanc/VebTWNv/gpx0FuFZGY+OjbMfATirPA PidA== 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=xl8TmbcNdPvAJxMtkZII7M3vTWYgGCvFlTrsDqOKsqU=; b=e0bM0eHxGzR4jn/Y4py/oFZCIi/h1gCjVukO4Al8OVdmAFRHzUmn7jtIbgMI24vhOk ePJY2X54/HvUKmzTmAXoj04TDMAO48lUmikK2wAjuRIgF8M0lzdhpMaNAtPZFWdUKRS8 XmJPKofnwE+Tjuxk/IISVAsr+8fot6w359cAzpabDH46rcsVhe1luSKozCLLbW5+0kfM ps8Aava2LCK/eOak7kpv3rEwEJSFTGbC/LgRKNYdmMCt4kR/+yD4XA2MDas6i1WxPvIN iUQ73Z4y9Ilc2o7LuRxc9IRKK7upoDGBMOog+wFdieDi3qEkUSu//mI75Xeywb1ISo7d MrSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga17.intel.com (mga17.intel.com. [192.55.52.151]) by mx.google.com with ESMTPS id d2-v6si18038840plh.387.2018.05.23.01.27.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 01:27:17 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 192.55.52.151 as permitted sender) client-ip=192.55.52.151; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 192.55.52.151 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 fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 May 2018 01:27:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,432,1520924400"; d="scan'208";a="57726233" Received: from yhuang6-ux31a.sh.intel.com ([10.239.197.97]) by fmsmga001.fm.intel.com with ESMTP; 23 May 2018 01:27:14 -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 -V3 16/21] mm, THP, swap: Free PMD swap mapping when zap_huge_pmd() Date: Wed, 23 May 2018 16:26:20 +0800 Message-Id: <20180523082625.6897-17-ying.huang@intel.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180523082625.6897-1-ying.huang@intel.com> References: <20180523082625.6897-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 01fdd59fe6d4..e057b966ea68 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);