From patchwork Wed May 23 08:26:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 10420633 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 B570C60224 for ; Wed, 23 May 2018 08:27:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7B9928E40 for ; Wed, 23 May 2018 08:27:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C98F28E3F; Wed, 23 May 2018 08:27:48 +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 E019928E40 for ; Wed, 23 May 2018 08:27:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EED06B0007; Wed, 23 May 2018 04:27:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8A0AE6B0284; Wed, 23 May 2018 04:27:46 -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 7B6966B0285; Wed, 23 May 2018 04:27:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 3B7DA6B0007 for ; Wed, 23 May 2018 04:27:46 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id x2-v6so13868838plv.0 for ; Wed, 23 May 2018 01:27:46 -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=I4NBIMzCR4zHSnnMZIt5yRkwNtBRdupLTuzUTZzNFrA=; b=oHrVmWSuwbN1Z4qnPsh+Yx86+5crnw+O0XfmOGMFyh/g9clraaaQXmW2oyeicDh6ED f32DDucb+UPj+uVTYottiRYc3gga80l8lae1vhmOSaNhtb5VQUzcjc2KN/gBywWAXwEC 9roN7oQr+F5yToDQi67//D7fgG9LYGGDtiaMIP1MdyBSIu3wdvqAV/7hkNzfFlTW96NH ds1nvYlqygsE+cL1vGzqGFFE0Et4IO8jjZOQ0LVKpNZUeDw4UdDCIbexYdlB8Kh0P0xT UzRg96XZPWtNAei1qvYT0ieUL159u/BRXUCNB1wn6Zd9T7FpQWYLfl9c/8qr3tNS+kq4 6nxQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.20 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: ALKqPwfN3uV1PER5hX2qRKtWNauQX7cd5lVQSLw0lf8nQVXbkRePpax+ UhqA9BidhqyQHoxnUOuiA2wOooj1jPPK2nOeAeIYAfdj5NCQGJu8fgiFK8p0chMI22UNDJLXvwt szm0/dBhlwEUEfg+0ThdjrAdvs8dnlcrNJGpT1A9Lbn15fJEGpDhQIJFQJrAmV5cATA== X-Received: by 2002:a63:a312:: with SMTP id s18-v6mr1532111pge.187.1527064065908; Wed, 23 May 2018 01:27:45 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqr5qG61mbUXRaaRoUkYXG9prNwYbg/RWHfufWUqQQPoSC/SB/+bLnCSRk7IgINWS/1tuGb X-Received: by 2002:a63:a312:: with SMTP id s18-v6mr1532073pge.187.1527064065172; Wed, 23 May 2018 01:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527064065; cv=none; d=google.com; s=arc-20160816; b=wzB4BVnawOrK+hpDnuguI8MA6FUdpnI/AsvQtuF7j6nn41+6dNwsngjCAXXViz6zKm jXY0Q3l1XwKLPEfJibkL6NSWHsrflu8kYvtEYp06cQE06ry6JXyFwrDHYFI1IlQPkfda rOZ8ELLq/jGSKHK8jQoi41TXb9uDBHffQ56nLzkzLNbjheCi6Ol7gioPGta0UFLV6r6B CNOViGvBH3mBz9LzUlSIPSDuDYV1cuzS32ozK9rMC1t2JTeIZvFJb74kGMnlpPM5ssvx L2kD1SUZH7i3FzzfY/6mdi/YDrnPx4fNMRhou0r/oaPu6teom9+IeHvwPf4vClHtCX6+ 7WQg== 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=I4NBIMzCR4zHSnnMZIt5yRkwNtBRdupLTuzUTZzNFrA=; b=wg/PWaD7xxX54+cozTUy8Ox+rDapZ7v7Eg3QxWgRDtCIP97Dokix2+eJdyCfcoFRgG WpKqcCvBkYgH64rblFqeCFw99eRtPFyFQrULDwMO7DTR1zEBK9ALXtbLYw4uSerahD68 ZUzHc/HddAtcwHNyM4z0kcWngMLYRRlzYsT+Zm3r+ZS4o5pFCBOHnzIgBpak0zLX3zsp 6ZXr4OkBWKSWJpAr5/qd8dtpCTcXwqbZ6x5KO5BKCpZsMuk2IQQYDPP779/Sfvgcwc8Q 4t5wByH3b96BS1McCMXL0mo7IayUpK9jE02MJG92ZI8TG9UOBbF5RmyuHs15WH38hIwl 5xkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga02.intel.com (mga02.intel.com. [134.134.136.20]) by mx.google.com with ESMTPS id z6-v6si712662pgr.4.2018.05.23.01.27.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 01:27:45 -0700 (PDT) Received-SPF: pass (google.com: domain of ying.huang@intel.com designates 134.134.136.20 as permitted sender) client-ip=134.134.136.20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ying.huang@intel.com designates 134.134.136.20 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 orsmga101.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> 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 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;