From patchwork Fri Sep 13 08:45:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingxiang Zeng X-Patchwork-Id: 13803155 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 A847EFA3730 for ; Fri, 13 Sep 2024 08:45:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 396846B00D3; Fri, 13 Sep 2024 04:45:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 31DEA6B00D4; Fri, 13 Sep 2024 04:45:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E6F96B00D5; Fri, 13 Sep 2024 04:45:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id F3B0F6B00D3 for ; Fri, 13 Sep 2024 04:45:19 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5A4A316210C for ; Fri, 13 Sep 2024 08:45:19 +0000 (UTC) X-FDA: 82559080758.17.1C480C4 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf11.hostedemail.com (Postfix) with ESMTP id 8A5674000A for ; Fri, 13 Sep 2024 08:45:17 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=R5mtA+Lc; spf=pass (imf11.hostedemail.com: domain of jingxiangzeng.cas@gmail.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=jingxiangzeng.cas@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726217011; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LBaXwW8QjKdmii8I0jDL7B6wKU8ukCvUrMoN+whfYyo=; b=3Ii2ZQ0pYTnHu00ZaUBEpHnxSGbEND3KqLE9NqlbuLN+mMgKjPRVbQuf2I80umLJ8YpEQi Y2eiaGpuGUyJEzpCU46o5tviJBNncBWiscPDVqqd9+BofZJY8tH/+hvF08O4SO8rR5j9EH sl1zds4+pPbO1fq+4VLK67WeDXGt7gM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726217011; a=rsa-sha256; cv=none; b=wIDNQweLlEteyyyk+tQjtD03myXZMxD6sODgQfnpmPgsAVVWhwv+UdzyAjWvglAZccw2sZ bkdK/GQtwp8LLuPlti/hpHYI1U3W5/OMSMxx0cEgPSB/kbw0L9X1YgYkOo+lACwkuc5iSs MI2L9idg4yQnqAWgtBnSvECaEZ1NVKA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=R5mtA+Lc; spf=pass (imf11.hostedemail.com: domain of jingxiangzeng.cas@gmail.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=jingxiangzeng.cas@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-7d916b6a73aso1212806a12.1 for ; Fri, 13 Sep 2024 01:45:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726217116; x=1726821916; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LBaXwW8QjKdmii8I0jDL7B6wKU8ukCvUrMoN+whfYyo=; b=R5mtA+Lcij4FjRksW3CtnOBz1ht4M4ciAvi5+aoBNXiN9hiH5JPOMpBtqcIoygAJqa BvNpZ9U7SOC3J8V/bdusBQNhKaZltP5AKwzeWDQVQxJLk1gtDxbqA67RwAC0g/kfVkJp hSRp3YFcgvlTFW8UHQl2UuiL5X+yw0plmS2nv2rEnAk1nWJ8VPsKD7CcPHa8geDbnhMu ACyJTW7NnkwQr3HC88Sg3T3St7Yg1OX66CvnwoTdiXPhkGeqGqaPbopaM5iLHj4h5TJZ YmgJTBOQmLWVarOHIrvjZhcNl5NAKlFvRBAAWuf9s8x5qG1BitgPQ2xzjC2TKSMl+K5a ZEwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726217116; x=1726821916; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LBaXwW8QjKdmii8I0jDL7B6wKU8ukCvUrMoN+whfYyo=; b=fI4wgkLM/zrHJn9RNRH3NcPJXBN2ouE/hQGHy0fK3QOpoch5I2VmO3VrMo1KO/bsoL qKPD1Pt029cDkR3DmJ86AWTayeKJ3unI3iiiYkPNixOVypWay5y3UlYnU1bqQqOq7akA 86gEj2Jxk2VJTfo+HdB9QghOgewuoyH8ykchHxW5FQvlZ74YeslRfwuSNHuykgunwXH7 BpUnum7dYmgRGkvCt/XgN9u6FbMEAcP0wEY7pQyIhNDTR3xktoZroH7i/ystv9r0dmHx a6Mmi3rQr+zEUPrYo9RSEOoqXXJB+TyvCfx898hHgDoc4ejl5VFE4ZgLSM4tg4uemu95 kc6w== X-Gm-Message-State: AOJu0YzXoqBwfAR5GIVc2O5y1obng9ASMlO42j/l5C8J5yZK0Kl0aFrg 9Kt/mJsZ3AukLqV3uBe3yGw4HGvW5yV61/414qRQadIZIZ4kaL1Iqf2GT5jd X-Google-Smtp-Source: AGHT+IEe/ktw1g7ykbDpuyD3WcdpPiVaeAgpfOqsyCOMhflk5+yuFzMnyfckA1sKTTcbC3biWB58Gg== X-Received: by 2002:a05:6a21:1698:b0:1c0:ec1c:f4a5 with SMTP id adf61e73a8af0-1cf75f00575mr8644130637.25.1726217115686; Fri, 13 Sep 2024 01:45:15 -0700 (PDT) Received: from localhost.localdomain ([14.116.239.33]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7db1fb9ad9fsm2502679a12.10.2024.09.13.01.45.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 01:45:15 -0700 (PDT) From: Jingxiang Zeng To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, kasong@tencent.com, linuszeng@tencent.com, linux-kernel@vger.kernel.org, tjmercier@google.com, weixugc@google.com, yuzhao@google.com Subject: [PATCH V2] mm/vmscan: wake up flushers conditionally to avoid cgroup OOM Date: Fri, 13 Sep 2024 16:45:06 +0800 Message-ID: <20240913084506.3606292-1-jingxiangzeng.cas@gmail.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8A5674000A X-Stat-Signature: 5g5smdoygpb1gq4pnz9oubmudqbchmjg X-HE-Tag: 1726217117-300563 X-HE-Meta: U2FsdGVkX19m5JG2G53kxqvpS5UG025Q6NeC3CftMvM9FxMKq+fy/RsfmT/+xVP7LZVhRsWvDLucIAkTQ6YUqKbiG1es+NjevD4AiYbJJ6GtJsk/t/Cr5M/rlYB3c91dqBJnixFAR+Q1M9nUH3kPhjstZ2HTOdf3QFpnSKqnU0d8zMopEiM8z1hOylFj7BJnoslPFqviGZbOqIWW243GAG1KlPS+ASlzYU9ie4uagIwvUUbWjfZk2WPjnNP/nslgIFm4K1LhQjLIZu1I+8izGqrCfTzEgdR7BnIqU8cGEWoGhB7XjRro2FVmPlDTaFV3NbKZuz+UMRVNGEspJilj77PmgNvQJEKmaIP7/QFwzBsVhyWuINYnk+T5HK42Ds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yuWnxckNTtcDA/wh4YreGknOyVWz+pJcKu++ZElSxOaDxv7+BiYWNHGPCltXrPFE4JEtSKhX6 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zeng Jingxiang Commit 14aa8b2d5c2e ("mm/mglru: don't sync disk for each aging cycle") removed the opportunity to wake up flushers during the MGLRU page reclamation process can lead to an increased likelihood of triggering OOM when encountering many dirty pages during reclamation on MGLRU. This leads to premature OOM if there are too many dirty pages in cgroup: Killed dd invoked oom-killer: gfp_mask=0x101cca(GFP_HIGHUSER_MOVABLE|__GFP_WRITE), order=0, oom_score_adj=0 Call Trace: dump_stack_lvl+0x5f/0x80 dump_stack+0x14/0x20 dump_header+0x46/0x1b0 oom_kill_process+0x104/0x220 out_of_memory+0x112/0x5a0 mem_cgroup_out_of_memory+0x13b/0x150 try_charge_memcg+0x44f/0x5c0 charge_memcg+0x34/0x50 __mem_cgroup_charge+0x31/0x90 filemap_add_folio+0x4b/0xf0 __filemap_get_folio+0x1a4/0x5b0 ? srso_return_thunk+0x5/0x5f ? __block_commit_write+0x82/0xb0 ext4_da_write_begin+0xe5/0x270 generic_perform_write+0x134/0x2b0 ext4_buffered_write_iter+0x57/0xd0 ext4_file_write_iter+0x76/0x7d0 ? selinux_file_permission+0x119/0x150 ? srso_return_thunk+0x5/0x5f ? srso_return_thunk+0x5/0x5f vfs_write+0x30c/0x440 ksys_write+0x65/0xe0 __x64_sys_write+0x1e/0x30 x64_sys_call+0x11c2/0x1d50 do_syscall_64+0x47/0x110 entry_SYSCALL_64_after_hwframe+0x76/0x7e memory: usage 308224kB, limit 308224kB, failcnt 2589 swap: usage 0kB, limit 9007199254740988kB, failcnt 0 ... file_dirty 303247360 file_writeback 0 ... oom-kill:constraint=CONSTRAINT_MEMCG,nodemask=(null),cpuset=test, mems_allowed=0,oom_memcg=/test,task_memcg=/test,task=dd,pid=4404,uid=0 Memory cgroup out of memory: Killed process 4404 (dd) total-vm:10512kB, anon-rss:1152kB, file-rss:1824kB, shmem-rss:0kB, UID:0 pgtables:76kB oom_score_adj:0 The flusher wake up was removed to decrease SSD wearing, but if we are seeing all dirty folios at the tail of an LRU, not waking up the flusher could lead to thrashing easily. So wake it up when a mem cgroups is about to OOM due to dirty caches. Link: https://lkml.kernel.org/r/20240829102543.189453-1-jingxiangzeng.cas@gmail.com Fixes: 14aa8b2d5c2e ("mm/mglru: don't sync disk for each aging cycle") Signed-off-by: Zeng Jingxiang Signed-off-by: Kairui Song Cc: T.J. Mercier Cc: Wei Xu Cc: Yu Zhao Signed-off-by: Andrew Morton --- mm/vmscan.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mm/vmscan.c b/mm/vmscan.c index 749cdc110c74..ce471d686a88 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4284,6 +4284,7 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_c int tier_idx) { bool success; + bool dirty, writeback; int gen = folio_lru_gen(folio); int type = folio_is_file_lru(folio); int zone = folio_zonenum(folio); @@ -4332,6 +4333,9 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_c /* waiting for writeback */ if (folio_test_locked(folio) || folio_test_writeback(folio) || (type == LRU_GEN_FILE && folio_test_dirty(folio))) { + folio_check_dirty_writeback(folio, &dirty, &writeback); + if (dirty && !writeback) + sc->nr.unqueued_dirty += delta; gen = folio_inc_gen(lruvec, folio, true); list_move(&folio->lru, &lrugen->folios[gen][type][zone]); return true; @@ -4448,6 +4452,7 @@ static int scan_folios(struct lruvec *lruvec, struct scan_control *sc, scanned, skipped, isolated, type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON); + sc->nr.taken += isolated; /* * There might not be eligible folios due to reclaim_idx. Check the * remaining to prevent livelock if it's not making progress. @@ -4920,6 +4925,14 @@ static void lru_gen_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc if (try_to_shrink_lruvec(lruvec, sc)) lru_gen_rotate_memcg(lruvec, MEMCG_LRU_YOUNG); + /* + * If too many pages failed to evict due to page being dirty, + * memory pressure have pushed dirty pages to oldest gen, + * wake up flusher. + */ + if (sc->nr.unqueued_dirty > sc->nr.taken) + wakeup_flusher_threads(WB_REASON_VMSCAN); + clear_mm_walk(); blk_finish_plug(&plug);