Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2253783ybz; Thu, 30 Apr 2020 13:44:04 -0700 (PDT) X-Google-Smtp-Source: APiQypLV5x+17ctboOvN8mWhnn0G0OautvHXbvgBSVDnw7+3/wBQEB5lgfMAsqWdsmluAgmtB6hT X-Received: by 2002:a17:907:210d:: with SMTP id qn13mr276351ejb.376.1588279444827; Thu, 30 Apr 2020 13:44:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588279444; cv=none; d=google.com; s=arc-20160816; b=jiMzBN8S9YI1gRawWVbDgGHbf6rHpiSwU+XTtx4P+RMw9dHjHqhSHvCNNm+8jZh46h HiQXEfSueUrHerfbhug2DoLJTuWbwuSY/VeAPVY6lPpD8pj1w8BjzqGi3HQ74N6cV4pi KUNyilLqoSizY8UwSrAuI5hc3nF0zhXtSQiims+WvAAnTYlTET9mJr40DHdWWPsAzDbM +uEcp5H4rm7uFKfpMsNvKRLIPguznyqYW+0Bpq9/2XdEmKRBkDKFwkGNbr2MgqvaM2zw OrpUKL3i+q4OaOtmCp5iBqyO4iKPKjHrMv/LRBWhrlA+O/AMgy/PYI/BKzL510PkPCFU wq1w== 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; bh=Pd/NXx67dlwECMpnGrCxUGHPrqS/g5XAj0O8BBHV2AA=; b=LVK7L61Ec/9r3wZ1qb0LV20bgRjCa4oLfWYnZ7PIDgcYkIyRY89mRH8I6sE7upTnaO yZhT2BlwMERGNUMtymcBBc2ydBNOrj1FB+HzGw3Ck6gGUti29rV5WnRH/s9lwCkcsVRp MBeboYd7NG6cXgU10WhmYr9tX4STcRSrGrpIJGyiRtR4pRFobGuwam3ybELJBr6einwh 1em446w466JMat49SwR6mEfmDXg/x1W4HK6IDcPSaN9ooFyKyj2FKnymE/RcsXXY6Hi3 T3MIu48hHDYjNwYtCON5YvgoiLpAZcMICJNAQ2s680r8IK78lIvXFD4xfJslpnbKEoYH yKRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a4si637211edf.478.2020.04.30.13.43.33; Thu, 30 Apr 2020 13:44:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727888AbgD3Ulj (ORCPT + 99 others); Thu, 30 Apr 2020 16:41:39 -0400 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:38284 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726784AbgD3Ulj (ORCPT ); Thu, 30 Apr 2020 16:41:39 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01422;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0Tx7vcUa_1588279287; Received: from localhost(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0Tx7vcUa_1588279287) by smtp.aliyun-inc.com(127.0.0.1); Fri, 01 May 2020 04:41:35 +0800 From: Yang Shi To: kirill.shutemov@linux.intel.com, hughd@google.com, aarcange@redhat.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v2 linux-next PATCH 2/2] mm: khugepaged: don't have to put being freed page back to lru Date: Fri, 1 May 2020 04:41:19 +0800 Message-Id: <1588279279-61908-2-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1588279279-61908-1-git-send-email-yang.shi@linux.alibaba.com> References: <1588279279-61908-1-git-send-email-yang.shi@linux.alibaba.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When khugepaged successfully isolated and copied data from old page to collapsed THP, the old page is about to be freed if its last mapcount is gone. So putting the page back to lru sounds not that productive in this case since the page might be isolated by vmscan but it can't be reclaimed by vmscan since it can't be unmapped by try_to_unmap() at all. Actually if khugepaged is the last user of this page so it can be freed directly. So, clearing active and unevictable flags, unlocking and dropping refcount from isolate instead of calling putback_lru_page(). Cc: Kirill A. Shutemov Cc: Hugh Dickins Cc: Andrea Arcangeli Signed-off-by: Yang Shi --- v2: Check mapcount and skip putback lru if the last mapcount is gone mm/khugepaged.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 0c8d30b..1fdd677 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -559,10 +559,18 @@ void __khugepaged_exit(struct mm_struct *mm) static void release_pte_page(struct page *page) { mod_node_page_state(page_pgdat(page), - NR_ISOLATED_ANON + page_is_file_lru(page), - -compound_nr(page)); - unlock_page(page); - putback_lru_page(page); + NR_ISOLATED_ANON + page_is_file_lru(page), -compound_nr(page)); + + if (total_mapcount(page)) { + unlock_page(page); + putback_lru_page(page); + } else { + ClearPageActive(page); + ClearPageUnevictable(page); + unlock_page(page); + /* Drop refcount from isolate */ + put_page(page); + } } static void release_pte_pages(pte_t *pte, pte_t *_pte, @@ -771,8 +779,6 @@ static void __collapse_huge_page_copy(pte_t *pte, struct page *page, } else { src_page = pte_page(pteval); copy_user_highpage(page, src_page, address, vma); - if (!PageCompound(src_page)) - release_pte_page(src_page); /* * ptl mostly unnecessary, but preempt has to * be disabled to update the per-cpu stats @@ -786,6 +792,8 @@ static void __collapse_huge_page_copy(pte_t *pte, struct page *page, pte_clear(vma->vm_mm, address, _pte); page_remove_rmap(src_page, false); spin_unlock(ptl); + if (!PageCompound(src_page)) + release_pte_page(src_page); free_page_and_swap_cache(src_page); } } -- 1.8.3.1