From patchwork Wed Mar 16 23:15:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12783258 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 26B0DC4332F for ; Wed, 16 Mar 2022 23:15:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D3536B0072; Wed, 16 Mar 2022 19:15:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9AAC16B0073; Wed, 16 Mar 2022 19:15:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 872E08D0001; Wed, 16 Mar 2022 19:15:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0082.hostedemail.com [216.40.44.82]) by kanga.kvack.org (Postfix) with ESMTP id 784106B0072 for ; Wed, 16 Mar 2022 19:15:07 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2C2D295B10 for ; Wed, 16 Mar 2022 23:15:07 +0000 (UTC) X-FDA: 79251807054.29.064678F Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf08.hostedemail.com (Postfix) with ESMTP id BDB4916000B for ; Wed, 16 Mar 2022 23:15:05 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2DA7DB81C4D; Wed, 16 Mar 2022 23:15:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA1FBC340EC; Wed, 16 Mar 2022 23:15:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1647472504; bh=zNSaguHsQ0Z2gT5BRDht4ZRF2pSwkFvPw/VCK/fS2rU=; h=Date:To:From:In-Reply-To:Subject:From; b=WfHu4NO17kX+/KhtTIvQHFzwpu5wxJJ+ipBYzR5NyJq1qql8RTKchjaSTFWTbkJ2s hAmTBubEv/TovifNCu8wbqskdLRjNga9Xut243aQTJ9qp4z+4A7I/ApL3UTdyEd4S2 Sqe25MYVTXlQlt66X4bcll6swxs6Frct8dIVQO60= Date: Wed, 16 Mar 2022 16:15:03 -0700 To: zealci@zte.com.cn,yang.yang29@zte.com.cn,stable@vger.kernel.org,rogerq@kernel.org,ran.xiaokai@zte.com.cn,naoya.horiguchi@nec.com,minchan@kernel.org,mhocko@kernel.org,jiang.xuexin@zte.com.cn,hughd@google.com,hannes@cmpxchg.org,guo.ziliang@zte.com.cn,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220316161433.5c2e137a69eaee50d2249a27@linux-foundation.org> Subject: [patch 1/4] mm: swap: get rid of deadloop in swapin readahead Message-Id: <20220316231503.DA1FBC340EC@smtp.kernel.org> X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: BDB4916000B X-Stat-Signature: 8dn3q4poos3snqgiydjrm1oy7ng6ec6f Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=WfHu4NO1; dmarc=none; spf=pass (imf08.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-HE-Tag: 1647472505-853525 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: From: Guo Ziliang Subject: mm: swap: get rid of deadloop in swapin readahead In our testing, a deadloop task was found. Through sysrq printing, same stack was found every time, as follows: __swap_duplicate+0x58/0x1a0 swapcache_prepare+0x24/0x30 __read_swap_cache_async+0xac/0x220 read_swap_cache_async+0x58/0xa0 swapin_readahead+0x24c/0x628 do_swap_page+0x374/0x8a0 __handle_mm_fault+0x598/0xd60 handle_mm_fault+0x114/0x200 do_page_fault+0x148/0x4d0 do_translation_fault+0xb0/0xd4 do_mem_abort+0x50/0xb0 The reason for the deadloop is that swapcache_prepare() always returns EEXIST, indicating that SWAP_HAS_CACHE has not been cleared, so that it cannot jump out of the loop. We suspect that the task that clears the SWAP_HAS_CACHE flag never gets a chance to run. We try to lower the priority of the task stuck in a deadloop so that the task that clears the SWAP_HAS_CACHE flag will run. The results show that the system returns to normal after the priority is lowered. In our testing, multiple real-time tasks are bound to the same core, and the task in the deadloop is the highest priority task of the core, so the deadloop task cannot be preempted. Although cond_resched() is used by __read_swap_cache_async, it is an empty function in the preemptive system and cannot achieve the purpose of releasing the CPU. A high-priority task cannot release the CPU unless preempted by a higher-priority task. But when this task is already the highest priority task on this core, other tasks will not be able to be scheduled. So we think we should replace cond_resched() with schedule_timeout_uninterruptible(1), schedule_timeout_interruptible will call set_current_state first to set the task state, so the task will be removed from the running queue, so as to achieve the purpose of giving up the CPU and prevent it from running in kernel mode for too long. (akpm: ugly hack becomes uglier. But it fixes the issue in a backportable-to-stable fashion while we hopefully work on something better) Link: https://lkml.kernel.org/r/20220221111749.1928222-1-cgel.zte@gmail.com Signed-off-by: Guo Ziliang Reported-by: Zeal Robot Reviewed-by: Ran Xiaokai Reviewed-by: Jiang Xuexin Reviewed-by: Yang Yang Acked-by: Hugh Dickins Cc: Naoya Horiguchi Cc: Michal Hocko Cc: Minchan Kim Cc: Johannes Weiner Cc: Roger Quadros Cc: Ziliang Guo Cc: Signed-off-by: Andrew Morton --- mm/swap_state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/swap_state.c~mm-swap-get-rid-of-deadloop-in-swapin-readahead +++ a/mm/swap_state.c @@ -478,7 +478,7 @@ struct page *__read_swap_cache_async(swp * __read_swap_cache_async(), which has set SWAP_HAS_CACHE * in swap_map, but not yet added its page to swap cache. */ - cond_resched(); + schedule_timeout_uninterruptible(1); } /*