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 83E4EC4332F for ; Fri, 18 Nov 2022 21:27:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFADF6B0071; Fri, 18 Nov 2022 16:27:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A849E6B0072; Fri, 18 Nov 2022 16:27:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 924978E0001; Fri, 18 Nov 2022 16:27:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 809A46B0071 for ; Fri, 18 Nov 2022 16:27:44 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4C2D6C060E for ; Fri, 18 Nov 2022 21:27:44 +0000 (UTC) X-FDA: 80147850048.13.980DE26 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf17.hostedemail.com (Postfix) with ESMTP id E081540002 for ; Fri, 18 Nov 2022 21:27: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 0A23662781; Fri, 18 Nov 2022 21:27:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29640C433D6; Fri, 18 Nov 2022 21:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1668806862; bh=RKeUbLAWkAqKAQpRa/aMhHUQToW5rk/wNnEtKf8AAVs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=AHI++KLcg8f1oKeTyVJj9GgaijJqkIhGCizaWFzcfqfKY2Na6sQIY8Rv/9j6Dlnp2 PCy1lMm98PDg76enX/+l1cj3fSgb4vf1ZSWgQaiGwTESXq2ViX5/xhK05feuKPEMcb 0zs/sY66agmdTG8jixrCs7AyIZFi7lqGyH6tqnso= Date: Fri, 18 Nov 2022 13:27:41 -0800 From: Andrew Morton To: Chen Wandun Cc: , , , , , , Huang Ying Subject: Re: [RFC PATCH] swapfile: fix soft lockup in scan_swap_map_slots Message-Id: <20221118132741.aaf6f9081b5a1018cc9a5402@linux-foundation.org> In-Reply-To: <20221118133850.3360369-1-chenwandun@huawei.com> References: <20221118133850.3360369-1-chenwandun@huawei.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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668806864; a=rsa-sha256; cv=none; b=Tx2KlW5SQ/UCT14uP6ar9zCQ/PBP7IL/K+tPFdN28aB8p0VX/lFGmB/kwnJeFofLY+mgSd 59Yuweviriy7bP2dbMKHtL7Hi5Rs9+RNhXJhOWINOdAj0E3qX1gaoyLouV5qYCMtOvKXl6 EONSuhs8yt1MZDrlAOx3ivQHnXaFTok= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=AHI++KLc; spf=pass (imf17.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668806864; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CyExldfbrsqWBNGdEWi4FK0cXws7x5ZfaRqkvG0GwxY=; b=KmD+XAemj/kqyzNANmUp+fGvQ7D0YJ0iSyULXNu+viHUGvyVazhO6ya1R+7MlnVFhEjSsG 0oKG3suQeGJuYpuGRv78+sAk16kbHo5jm23EhP/MbyHaVedbnVd5QZfgXjZ+APpBithQgz jGXolr4x56AP+HFQ9hXQg13Wqnd6JHg= Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=AHI++KLc; spf=pass (imf17.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E081540002 X-Rspam-User: X-Stat-Signature: frdjc7igyb4ryqeduse5z5ug59sen7bu X-HE-Tag: 1668806863-516795 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 Fri, 18 Nov 2022 21:38:50 +0800 Chen Wandun wrote: > A soft lockup occur in scan free swap slot by constructing > huge memory pressure. > The test scenario is: 64 CPU cores, 64GB memory, and 28 > zram devices, the disksize of each zram device is 50MB. > > LATENCY_LIMIT is used to prevent soft lockup in function > scan_swap_map_slots, but the real loop number would more > than LATENCY_LIMIT because of "goto checks and goto scan" > repeatly without decrease of latency limit. > > In order to fix it, move decrease latency_ration code in advance. > > There is also a suspicious place that will cause soft lockup in > function get_swap_pages, in this function, the "goto start_over" > may result in continuous scanning of swap partition, if there is > no cond_sched in scan_swap_map_slots, it would cause soft lockup > (I am not sure about this). > > ... > Looks sensible. > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -972,23 +972,23 @@ static int scan_swap_map_slots(struct swap_info_struct *si, > scan: > spin_unlock(&si->lock); > while (++offset <= READ_ONCE(si->highest_bit)) { > - if (swap_offset_available_and_locked(si, offset)) > - goto checks; > if (unlikely(--latency_ration < 0)) { > cond_resched(); > latency_ration = LATENCY_LIMIT; > scanned_many = true; > } > + if (swap_offset_available_and_locked(si, offset)) > + goto checks; > } > offset = si->lowest_bit; > while (offset < scan_base) { > - if (swap_offset_available_and_locked(si, offset)) > - goto checks; > if (unlikely(--latency_ration < 0)) { > cond_resched(); > latency_ration = LATENCY_LIMIT; > scanned_many = true; > } > + if (swap_offset_available_and_locked(si, offset)) > + goto checks; > offset++; > } > spin_lock(&si->lock); But this does somewhat alter the `scanned_many' logic. We'll now set 'scanned_many` earlier. What are the effects of this? The ed43af10975eef7e changelog outlines tests which could be performed to ensure we aren't regressing from this.