From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEBC1E92FFC for ; Sat, 7 Oct 2023 06:26:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343578AbjJGG0l (ORCPT ); Sat, 7 Oct 2023 02:26:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343551AbjJGG0i (ORCPT ); Sat, 7 Oct 2023 02:26:38 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C1ACC5 for ; Fri, 6 Oct 2023 23:26:36 -0700 (PDT) Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4S2ZvY0h7RztTQg; Sat, 7 Oct 2023 14:22:01 +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; Sat, 7 Oct 2023 14:26:33 +0800 Subject: Re: [PATCH v6] mm: vmscan: try to reclaim swapcache pages if no swap space To: Andrew Morton References: <20230915083417.3190512-1-liushixin2@huawei.com> <20231004091853.9be5aa562f65e0305e06b14c@linux-foundation.org> CC: Yosry Ahmed , Huang Ying , Sachin Sant , Michal Hocko , Johannes Weiner , Kefeng Wang , , From: Liu Shixin Message-ID: <38420ca8-9c83-bb06-041f-ce1cf1f084ef@huawei.com> Date: Sat, 7 Oct 2023 14:26:32 +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: <20231004091853.9be5aa562f65e0305e06b14c@linux-foundation.org> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.24] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/10/5 0:18, Andrew Morton wrote: > On Fri, 15 Sep 2023 16:34:17 +0800 Liu Shixin wrote: > >> 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. >> >> The problem is found with such step: >> >> Firstly, set a 9MB disk swap space, then create a cgroup with 10MB >> memory limit, then runs an program to allocates about 15MB memory. >> >> The problem occurs occasionally, which may need about 100 times [1]. >> >> Fix it by checking number of swapcache pages in can_reclaim_anon_pages(). >> If the number is not zero, return true and set swapcache_only to 1. >> When scan anon lru list in swapcache_only mode, non-swapcache pages will >> be skipped to isolate in order to accelerate reclaim efficiency. >> >> However, in swapcache_only mode, the scan count still increased when scan >> non-swapcache pages because there are large number of non-swapcache pages >> and rare swapcache pages in swapcache_only mode, and if the non-swapcache >> is skipped and do not count, the scan of pages in isolate_lru_folios() can >> eventually lead to hung task, just as Sachin reported [2]. >> >> By the way, since there are enough times of memory reclaim before OOM, it >> is not need to isolate too much swapcache pages in one times. >> > mhocko earlier suspected this might impact global reclaim. Have you > looked into that further? > . Alreadly test the case of global reclaim using ltp testcases. In previous version, the reclaim can stall in isolate_lru_folios() because I didn't count non-swapcache pages into scan so it will waste too much times scanning non-swapcache pages. In this version, I count non-swapcache pages into scan too and terminate when scan reaches the threshold. So it will not stall in reclaim now.