Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp2333822rdb; Mon, 28 Aug 2023 00:17:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFOGIqFjkwlT0VjiByZuLnPfzECjwYM4FAyexUEIR8axWI+75YqBcUiCQyE6p4MT4tvq0QF X-Received: by 2002:a05:6512:3e1a:b0:500:b102:d1c6 with SMTP id i26-20020a0565123e1a00b00500b102d1c6mr4298783lfv.47.1693207060137; Mon, 28 Aug 2023 00:17:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693207060; cv=none; d=google.com; s=arc-20160816; b=ZHaaySfg1kpHNbg1dDKbB3mzHdjV8T0jX/v5k+yWOuXphZ0traAbh9tTnqJHI6GxzH RGwf2uyPBeOgcagUbuOzf83pP+taD9Y2gR69zy6Z2NQ5R58w3FiHHpy7efqExEkHOFvm LUQqftFhEvA6QOTDmnlYpfGoSv/1zqrMJpI68quMTezgkovpdqtHFeRPL6t81E2TTjKW adgg5D2SaY/Q7u/ArDdKW/z3TCbN3yxPJKCmM63FxfioWQiV8WCu9zLNQuW9+WJoE0J/ PatP8q3Ugr5Cw6EmJcel/IFeFzPWZAsbggb5MNtOSkjmTqk5lGwvCxXEF9jHf2Jqbyn8 tUqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=yudRVUURh4wslchr7CNaLbLd69ya7qKW0UC1g0aPS7U=; fh=UOF3WKVoGkQTJNZvURN/AhItv/AsdygIolpPlMdT0PE=; b=YD9+H+I3d3cqSYQPrlq0aBnJIkE4ZTI7Og1SPV4vFOPC4GoJV6gReWNEfE8zD+VgEx +8X+DXR3LfWNkpuDTTAeZNOHvtOSU6C7YYAmCcvDAWNHrWjhXVUhQQw1jnlmiQEZyGy0 maA+FcwJBrNZn3zKHXKsAbOlqyEI7xgziReoWyZOpkj7qTuEPweB0zNmDTItX8sQ8waJ 50ftO/Evz5SZhODJ/3srJlB+U2ZW2Zm6yoo3JmgH62aYq2KEaMhSIgHOHOY8SwhbbtAJ 1msU5hSxQf2AgDCSogSzLciKYHY7eu7dYHqjb85El5t/zP7ufOlJTpVk7MpA+wn3EnlP MD4A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020a170906134100b0096f4deef5basi2976272ejb.649.2023.08.28.00.16.53; Mon, 28 Aug 2023 00:17:40 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229632AbjH1HLl (ORCPT + 99 others); Mon, 28 Aug 2023 03:11:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbjH1HL0 (ORCPT ); Mon, 28 Aug 2023 03:11:26 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3229D8; Mon, 28 Aug 2023 00:11:21 -0700 (PDT) Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RZ1s33MzjzrSCZ; Mon, 28 Aug 2023 15:09:43 +0800 (CST) Received: from [10.174.179.24] (10.174.179.24) by dggpemm500009.china.huawei.com (7.185.36.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 28 Aug 2023 15:11:19 +0800 Subject: Re: [PATCH v3] mm: vmscan: try to reclaim swapcache pages if no swap space To: "Huang, Ying" References: <20230826034401.640861-1-liushixin2@huawei.com> <87il9053zo.fsf@yhuang6-desk2.ccr.corp.intel.com> CC: Yosry Ahmed , Michal Hocko , Johannes Weiner , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , , , , From: Liu Shixin Message-ID: <2992c888-b8c7-d93b-d132-ea90e2c516e3@huawei.com> Date: Mon, 28 Aug 2023 15:11:19 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <87il9053zo.fsf@yhuang6-desk2.ccr.corp.intel.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.24] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS 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 2023/8/28 9:51, Huang, Ying wrote: > Liu Shixin writes: > >> When spaces of swap devices are exhausted, only file pages can be reclaimed. >> But there are still some swapcache pages in anon lru list. This can lead >> to a premature out-of-memory. >> >> This problem can be fixed by checking number of swapcache pages in >> can_reclaim_anon_pages(). >> >> Add a new bit swapcache_only in struct scan_control to skip isolating anon >> pages that are not in the swap cache when only swap cache can be reclaimed. > Better to describe how you test the patch and test results. OK, I will add the infomation. > >> Signed-off-by: Liu Shixin >> --- >> include/linux/swap.h | 6 ++++++ >> mm/memcontrol.c | 8 ++++++++ >> mm/vmscan.c | 29 +++++++++++++++++++++++++++-- >> 3 files changed, 41 insertions(+), 2 deletions(-) >> >> diff --git a/include/linux/swap.h b/include/linux/swap.h >> index 456546443f1f..0318e918bfa4 100644 >> --- a/include/linux/swap.h >> +++ b/include/linux/swap.h >> @@ -669,6 +669,7 @@ static inline void mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_p >> } >> >> extern long mem_cgroup_get_nr_swap_pages(struct mem_cgroup *memcg); >> +extern long mem_cgroup_get_nr_swapcache_pages(struct mem_cgroup *memcg); >> extern bool mem_cgroup_swap_full(struct folio *folio); >> #else >> static inline void mem_cgroup_swapout(struct folio *folio, swp_entry_t entry) >> @@ -691,6 +692,11 @@ static inline long mem_cgroup_get_nr_swap_pages(struct mem_cgroup *memcg) >> return get_nr_swap_pages(); >> } >> >> +static inline long mem_cgroup_get_nr_swapcache_pages(struct mem_cgroup *memcg) >> +{ >> + return total_swapcache_pages(); >> +} >> + >> static inline bool mem_cgroup_swap_full(struct folio *folio) >> { >> return vm_swap_full(); >> diff --git a/mm/memcontrol.c b/mm/memcontrol.c >> index e8ca4bdcb03c..c465829db92b 100644 >> --- a/mm/memcontrol.c >> +++ b/mm/memcontrol.c >> @@ -7567,6 +7567,14 @@ long mem_cgroup_get_nr_swap_pages(struct mem_cgroup *memcg) >> return nr_swap_pages; >> } >> >> +long mem_cgroup_get_nr_swapcache_pages(struct mem_cgroup *memcg) >> +{ >> + if (mem_cgroup_disabled()) >> + return total_swapcache_pages(); >> + >> + return memcg_page_state(memcg, NR_SWAPCACHE); >> +} >> + >> bool mem_cgroup_swap_full(struct folio *folio) >> { >> struct mem_cgroup *memcg; >> diff --git a/mm/vmscan.c b/mm/vmscan.c >> index 7c33c5b653ef..5cb4adf6642b 100644 >> --- a/mm/vmscan.c >> +++ b/mm/vmscan.c >> @@ -137,6 +137,9 @@ struct scan_control { >> /* Always discard instead of demoting to lower tier memory */ >> unsigned int no_demotion:1; >> >> + /* Swap space is exhausted, only reclaim swapcache for anon LRU */ >> + unsigned int swapcache_only:1; >> + >> /* Allocation order */ >> s8 order; >> >> @@ -613,10 +616,20 @@ static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg, >> */ >> if (get_nr_swap_pages() > 0) >> return true; >> + /* Is there any swapcache pages to reclaim? */ >> + if (total_swapcache_pages() > 0) { >> + sc->swapcache_only = 1; >> + return true; >> + } >> } else { >> /* Is the memcg below its swap limit? */ >> if (mem_cgroup_get_nr_swap_pages(memcg) > 0) >> return true; >> + /* Is there any swapcache pages in memcg to reclaim? */ >> + if (mem_cgroup_get_nr_swapcache_pages(memcg) > 0) { >> + sc->swapcache_only = 1; >> + return true; >> + } >> } >> >> /* >> @@ -2280,6 +2293,19 @@ static bool skip_cma(struct folio *folio, struct scan_control *sc) >> } >> #endif >> >> +static bool skip_isolate(struct folio *folio, struct scan_control *sc, >> + enum lru_list lru) >> +{ >> + if (folio_zonenum(folio) > sc->reclaim_idx) >> + return true; >> + if (skip_cma(folio, sc)) >> + return true; >> + if (unlikely(sc->swapcache_only && !is_file_lru(lru) && >> + !folio_test_swapcache(folio))) > Just > > if (unlikely(sc->swapcache_only && !folio_test_swapcache(folio))) > > is enough. That would results the file pages to be skipped too, but what expected is to skip non-swapcache pages in anon lru list. So I think the condition !is_file_lru(lru) is required. Thanks, > >> + return true; >> + return false; >> +} >> + >> /* >> * Isolating page from the lruvec to fill in @dst list by nr_to_scan times. >> * >> @@ -2326,8 +2352,7 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan, >> nr_pages = folio_nr_pages(folio); >> total_scan += nr_pages; >> >> - if (folio_zonenum(folio) > sc->reclaim_idx || >> - skip_cma(folio, sc)) { >> + if (skip_isolate(folio, sc, lru)) { >> nr_skipped[folio_zonenum(folio)] += nr_pages; >> move_to = &folios_skipped; >> goto move; > -- > Best Regards, > Huang, Ying > . >