From patchwork Mon Feb 21 11:17:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: CGEL X-Patchwork-Id: 12753459 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 3E0F5C433F5 for ; Mon, 21 Feb 2022 11:17:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 887DB8D0002; Mon, 21 Feb 2022 06:17:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 80FEA8D0001; Mon, 21 Feb 2022 06:17:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BB2F8D0002; Mon, 21 Feb 2022 06:17:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id 55E968D0001 for ; Mon, 21 Feb 2022 06:17:58 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id EA124181D3976 for ; Mon, 21 Feb 2022 11:17:57 +0000 (UTC) X-FDA: 79166537394.23.FEFEC0E Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) by imf02.hostedemail.com (Postfix) with ESMTP id 6CDF280005 for ; Mon, 21 Feb 2022 11:17:57 +0000 (UTC) Received: by mail-qk1-f175.google.com with SMTP id q4so14839436qki.11 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=ICZ2glnIHeU+E0GNFv5N1Mo0A58Pnx66p+uFEnLGmuSeUxPjdMbP2TQwuLoRORFKsK m5ilNtPSQEJeikx6PP5HPrrUa/tuR2Xx6MAxLvawdqpSFT0dR/7+DcPCZekPHe/5X83d 5X7y9oqMqZMOOl6I2B6CmZC8rNoAB8A5/LtNU2ud9LJ0NlxvHu0AChsupBz2H26DPldH WFRs8q3V8iMqpxk0V+Obofe3r+PAEzUb6bOpPHr5udguxtii8iBheMrFOAZ3oJM0A2Cs GBFG9Ds4ZaBod+KTQPEt77/fcgg5wXZ/wZ/ETbCwdyJe+850upAN1+D+5qg8iv0qlh52 7pzg== X-Gm-Message-State: AOAM530BB+gPaQZ3sF+qLzV9ug4UB15ClpYXXBIlXVMIt66jn24raDVF //CL+J2az95gPyLWnbSmtfw= X-Google-Smtp-Source: ABdhPJw/Bm47unRUNrP9rgGjLdOY/XVWlTT1u2FHeFomCD9tLiSyRCmTe3k5zzcSU5hTdLLp9qNZGQ== 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 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 6CDF280005 X-Stat-Signature: afwo4zqnxawoecjuyk95quxpce6tdwph Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=q3wK6oJw; spf=pass (imf02.hostedemail.com: domain of cgel.zte@gmail.com designates 209.85.222.175 as permitted sender) smtp.mailfrom=cgel.zte@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1645442277-871747 X-Bogosity: Ham, tests=bogofilter, spamicity=0.003008, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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); } /*