Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp987745iog; Wed, 15 Jun 2022 17:34:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vUBD9CeUekJPGr41xcIPC1S0gXHCuYKuVq7C+gvyP14ZO2+TozmpJzpoJamCZ2B483JU7i X-Received: by 2002:a17:907:a420:b0:6ff:1541:8d34 with SMTP id sg32-20020a170907a42000b006ff15418d34mr2177993ejc.447.1655339644782; Wed, 15 Jun 2022 17:34:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655339644; cv=none; d=google.com; s=arc-20160816; b=IsDzvgfg6l47dbBOh3GnoElwOvT6B7fXZaI3vnj41ln7S6F7zLdQ4llsGjMN6gXC7+ kdzXy4O/dcCboXdCtlzf0FmO6tYISaMEYxxYlKz0OqCPGMNJlxAPnAi2mcXeqtuFELF0 pQRm9DRgzrmfVvBDwtnx//4rrawmndJql0p0rbkWbjr8tywU6RmvSSHVASbeSMt/DDBD yDT0ZCIH6KUybaIhZOG9UAtrekoinSseXp/OUr8IkKV255SBQF5GO9LQ/hqV+GxUnhKw O3Mc9pHuWDzS+W4PcDO0nPH7ChCpSdhxePxkwVcyz+YTle9B4pEkLBActHIY26VTSDz/ Dz+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8FxRBjQ0UOjYH2PrzD6Nb5pD0gKIkBB2NSnuTdmjdco=; b=JW96jdyL5inxSm/VnlyEQglyZ+IaDLwLiPc3miudkg6rMOL51ZUuZRa0dTovToPl8e qwUCeehi9aOLg95QJHZQG7hkr7bbk6fQhbHj09oCA1vNpTmtTp/PuInzmUaIVYXBhD79 D/TL88Tta3VB5O7AFDmAMQqShW5Xlz9qtuh46aw6bsh/Ksp1FoOqnOEB7fiYvOayZQ+W WHVadtWNHuU6VRpg2TYLnrNSJWPmpLQ9LS0GMpPnQZZO/FxtI9p7cx8DsTE0SQ8n7HEq dD2VPefEjzF+rRbSyQEvz/mfoRNCQR/M4A3X1kSnOTsdC2FVIt2Ia1wIuI6vgk3SQV+B Yi4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=BLH1wVDp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q12-20020aa7da8c000000b0043343b37a13si713453eds.279.2022.06.15.17.33.39; Wed, 15 Jun 2022 17:34:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=BLH1wVDp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348454AbiFOX6j (ORCPT + 99 others); Wed, 15 Jun 2022 19:58:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347635AbiFOX6c (ORCPT ); Wed, 15 Jun 2022 19:58:32 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2DFD41999 for ; Wed, 15 Jun 2022 16:58:31 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id y13-20020a17090a154d00b001eaaa3b9b8dso27754pja.2 for ; Wed, 15 Jun 2022 16:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8FxRBjQ0UOjYH2PrzD6Nb5pD0gKIkBB2NSnuTdmjdco=; b=BLH1wVDpXIg/aGye42+V5ZSnYf2qgfj028inxDJF/QYFv6aPBZH3fjtcTPpASjZ7mm eqShbHrAZ4iNKuhCfzD5e7moJmC9XOGQrFtRnK4h5aPUp11FaoG2uXDtCvPYh6Ty8KIR Lba8W53JDVcaEAf3SWKRvN9W5cyF2XKYN8gpNCKesEPYb27YuctmmSb0MuYST1yGp1rH RD44er+jfH0JSNzyvV1Kj2LJ7A8xHfQ3Okxdg0JQKUoUoSfc17Yo3ndTOx+5tKrTMBhV R6M+u7B9D/kWFpe2tGQDmfp+Ppjhsv3t+dWJuF2AetPdBGMXfTKYUULxlwdtbzQrSdzu yMlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8FxRBjQ0UOjYH2PrzD6Nb5pD0gKIkBB2NSnuTdmjdco=; b=4Xqy+A7tRDX3BKXothcDJnXwY23vyraAaNh3iQ/wkrmX6b9uc4zcCLcuAk+lfw/Nxm xgjuBjHQb9xgAju/ZRtoDZrBHD+aH0IjacvEyVKwNtjoNkPmNvZ1Htes7+JTpsGlsLQB Bl5su20sT4/ywPQcf0afaoi2RCRqwvhGXqU+Zq2Ba+yL00rXOU0rFg5rHZtdeDLH4gA6 xuofC0/NT3bpSTnMTPxTCJAYyG4TREWD3TIc2PkNQo54HZxPwC9NXvBVFbeu0u/pAARZ Nl2+z91dLWRD0YioWMaV0660JKn8YN1nr19h+iHy1vo7pwb4HPksybvgn/oPkWQOM1ET u0ng== X-Gm-Message-State: AJIora/INxMbNtXPH26zjaTnYVn3yWuGe5Ig+eZ+8gol/GZQm+B89tsj m3cGTntCExfJ/mU7HZS93Q4bt8byOci3vlAIv00= X-Received: by 2002:a17:903:32c4:b0:167:6e6f:204b with SMTP id i4-20020a17090332c400b001676e6f204bmr1965881plr.117.1655337511162; Wed, 15 Jun 2022 16:58:31 -0700 (PDT) MIME-Version: 1.0 References: <20220611084731.55155-1-linmiaohe@huawei.com> <20220611084731.55155-8-linmiaohe@huawei.com> In-Reply-To: <20220611084731.55155-8-linmiaohe@huawei.com> From: Yang Shi Date: Wed, 15 Jun 2022 16:58:18 -0700 Message-ID: Subject: Re: [PATCH 7/7] mm/khugepaged: try to free transhuge swapcache when possible To: Miaohe Lin Cc: Andrew Morton , Andrea Arcangeli , Matthew Wilcox , Vlastimil Babka , David Howells , NeilBrown , Alistair Popple , David Hildenbrand , Suren Baghdasaryan , Peter Xu , Linux MM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 11, 2022 at 1:47 AM Miaohe Lin wrote: > > 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); Will this really work? The free_swap_cache() will just dec refcounts without putting the page back to buddy. So the hugepage is not actually freed at all. Am I missing something? > } > } > > 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) > { > } > -- > 2.23.0 > >