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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07ED8C7618E for ; Wed, 26 Apr 2023 11:07:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A5306B00C7; Wed, 26 Apr 2023 07:07:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 453746B00C8; Wed, 26 Apr 2023 07:07:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31D236B00C9; Wed, 26 Apr 2023 07:07:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 213526B00C7 for ; Wed, 26 Apr 2023 07:07:40 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B9CB34025B for ; Wed, 26 Apr 2023 11:07:39 +0000 (UTC) X-FDA: 80723266638.11.14A28DB Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) by imf25.hostedemail.com (Postfix) with ESMTP id 41D53A0031 for ; Wed, 26 Apr 2023 11:07:35 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=canonical.com header.s=20210705 header.b=H6iquVvd; dmarc=pass (policy=none) header.from=canonical.com; spf=pass (imf25.hostedemail.com: domain of hui.wang@canonical.com designates 185.125.188.121 as permitted sender) smtp.mailfrom=hui.wang@canonical.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682507256; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NBFrbPOZWWytZMQ81SI0vbuR3/xmBNFj9NaJHoFqwtk=; b=o8/KpHjlh1LJbThNjSrHOac3lRfTMPY9zqHYIigN/uFgbO5Nwf1gO5vp0H5dxb1IY36L7z qzNeWetvTTTEYISZD5d5ZwnI6yoaT0BbcCnp4stsJAfpnkmo7/jAZTy2lw2hq73Kb3bZzh +Ev0fbnmf6GZrQy21s9saGYE82qAwCQ= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=canonical.com header.s=20210705 header.b=H6iquVvd; dmarc=pass (policy=none) header.from=canonical.com; spf=pass (imf25.hostedemail.com: domain of hui.wang@canonical.com designates 185.125.188.121 as permitted sender) smtp.mailfrom=hui.wang@canonical.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682507256; a=rsa-sha256; cv=none; b=pO6+KinHmwThX5E3z7ayfk1tUS3n5F06Dr5jZECfah2oGAyAbCaHoVXXzhhFBQhyPN6wZN DV2t6U33ztyO+xftJlaFDOuAPSWMOIV+ZpYhL7bNGalGtA56w3PRr1aqfS0QL9Bn/yIT7E ycaukUXCMkAEDf0VjB/EKrKePeXK8JY= Received: from [192.168.0.106] (unknown [123.112.66.36]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id 9C3943FC2B; Wed, 26 Apr 2023 11:07:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1682507253; bh=NBFrbPOZWWytZMQ81SI0vbuR3/xmBNFj9NaJHoFqwtk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=H6iquVvdF9Nsh9L74QTkEt3/uXyCiAZEuXMwMmMV4n4pSsn/YC9a/4rViVxkdl0tL Uat2Z/LWPTcOL8FEn118q+4KfSjVR/80DoQzucOWplhqq2joT0V7xhAm3Hlb9giR3R vwiu4UYYpFDSIg7ExOdHSnQ8hhKKO7i03RKs5oychzMZaehvxX6XF0fIywW+FwAuE8 E37223/XitlMEo6mO3E3DcRPowEtZAbV0yGGvSqwE9fgYDLyx3XTPA7GO7mifq4xy4 GD/PRBs3z+s5g0KtTY2gYgx/v/vF6pf3rL8T1o4hcSX4Dl8rp7LyV40TLmqIHnRVq+ xXf0R4CY1m3hA== Message-ID: Date: Wed, 26 Apr 2023 19:07:23 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH 1/1] mm/oom_kill: trigger the oom killer if oom occurs without __GFP_FS To: Michal Hocko Cc: linux-mm@kvack.org, akpm@linux-foundation.org, surenb@google.com, colin.i.king@gmail.com, shy828301@gmail.com, hannes@cmpxchg.org, vbabka@suse.cz, hch@infradead.org, mgorman@suse.de, dan.carpenter@oracle.com, Phillip Lougher References: <20230426051030.112007-1-hui.wang@canonical.com> <20230426051030.112007-2-hui.wang@canonical.com> Content-Language: en-US From: Hui Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 41D53A0031 X-Stat-Signature: cbhnoksd9z6hr5hy4qybbfmwywy5k49q X-HE-Tag: 1682507255-565807 X-HE-Meta: U2FsdGVkX1/MP8iuCbb2MbCBVEPteFxCwqbhRQFCxVUaAequzFl4lLV6JDjZBOTFOGvh8FbnrllTmpkYjON3tjGWQLJycPcBpgZ+G4Wrl9dJ8MY5pG+zubJXRRJ1LhxWbXHj+AP65k2BrJ04UUla5hQPwADqEew+5URfcBemmp6Iw5i1CRKKxSiRQrrLHuSSz6ovxDNjsydo6t/ki0WlpcbHOq5y1zkBF6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l3vSAoZwzfvfxA38tA66EEqiA++kP/r5NajpaNCaNriRzPMQGqM+buqIdpvyzjKkrtz81aZfs/QZ+P+zokJqQBRNDaD+uLLuq7YA+6cmuRcxIy2pRvklVqPW9DZMG4AgzrxHcqyC1U8f1zbwVBFpSo/tTKUYJlUjgD9Ll3lBa5uPNANoM3APdVVaoGkMgfJWEqcZhMiD4g5WXBQ3Xx9ZsoyGk0qCgCiC3Nq6mAAVCS3fQX6Ygyf7qsDJAZM8xlaMaTq5dxOl3Cp9ryLnKB1uj1sRI8LN+kQsgg5oYrU+ngACv91hu0X0j8DXoom7tML7EMuJ2tPaMV6H5jfS3HlN9YkoIU8TIYMsUQKiVAr31CLshLMhIZhJaTQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 4/26/23 16:33, Michal Hocko wrote: > [CC squashfs maintainer] > > On Wed 26-04-23 13:10:30, Hui Wang wrote: >> If we run the stress-ng in the filesystem of squashfs, the system >> will be in a state something like hang, the stress-ng couldn't >> finish running and the console couldn't react to users' input. >> >> This issue happens on all arm/arm64 platforms we are working on, >> through debugging, we found this issue is introduced by oom handling >> in the kernel. >> >> The fs->readahead() is called between memalloc_nofs_save() and >> memalloc_nofs_restore(), and the squashfs_readahead() calls >> alloc_page(), in this case, if there is no memory left, the >> out_of_memory() will be called without __GFP_FS, then the oom killer >> will not be triggered and this process will loop endlessly and wait >> for others to trigger oom killer to release some memory. But for a >> system with the whole root filesystem constructed by squashfs, >> nearly all userspace processes will call out_of_memory() without >> __GFP_FS, so we will see that the system enters a state something like >> hang when running stress-ng. >> >> To fix it, we could trigger a kthread to call page_alloc() with >> __GFP_FS before returning from out_of_memory() due to without >> __GFP_FS. > I do not think this is an appropriate way to deal with this issue. > Does it even make sense to trigger OOM killer for something like > readahead? Would it be more mindful to fail the allocation instead? > That being said should allocations from squashfs_readahead use > __GFP_RETRY_MAYFAIL instead? Thanks for your comment, and this issue could hardly be reproduced on ext4 filesystem, that is because the ext4->readahead() doesn't call alloc_page(). If changing the ext4->readahead() as below, it will be easy to reproduce this issue with the ext4 filesystem (repeatedly run: $stress-ng --bigheap ${num_of_cpu_threads} --sequential 0 --timeout 30s --skip-silent --verbose) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index ffbbd9626bd8..8b9db0b9d0b8 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3114,12 +3114,18 @@ static int ext4_read_folio(struct file *file, struct folio *folio)  static void ext4_readahead(struct readahead_control *rac)  {         struct inode *inode = rac->mapping->host; +       struct page *tmp_page;         /* If the file has inline data, no need to do readahead. */         if (ext4_has_inline_data(inode))                 return; +       tmp_page = alloc_page(GFP_KERNEL); +         ext4_mpage_readpages(inode, rac, NULL); + +       if (tmp_page) +               __free_page(tmp_page);  } BTW, I applied my patch to the linux-next and ran the oom stress-ng testcases overnight, there is no hang, oops or crash, looks like there is no big problem to use a kthread to trigger the oom killer in this case. And Hi squashfs maintainer, I checked the code of filesystem, looks like most filesystems will not call alloc_page() in the readahead(), could you please help take a look at this issue, thanks. > >> Cc: Andrew Morton >> Cc: Michal Hocko >> Cc: Suren Baghdasaryan >> Cc: Colin Ian King >> Cc: Yang Shi >> Cc: Johannes Weiner >> Cc: Vlastimil Babka >> Cc: Christoph Hellwig >> Cc: Mel Gorman >> Cc: Dan Carpenter >> Signed-off-by: Hui Wang >> --- >> mm/oom_kill.c | 22 +++++++++++++++++++++- >> 1 file changed, 21 insertions(+), 1 deletion(-) >> >> diff --git a/mm/oom_kill.c b/mm/oom_kill.c >> index 044e1eed720e..c9c38d6b8580 100644 >> --- a/mm/oom_kill.c >> +++ b/mm/oom_kill.c >> @@ -1094,6 +1094,24 @@ int unregister_oom_notifier(struct notifier_block *nb) >> } >> EXPORT_SYMBOL_GPL(unregister_oom_notifier); >> >> +/* >> + * If an oom occurs without the __GFP_FS flag in the gfp_mask, the oom killer >> + * will not be triggered. In this case, we could call schedule_work to run >> + * trigger_oom_killer_work() to trigger an oom forcibly with __GFP_FS flag, >> + * this could make the oom killer run with a fair chance. >> + */ >> +static void trigger_oom_killer_work(struct work_struct *work) >> +{ >> + struct page *tmp_page; >> + >> + /* This could trigger an oom forcibly with a chance */ >> + tmp_page = alloc_page(GFP_KERNEL); >> + if (tmp_page) >> + __free_page(tmp_page); >> +} >> + >> +static DECLARE_WORK(oom_trigger_work, trigger_oom_killer_work); >> + >> /** >> * out_of_memory - kill the "best" process when we run out of memory >> * @oc: pointer to struct oom_control >> @@ -1135,8 +1153,10 @@ bool out_of_memory(struct oom_control *oc) >> * ___GFP_DIRECT_RECLAIM to get here. But mem_cgroup_oom() has to >> * invoke the OOM killer even if it is a GFP_NOFS allocation. >> */ >> - if (oc->gfp_mask && !(oc->gfp_mask & __GFP_FS) && !is_memcg_oom(oc)) >> + if (oc->gfp_mask && !(oc->gfp_mask & __GFP_FS) && !is_memcg_oom(oc)) { >> + schedule_work(&oom_trigger_work); >> return true; >> + } >> >> /* >> * Check if there were limitations on the allocation (only relevant for >> -- >> 2.34.1