Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1397126ybz; Sat, 25 Apr 2020 18:19:51 -0700 (PDT) X-Google-Smtp-Source: APiQypLaDV9+K5TvFC/aWOj5MVF+nm1qN1yXo4N81XIOkjOlv1VPIiuUTMDqCQTi7FOvQMu93N6b X-Received: by 2002:a17:906:add7:: with SMTP id lb23mr14417274ejb.6.1587863991594; Sat, 25 Apr 2020 18:19:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587863991; cv=none; d=google.com; s=arc-20160816; b=AIdfpYtk6186R4Zrg+t8TR5R7u9PdjseS24BaWIj9bYbkSy8fc+bNndqmZ6znD7awo UDPPYEfS1/TOBDMVJjgoSP46wG7nt7C4YPzPY5VnsEvCN0GlF76n5HcMh8RCMMHN+nNm ux49pOuSXeuWKjRBfg08s0UYm7xR/o1Er+MAo4eXtO5H+fonYS0FaA6dnC0HUO0biju+ FPFn2j8cFnGDluerXjSiC/TQU1lFkEpwf2B30pus9swCuVFyzVutWwj0gf+UgP+DXsdg kUpCdBZvb20DH7sMDVvo3LYUCSUcI6fRYaR9N8nLoA6dwOAYfdmsYRn7a2VlV0DD6WKn N8wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter; bh=ZFWUN6SwqhbZKTinzJo6P5hYJfST8OnlARc+KdAxrtw=; b=g0jdpe341X0GRD1H5L8rbtb0Jiuqmr1JgKGk1vTpsc/5TYSbzd2N0C0Ghf1ZElSg6I jb+9V7OLq4cOPnA+eyPvxAQwRSgUOO12w+LfhYOy5pG/9GjxGxTMTsDOgnvS66eLgnud lRsPsxlcDxV01IA+RD1EAxhCl5VFLi8NLIWdScnq3z2u3iwYuBu/afC6vYYyOtWlv5aL N8HwU9FYo38rWW4+IhWVwBvzl/5siZoi5KaEgD9/TOj1B4toXRVBeiDhsCFuCJPV3gRQ 8SW9gkC6uB03egkpmT9U9Hyj+OKr3lEpjfvb5FT7QSfbo7XdovkcCBdkFwkBlZFiU/zA VaQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=Tyg6WqMn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w13si5804591ejj.231.2020.04.25.18.19.26; Sat, 25 Apr 2020 18:19:51 -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; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=Tyg6WqMn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726118AbgDZBRy (ORCPT + 99 others); Sat, 25 Apr 2020 21:17:54 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:20509 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725962AbgDZBRx (ORCPT ); Sat, 25 Apr 2020 21:17:53 -0400 Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20200426011749epoutp04e76796630a70f166c2f91bf4305cceee~JOcaolASy0845008450epoutp04L for ; Sun, 26 Apr 2020 01:17:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20200426011749epoutp04e76796630a70f166c2f91bf4305cceee~JOcaolASy0845008450epoutp04L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1587863869; bh=ZFWUN6SwqhbZKTinzJo6P5hYJfST8OnlARc+KdAxrtw=; h=From:To:Cc:Subject:Date:References:From; b=Tyg6WqMnph77OViEMzVDVfr1PX9BlnWY3NlIFKCQ6Uis+8BQbOv5EDf2aCoCqfRwm uLBw0dN3/nldCdIcnN9LtfFoKtqYGz8gzZ8FFQjX5P6svqBsSH0E8IkzmCYqFQqiIB Q5ZbtlI5jyQbPwyT3PXD0sXPeYJA1ANuRuxoM4wY= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20200426011748epcas1p2bfac8646092af2f903f7a5f4c568f472~JOcZ4dTiz2184821848epcas1p2L; Sun, 26 Apr 2020 01:17:48 +0000 (GMT) Received: from epsmges1p3.samsung.com (unknown [182.195.40.165]) by epsnrtp4.localdomain (Postfix) with ESMTP id 498qlb1ptLzMqYkZ; Sun, 26 Apr 2020 01:17:47 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p3.samsung.com (Symantec Messaging Gateway) with SMTP id 4C.48.04648.A31E4AE5; Sun, 26 Apr 2020 10:17:46 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p2.samsung.com (KnoxPortal) with ESMTPA id 20200426011745epcas1p2255acdcaac77a0efc930337a2cb51aff~JOcX0Codx1719317193epcas1p2u; Sun, 26 Apr 2020 01:17:45 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200426011745epsmtrp128ce6ba78e8f1929b66a10dbd69b6bbd~JOcXzCRsA0818008180epsmtrp1i; Sun, 26 Apr 2020 01:17:45 +0000 (GMT) X-AuditID: b6c32a37-1dbff70000001228-63-5ea4e13ae040 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 17.DD.25866.931E4AE5; Sun, 26 Apr 2020 10:17:45 +0900 (KST) Received: from jaewon-linux.10.32.193.11 (unknown [10.253.104.82]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200426011745epsmtip1f3ce8b3e3185a0a375ab6086a5038ba5~JOcXnAx-V2682426824epsmtip1c; Sun, 26 Apr 2020 01:17:45 +0000 (GMT) From: Jaewon Kim To: minchan@kernel.org, mgorman@suse.de, hannes@cmpxchg.org, m.szyprowski@samsung.com, mina86@mina86.com, shli@fb.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, jaewon31.kim@gmail.com, ytk.lee@samsung.com, Jaewon Kim Subject: [PATCH v3] mm/vmscan: count layzfree pages and fix nr_isolated_* mismatch Date: Sun, 26 Apr 2020 10:17:18 +0900 Message-Id: <20200426011718.30246-1-jaewon31.kim@samsung.com> X-Mailer: git-send-email 2.13.7 X-Brightmail-Tracker: H4sIAAAAAAAAA01Sa0hTYRju82w7y1wcptWHaK1DRRnLrTk9lYugiAMVCvWni66D+1Lp7NLO JplghmuozZZllKagaRfWyppmum5kXrpQiWFhZVGWpJiSokFqa9tR6t/zPu/zvM/L971iTOoU RYozDRZkNjAsKQoVND5epZBv+Fybqph24VRFnVtEXfPsoE7UlwGqeGQwhHrtrRBRH90+IXW9 tRenzgz3A6qqwyakLo+P4NTlZqeA6qubtymMfjw0gtEl+cM43Vzei9MeV6GI9oyexukn5ycF 9I2pwRD6ZIML0PXPc+gxz+Lk0D1sYgZidMgsQ4Y0oy7TkK4ht+3Ubtaq4xVKuXIdlUDKDIwe acgt25PlWzNZ/9akLIthrX4qmeE4MnZjotlotSBZhpGzaEhk0rEmpcK0hmP0nNWQvibNqF+v VCjWqv3K/WzGxKMOzHRm5WHH3U5RHnAvLQJzxZCIg89KXHgRCBVLiSYAi+qeCvhiFMDy0mEh X4wB6D3xC5u1tH3IA3zDC+Dvc99n/L8AvH/vriigEhGr4UjVaWEARxClAE40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g1lJhDem ZFGcEG9KYmVValF+fFFpTmrxIUZpDhYlcd6vsxbGCQmkJ5akZqemFqQWwWSZODilGpjMCg58 3fNOdlpbj+cEeQe+u29rg5Zlv645d4T/hNKj7Lssl/jfK7nbHzHKYf3eLpHRY3jryEGbKjOZ xEvaIWJKc3lnJvxYda5Zxup/6k5bi3nPp5xP61xyT+3lFp0pKW6Zzz5+sZ/anx66OvdOu+L0 /yHcMmcyNgqtLnooLlAv1Nor9uhO6pp7u9a8naKmxlORs2jeuVuLpC3qWkMLZmg59ds7f7AX Wjv79R6na7W//k603aL8qD40f6PF3GeL3j93jDn27v/chMyw9prAHQpvWm+KFTKvVFtWIHx/ 0Y3pbu46AbwFbfKdvZxvFx4x/99x8dH61MVbdvQvlZ0XUfDc07vV4ZkD80HHFTWyn3OVWIoz Eg21mIuKEwGB3h5PwQIAAA== X-CMS-MailID: 20200426011745epcas1p2255acdcaac77a0efc930337a2cb51aff X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20200426011745epcas1p2255acdcaac77a0efc930337a2cb51aff References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch fix nr_isolate_* mismatch problem between cma and dirty lazyfree page. If try_to_unmap_one is used for reclaim and it detects a dirty lazyfree page, then the lazyfree page is changed to a normal anon page having SwapBacked by commit 802a3a92ad7a ("mm: reclaim MADV_FREE pages"). Even with the change, reclaim context correctly counts isolated files because it uses is_file_lru to distinguish file. And the change to anon is not happened if try_to_unmap_one is used for migration. So migration context like compaction also correctly counts isolated files even though it uses page_is_file_lru insted of is_file_lru. Recently page_is_file_cache was renamed to page_is_file_lru by commit 9de4f22a60f7 ("mm: code cleanup for MADV_FREE"). But the nr_isolate_* mismatch problem happens on cma alloc. There is reclaim_clean_pages_from_list which is being used only by cma. It was introduced by commit 02c6de8d757c ("mm: cma: discard clean pages during contiguous allocation instead of migration") to reclaim clean file pages without migration. The cma alloc uses both reclaim_clean_pages_from_list and migrate_pages, and it uses page_is_file_lru to count isolated files. If there are dirty lazyfree pages allocated from cma memory region, the pages are counted as isolated file at the beginging but are counted as isolated anon after finished. Mem-Info: Node 0 active_anon:3045904kB inactive_anon:611448kB active_file:14892kB inactive_file:205636kB unevictable:10416kB isolated(anon):0kB isolated(file):37664kB mapped:630216kB dirty:384kB writeback:0kB shmem:42576kB writeback_tmp:0kB unstable:0kB all_unreclaimable? no Like log above, there were too much isolated files, 37664kB, which triggers too_many_isolated in reclaim even when there is no actually isolated file in system wide. It could be reproducible by running two programs, writing on MADV_FREE page and doing cma alloc, respectively. Although isolated anon is 0, I found that the internal value of isolated anon was the negative value of isolated file. Fix this by compensating the isolated count for both LRU lists. Count non-discarded lazyfree pages in shrink_page_list, then compensate the counted number in reclaim_clean_pages_from_list. Reported-by: Yong-Taek Lee Signed-off-by: Jaewon Kim Suggested-by: and Acked-by: Minchan Kim --- v3: remove redundant PageAnon check and rename some variables v2: do not change logic regarding lazyfree just count dirty lazyfree pages and fix the count issue v1: skip dirty lazyfree pages in reclaim_clean_pages_from_list --- include/linux/vmstat.h | 1 + mm/vmscan.c | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index 292485f3d24d..10cc932e209a 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -29,6 +29,7 @@ struct reclaim_stat { unsigned nr_activate[2]; unsigned nr_ref_keep; unsigned nr_unmap_fail; + unsigned nr_lazyfree_fail; }; enum writeback_stat_item { diff --git a/mm/vmscan.c b/mm/vmscan.c index b06868fc4926..5c78d480db98 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1295,11 +1295,15 @@ static unsigned long shrink_page_list(struct list_head *page_list, */ if (page_mapped(page)) { enum ttu_flags flags = ttu_flags | TTU_BATCH_FLUSH; + bool was_swapbacked = PageSwapBacked(page); if (unlikely(PageTransHuge(page))) flags |= TTU_SPLIT_HUGE_PMD; + if (!try_to_unmap(page, flags)) { stat->nr_unmap_fail += nr_pages; + if (!was_swapbacked && PageSwapBacked(page)) + stat->nr_lazyfree_fail += nr_pages; goto activate_locked; } } @@ -1491,8 +1495,8 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone, .priority = DEF_PRIORITY, .may_unmap = 1, }; - struct reclaim_stat dummy_stat; - unsigned long ret; + struct reclaim_stat stat; + unsigned long nr_reclaimed; struct page *page, *next; LIST_HEAD(clean_pages); @@ -1504,11 +1508,21 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone, } } - ret = shrink_page_list(&clean_pages, zone->zone_pgdat, &sc, - TTU_IGNORE_ACCESS, &dummy_stat, true); + nr_reclaimed = shrink_page_list(&clean_pages, zone->zone_pgdat, &sc, + TTU_IGNORE_ACCESS, &stat, true); list_splice(&clean_pages, page_list); - mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE, -ret); - return ret; + mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE, -nr_reclaimed); + /* + * Since lazyfree pages are isolated from file LRU from the beginning, + * they will rotate back to anonymous LRU in the end if it failed to + * discard so isolated count will be mismatched. + * Compensate the isolated count for both LRU lists. + */ + mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_ANON, + stat.nr_lazyfree_fail); + mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE, + -stat.nr_lazyfree_fail); + return nr_reclaimed; } /* -- 2.13.7