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 C17C7C433EF for ; Sat, 26 Feb 2022 01:24:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D83B8D0002; Fri, 25 Feb 2022 20:24:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 485828D0001; Fri, 25 Feb 2022 20:24:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3747B8D0002; Fri, 25 Feb 2022 20:24:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 2A3808D0001 for ; Fri, 25 Feb 2022 20:24:45 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id E5B09120280 for ; Sat, 26 Feb 2022 01:24:44 +0000 (UTC) X-FDA: 79183186488.15.6057776 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf23.hostedemail.com (Postfix) with ESMTP id 3FB34140007 for ; Sat, 26 Feb 2022 01:24:43 +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 dfw.source.kernel.org (Postfix) with ESMTPS id 5DE8B61DD4; Sat, 26 Feb 2022 01:24:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DFBCC340E7; Sat, 26 Feb 2022 01:24:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1645838681; bh=zgGPUxVPsTpIy2I0cC4JKCrYsg0+Z/RpLMyz/fQOXdc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=0lBVT3nlB5B/iU/UTefLiWv7Wvb2JHPpDeZW/IQSNOSJrZsz3lRngCvQqTaXyAIy/ 2nEozshcWrL5nwDcMZgVgNbJFrk2lgOOxwF9kIewlVf4ESaC3RyIPe3WWZkkiW7cOs tKKVhQkTzalPdnnG+9rnUguUVdWvcDdWp+4Q3rGk= Date: Fri, 25 Feb 2022 17:24:40 -0800 From: Andrew Morton To: cgel.zte@gmail.com Cc: naoya.horiguchi@nec.com, mhocko@kernel.org, minchan@kernel.org, hannes@cmpxchg.org, rogerq@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, guo.ziliang@zte.com.cn, Zeal Robot , Ran Xiaokai , Jiang Xuexin , Yang Yang , Hugh Dickins Subject: Re: [PATCH linux-next] mm: swap: get rid of deadloop in swapin readahead Message-Id: <20220225172440.ec62edf97b405d32061bcb37@linux-foundation.org> In-Reply-To: <20220221111749.1928222-1-cgel.zte@gmail.com> References: <20220221111749.1928222-1-cgel.zte@gmail.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 3FB34140007 X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=0lBVT3nl; dmarc=none; spf=pass (imf23.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Stat-Signature: czweizj64bbzmjjphpnn5d4p4djzkosx X-HE-Tag: 1645838683-562 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 Mon, 21 Feb 2022 11:17:49 +0000 cgel.zte@gmail.com wrote: > From: Guo Ziliang > > 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. > > ... > > --- a/mm/swap_state.c > +++ b/mm/swap_state.c > @@ -478,7 +478,7 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, > * __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); > } > > /* Sigh. I guess yes, we should do this, at least in a short-term, backportable-to-stable way. But busy-waiting while hoping that someone else will save us isn't an attractive design. Hugh, have you ever thought about something more deterministic in there? Thanks.