Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp736194pxm; Fri, 25 Feb 2022 18:44:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJxUYIsnm/nV46Y/IjAa0yZOPujlJtdMA4XVZePzvdLbkp3N415nwda5DqkNFxVBZwHMZ6AY X-Received: by 2002:a17:90a:6944:b0:1bc:40a0:a12d with SMTP id j4-20020a17090a694400b001bc40a0a12dmr6081568pjm.138.1645843454678; Fri, 25 Feb 2022 18:44:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645843454; cv=none; d=google.com; s=arc-20160816; b=QISN+21Zw/7yGrz83N893RIJwCeYiwIFNFFGvni+h2L/6w8bGRqYmmAf+CdfX+mqr8 BFOenkxhlC04Rk/ZdAF5kAZJIw8L2wZ09xqG+b8KREWf4xZ1zpXXrie5/vhkyOri3oIQ rVZvCJo42IdKxdItKoH5ZF37qJSSvljMu7CmLWJbyZ6IlfrK8fCLnS2ngMnENgMFr5/5 oYUvpJnjB2d9TbA1xhkODXHckok1cEuk4xfbd8wEz4U1kmsW2y9Y4uaDkJf0wc7r9oYq nz1hQbyVH5vEqYLsqOycM0ujF+vMox0p3acZ+LPciByZBT7wfqcGRPrsjPtavI+xLLlP gPPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=HnJGqsLzYlU6xp/Y4v2qwpIolt+KuAqKSLvawSlQP24=; b=ZHIsvshM915I9UWTJ2LO+tymEi0PZqy8Md8cJtKiFqMcm4qG1KWOqn48vqARMFWb6q iIHOAwJH7FVMl9s7xWWh1XFORo8SOisF5CjD7biKU2YO11WNVjf3sK6pxXLAqblo9yxW KYtYAzNdupDx5MrYxf9V5IwKQR3f5PXY/QtwC65HlTJAxd/diDsyhIcR4NDLgIJ1nSv4 Q58tbwige0MmUYzF4p5BF3862UtZnc9pZYsJwCwq+xi4UANdcgZrigzbOiwdCB/AE1wM zxvHyo6ekE/R69QMTg2xwCoNkc7PjWmKYAFinB8znXQpUJtOexjcyVGbb0lNwUjZTlMe CtmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=0lBVT3nl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e38-20020a635026000000b00373a7aa924dsi3522681pgb.127.2022.02.25.18.44.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 18:44:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=0lBVT3nl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B609724EA05; Fri, 25 Feb 2022 18:07:57 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230103AbiBZBZR (ORCPT + 99 others); Fri, 25 Feb 2022 20:25:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbiBZBZP (ORCPT ); Fri, 25 Feb 2022 20:25:15 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2AACBD7CB for ; Fri, 25 Feb 2022 17:24:42 -0800 (PST) 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 6C9DE61DFB for ; 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-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.