From patchwork Sat Jun 11 08:47:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12878377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59031C43334 for ; Sat, 11 Jun 2022 08:47:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A22908D010E; Sat, 11 Jun 2022 04:47:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9AB8B8D0115; Sat, 11 Jun 2022 04:47:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69F028D010E; Sat, 11 Jun 2022 04:47:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 550508D0115 for ; Sat, 11 Jun 2022 04:47:36 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 328A92079B for ; Sat, 11 Jun 2022 08:47:36 +0000 (UTC) X-FDA: 79565326512.04.80609AB Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf17.hostedemail.com (Postfix) with ESMTP id 9289440058 for ; Sat, 11 Jun 2022 08:47:35 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LKrzC2SkqzjXRb; Sat, 11 Jun 2022 16:46:31 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 11 Jun 2022 16:47:31 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , Subject: [PATCH 7/7] mm/khugepaged: try to free transhuge swapcache when possible Date: Sat, 11 Jun 2022 16:47:31 +0800 Message-ID: <20220611084731.55155-8-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220611084731.55155-1-linmiaohe@huawei.com> References: <20220611084731.55155-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654937255; a=rsa-sha256; cv=none; b=zSOdhjwrbMrPe5EFXRuSMjgkze8vfFVZs0V4vl1f8c8RjCaV4RXuWkyOe8Vfck729s+JUl PSH16tj4EfGXMckbeVN1L8hNHQRsTMqWf1qH3vJ4Nu1tQf9xEwiFfHwwTx22Jb8kq79Mlr F8Q7VGl9UWq6UTMYQBvqrsAC3FskxQI= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654937255; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pK1aJ/tp0wV/o2k1uh33rMqUJUM6ubVFYAFBRs8M5lM=; b=T8R2ObYs/A/mxVepWT3mUHmGfZWrZLLz73cqXU8zqgJ7eXmQrQbJbBlvyA8qneeW6yoYzN 006ormNuRZAsMWQVuW+S6DPdq5DQ7T26MKNKMBrYG1BbBO2n/4qMjSl0zWz/ldA0sZqKDO wLcp6ibcg6RNX7l8eZBIXKN3c9hE6+s= X-Rspamd-Queue-Id: 9289440058 X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Stat-Signature: 8xzrin6wbt945pfup7t1dwm9t9siqr6t X-Rspamd-Server: rspam02 X-HE-Tag: 1654937255-252966 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: Transhuge swapcaches won't be freed in __collapse_huge_page_copy(). It's because release_pte_page() is not called for these pages and thus free_page_and_swap_cache can't grab the page lock. These pages won't be freed from swap cache even if we are the only user until next time reclaim. It shouldn't hurt indeed, but we could try to free these pages to save more memory for system. Signed-off-by: Miaohe Lin --- include/linux/swap.h | 5 +++++ mm/khugepaged.c | 1 + mm/swap.h | 5 ----- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 8672a7123ccd..ccb83b12b724 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -456,6 +456,7 @@ static inline unsigned long total_swapcache_pages(void) return global_node_page_state(NR_SWAPCACHE); } +extern void free_swap_cache(struct page *page); extern void free_page_and_swap_cache(struct page *); extern void free_pages_and_swap_cache(struct page **, int); /* linux/mm/swapfile.c */ @@ -540,6 +541,10 @@ static inline void put_swap_device(struct swap_info_struct *si) /* used to sanity check ptes in zap_pte_range when CONFIG_SWAP=0 */ #define free_swap_and_cache(e) is_pfn_swap_entry(e) +static inline void free_swap_cache(struct page *page) +{ +} + static inline int add_swap_count_continuation(swp_entry_t swp, gfp_t gfp_mask) { return 0; diff --git a/mm/khugepaged.c b/mm/khugepaged.c index ee0a719c8be9..52109ad13f78 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -756,6 +756,7 @@ static void __collapse_huge_page_copy(pte_t *pte, struct page *page, list_for_each_entry_safe(src_page, tmp, compound_pagelist, lru) { list_del(&src_page->lru); release_pte_page(src_page); + free_swap_cache(src_page); } } diff --git a/mm/swap.h b/mm/swap.h index 0193797b0c92..863f6086c916 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -41,7 +41,6 @@ void __delete_from_swap_cache(struct page *page, void delete_from_swap_cache(struct page *page); void clear_shadow_from_swap_cache(int type, unsigned long begin, unsigned long end); -void free_swap_cache(struct page *page); struct page *lookup_swap_cache(swp_entry_t entry, struct vm_area_struct *vma, unsigned long addr); @@ -81,10 +80,6 @@ static inline struct address_space *swap_address_space(swp_entry_t entry) return NULL; } -static inline void free_swap_cache(struct page *page) -{ -} - static inline void show_swap_cache_info(void) { }