Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp557471imm; Wed, 23 May 2018 01:28:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZps+FKR2Ixug/C/Bb+EPVykTuFI4KBZQunVJzBsq/QtHPNkgf73AzXmaZMMHMsnEYZIQ99f X-Received: by 2002:a17:902:2f84:: with SMTP id t4-v6mr2073722plb.24.1527064113858; Wed, 23 May 2018 01:28:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527064113; cv=none; d=google.com; s=arc-20160816; b=AF7W1nvwYI+4pGlIAzfUb5lKyV7OXHxtKSiGa4x0MgKnQBIRYkLtlhH4TSr7h48dHO wo/+dSlyu/yaphcsSlSJeqqUqWAq/ioyftHb12g0QaIZYPIXe697X+FCoOC37DUa3HPk z9ij2WNYGXyQ3reTn7Y8+mvO1/tQoGuwkVPt6CP+p83ftHrHe9D8v5Mf9W0BMhijRLvE HVIbrcM/KHCxgAk/hjq6EY6smA7lYaI2x6jV7gAegnE2orABcPejbDBAogPM0looJZNJ wsIj2Oe99lxt+wNK+ajmwiUDNIYwboR7lb++xuJMdqbBBd4YwZP7Jv4RHXnu3F0xtDbT aEcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=I4NBIMzCR4zHSnnMZIt5yRkwNtBRdupLTuzUTZzNFrA=; b=tvWY/K5tIrU6U5JbUAEW9pRx14bt3is+MEt4EHowCpR8e8Y23O+HlMGcWRo2eP8fD1 xAufxWGZC3V+JCfeAXURWU8aDfL0dEWzcBf+QaZwbjmZwZNctQK03wDZtHns6NTL1B89 lVWO2rufY5mQFssDGSHf7mEUjW+neoW0R41ma7NkvXNARlKFZO9C4+f0kIcyxq2Iv9bI Hdx7YR3SDgjtlrYU7YkRGzr9zEyHG2R3hWg6oJNCTWcWAk12+FfchrcukisUnFIk1xQU nzqpnfyGQoFnsIZGkrdcCX3UpiBWwaDyDsa39b5IQYDPXO/K44OTJ/RFeMqQeNjN1X2g ZCZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d9-v6si18699038pls.334.2018.05.23.01.28.19; Wed, 23 May 2018 01:28:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754461AbeEWI14 (ORCPT + 99 others); Wed, 23 May 2018 04:27:56 -0400 Received: from mga18.intel.com ([134.134.136.126]:12144 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754629AbeEWI1p (ORCPT ); Wed, 23 May 2018 04:27:45 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 May 2018 01:27:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,432,1520924400"; d="scan'208";a="57726367" Received: from yhuang6-ux31a.sh.intel.com ([10.239.197.97]) by fmsmga001.fm.intel.com with ESMTP; 23 May 2018 01:27:38 -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 21/21] mm, THP: Avoid to split THP when reclaim MADV_FREE THP Date: Wed, 23 May 2018 16:26:25 +0800 Message-Id: <20180523082625.6897-22-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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Huang Ying Previously, to reclaim MADV_FREE THP, the THP will be split firstly, then reclaim each sub-pages. This wastes cycles to split THP and unmap and free each sub-pages, and split THP even if it has been written since MADV_FREE. We have to do this because MADV_FREE THP reclaiming shares same try_to_unmap() calling with swap, while swap needs to split the PMD page mapping at that time. Now swap can process PMD mapping, this makes it easy to avoid to split THP when MADV_FREE THP is reclaimed. 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 | 41 ++++++++++++++++++++++++++++++++--------- mm/vmscan.c | 3 ++- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 88984e95b9b2..2d68a8f65531 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1671,6 +1671,15 @@ int do_huge_pmd_numa_page(struct vm_fault *vmf, pmd_t pmd) return 0; } +static inline void zap_deposited_table(struct mm_struct *mm, pmd_t *pmd) +{ + pgtable_t pgtable; + + pgtable = pgtable_trans_huge_withdraw(mm, pmd); + pte_free(mm, pgtable); + mm_dec_nr_ptes(mm); +} + #ifdef CONFIG_THP_SWAP void __split_huge_swap_pmd(struct vm_area_struct *vma, unsigned long haddr, @@ -1885,6 +1894,28 @@ bool set_pmd_swap_entry(struct page_vma_mapped_walk *pvmw, struct page *page, pmd_t swp_pmd; swp_entry_t entry = { .val = page_private(page) }; + if (unlikely(PageSwapBacked(page) != PageSwapCache(page))) { + WARN_ON_ONCE(1); + return false; + } + + /* MADV_FREE page check */ + if (!PageSwapBacked(page)) { + if (!PageDirty(page)) { + zap_deposited_table(mm, pvmw->pmd); + add_mm_counter(mm, MM_ANONPAGES, -HPAGE_PMD_NR); + goto out_remove_rmap; + } + + /* + * If the page was redirtied, it cannot be + * discarded. Remap the page to page table. + */ + set_pmd_at(mm, address, pvmw->pmd, pmdval); + SetPageSwapBacked(page); + return false; + } + if (swap_duplicate(&entry, true) < 0) { set_pmd_at(mm, address, pvmw->pmd, pmdval); return false; @@ -1902,21 +1933,13 @@ bool set_pmd_swap_entry(struct page_vma_mapped_walk *pvmw, struct page *page, swp_pmd = pmd_swp_mksoft_dirty(swp_pmd); set_pmd_at(mm, address, pvmw->pmd, swp_pmd); +out_remove_rmap: page_remove_rmap(page, true); put_page(page); return true; } #endif -static inline void zap_deposited_table(struct mm_struct *mm, pmd_t *pmd) -{ - pgtable_t pgtable; - - pgtable = pgtable_trans_huge_withdraw(mm, pmd); - pte_free(mm, pgtable); - mm_dec_nr_ptes(mm); -} - /* * Return true if we do MADV_FREE successfully on entire pmd page. * Otherwise, return false. diff --git a/mm/vmscan.c b/mm/vmscan.c index 9f46047d4dee..1b89552523f6 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1137,7 +1137,8 @@ static unsigned long shrink_page_list(struct list_head *page_list, /* Adding to swap updated mapping */ mapping = page_mapping(page); } - } else if (unlikely(PageTransHuge(page))) { + } else if (unlikely(PageTransHuge(page)) && + (!thp_swap_supported() || !PageAnon(page))) { /* Split file THP */ if (split_huge_page_to_list(page, page_list)) goto keep_locked; -- 2.16.1