Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4444858pxb; Mon, 21 Feb 2022 21:50:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJy324bLYSfBAOEImV2QnxBMEgsVnmI6h0/Nlfrv0MXwL8nVTzqMWMhJxMtcYDzhkZ28Qbax X-Received: by 2002:a63:6785:0:b0:364:3dc6:27a8 with SMTP id b127-20020a636785000000b003643dc627a8mr18912439pgc.276.1645509031199; Mon, 21 Feb 2022 21:50:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645509031; cv=none; d=google.com; s=arc-20160816; b=xwn3Mu+Us/H1jDCL0TOK2HAG2NWWsN2kc1Yb0n2DHFyZRdkgoQPhAPA7Lw4H7gebp9 arU4VAuLCnDhuUwqjFfkNthLmCqV+ROzhLwvkYuT9DlMSk2XMkgZixAJ/9f80Wjq9Ien 5bN6M3uLFhbB+spud/S2sepuzPINyTfMtonpQ7WV29oIkFoyiOSDIigDU78T9V4ulh5d llbPwmvtglAqWdOL3Uhrsa6YdWDznlcIUHTdpZKl0wWxzNCdZC5dMwDgU4JyIvp7ZTjr Chp+0b5FuRKoWxt5Ei2SfiAdfKCRPO2XuiNzCO5t0MAl1eSbTxPIx2af31yzuhwVFmtv OcJA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=xlXsGRli3ze1+3F4Fxu+m92oWVroAjRttnPUA7W+HAk=; b=GvCsiOZjzxW5iJ6iCFlv15FPS4HVwFN8pa+m2Y5IgJSyqhsNa8do7IigUcudVSSBzo FZSO/sEVozGy0JCd4JAWTSDf7Pk+Vb/OY86TPNYBRawzjKRcClC3DBgMKE3Z3xEYvWyg O+VIAax9GnwAqiSOfNlxG6MfP4NteSaW85Tp64a2R7yrA5cPiVEUNKfu6u7cWCRx54ua EnSK/DhblKbC4lei97aoNTWTGaVzoBraEKD3sb288PVpD4elTxFqt4KGssTkTQb18i/g PQfCIkbUPDs2OJUM376RgsEd5cAXD3pKUpvglDbbARvZ1/EMgiqtm7lrM2z6W/6zJI4Y ZswA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=q3wK6oJw; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s9si31736038plg.193.2022.02.21.21.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:50:31 -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=@gmail.com header.s=20210112 header.b=q3wK6oJw; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AAE411354B9; Mon, 21 Feb 2022 21:14:10 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231793AbiBULYJ (ORCPT + 99 others); Mon, 21 Feb 2022 06:24:09 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356168AbiBULXp (ORCPT ); Mon, 21 Feb 2022 06:23:45 -0500 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 848D57655 for ; Mon, 21 Feb 2022 03:17:57 -0800 (PST) Received: by mail-qk1-x72e.google.com with SMTP id j78so11556330qke.2 for ; Mon, 21 Feb 2022 03:17:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xlXsGRli3ze1+3F4Fxu+m92oWVroAjRttnPUA7W+HAk=; b=q3wK6oJwVAEXOYSs60uAl84AdwpFF9NoNjhqogmvF8J2uyXxbK7hiF5qnDkWi5Onzi iojv7hOY31rbmk6DHbUkrAMr4AhfUZdTy5NoLhiNrASfnrkbvRjExvP/AOJeIQLL2eI7 pb/wkDqOAYiylzAqOWd+KLWDI8ZHSAJfTeztt7Fu5UxM0kzdJScKnF2rQz6R+FHNwzLY Y6OVRQ/UPlpEeopxKBON1qG6sBqHCWOaBTbf25Vq1+ke/k2ME0rknt+wqWFGdGJcbE0G 81wVcuG2N4TbVy21kU08v7mJHRdsoUs7NGEL6mMLmQvZjZuHcHmVhUuTUZenMerArWJq wM6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xlXsGRli3ze1+3F4Fxu+m92oWVroAjRttnPUA7W+HAk=; b=DleQPyXSlMSMwIXSF7ObOdZIEuiWbwz8djVy3Mdrnn7YeHWmklASC1MpZcyO2gtR1k dsTbEBQR2Rm+pAtEQmJli2anZHe54EPAQW+fhW8EPH9eY+ZOgQyLZ/KRFtQV/XHkjbAK s31imtwz+yS8qWpi7hN276Y4rrJo28NzJowi9KCicCRHwz5xkEKCl3wYfgnHseAqqtfE SSH0okaOCosSwaCPfJou5v0Qm4UeDiE7mRbLqyKK2sq5WVFvx5vhZjmNrzjr++SB8dsr ASj6UpSm9G8h5cIEWVhgJsZ+e64DHu12zSdw0ccdy/9ZmOwnmK59FHj3CPzEPmETYLYv e8tw== X-Gm-Message-State: AOAM5303w4kzx6rOVBXmag+vL0reo1IiMCdyxNRBW+M0KtwKvC2flvuT ddkWLkeXvBw8qZPm5OqExZA= X-Received: by 2002:a37:cd3:0:b0:5f1:707d:78b9 with SMTP id 202-20020a370cd3000000b005f1707d78b9mr11441751qkm.394.1645442276720; Mon, 21 Feb 2022 03:17:56 -0800 (PST) Received: from localhost.localdomain ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id j4sm10622085qtp.65.2022.02.21.03.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 03:17:56 -0800 (PST) From: cgel.zte@gmail.com To: akpm@linux-foundation.org, naoya.horiguchi@nec.com, mhocko@kernel.org, minchan@kernel.org, hannes@cmpxchg.org Cc: 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 Subject: [PATCH linux-next] mm: swap: get rid of deadloop in swapin readahead Date: Mon, 21 Feb 2022 11:17:49 +0000 Message-Id: <20220221111749.1928222-1-cgel.zte@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 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. Reported-by: Zeal Robot Reviewed-by: Ran Xiaokai Reviewed-by: Jiang Xuexin Reviewed-by: Yang Yang Signed-off-by: Guo Ziliang --- mm/swap_state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index 8d4104242100..ee67164531c0 100644 --- 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); } /* -- 2.15.2