Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp999649ybv; Wed, 19 Feb 2020 13:45:42 -0800 (PST) X-Google-Smtp-Source: APXvYqy7ER7GMUvlpXFveh6K1gwO/2PzeBguwiteNxmLOYaPfqZ4UBzl63XUKUhP8mtG7274hdbv X-Received: by 2002:a05:6830:124b:: with SMTP id s11mr20660340otp.333.1582148741870; Wed, 19 Feb 2020 13:45:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582148741; cv=none; d=google.com; s=arc-20160816; b=umG4aAoADqpyN2C5SjgG0EmP26pyOFw0l4rC5KO96lXy5ZswUh69lpT4vuHDiE67tp Jo311WkQyTj9HBCTkZ0bnIfHKRo9YrV++pJ4LPk7P58db7qQ2t2kYV2WfuSgowLWXV9A CjB5bLyjnUsHNw5qPPLXr6FtVGNRdJ/daP6V09jonmIXVUsARyZ7qjTbG7xNlHTv53rZ uRl1WveHs+zjMJZBlz24NZWEUhBhuAy2A0NQv5WSQq+/EcpzcONCii14mt7YngHzIlti Zx9F9eTJyXK31B4fxciEbA4hnZqaqClMST2G+MoxUifr/khYkY9Ejmqwue1UsTq+jwLK fSZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Tdnhevywod00VC4Q6xwvZyhtkYKnC1hlJ3i5tgrfmLQ=; b=Xms36w/2NuKAx/Z2M8KevrOeLj1UpVwtyQXnae98TObclTC1pkcS1Gsp3HG44OBL5w 6nlUpMl/i4QSXkG1//EqVGjbSFIyJ2JCWcSwxPeBVNpKpw7Bm6vvCl99k+Bju0L5UKvp oeG8cdeo00OC65tNJ3gWtYauBOolcb/P7lRJXnnb99KuNI8nKC8tmKfJ5RHbAwwph7yz +zPKoXQYX5E4qVGLi6Ec7t2/kwJYgg4kCNXFqIc77cqTpmv6qoERQFxE4vJuJBfU+k4i Ue72FkDh5O0BE516UjEVetFlQy5j989i4TTBdfTjy+iBXgwOVtaB2XsDllwkVGojhA0H qCAA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l11si575203otn.189.2020.02.19.13.45.30; Wed, 19 Feb 2020 13:45:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726760AbgBSVpU (ORCPT + 99 others); Wed, 19 Feb 2020 16:45:20 -0500 Received: from mx2.suse.de ([195.135.220.15]:59618 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727469AbgBSVpT (ORCPT ); Wed, 19 Feb 2020 16:45:19 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 13A39AF2D; Wed, 19 Feb 2020 21:45:17 +0000 (UTC) Date: Wed, 19 Feb 2020 21:45:13 +0000 From: Mel Gorman To: Sultan Alsawaf Cc: Michal Hocko , Dave Hansen , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Johannes Weiner Subject: Re: [PATCH] mm: Stop kswapd early when nothing's waiting for it to free pages Message-ID: <20200219214513.GL3420@suse.de> References: <20200219182522.1960-1-sultan@kerneltoast.com> <20200219194006.GA3075@sultan-book.localdomain> <20200219200527.GF11847@dhcp22.suse.cz> <20200219204220.GA3488@sultan-book.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <20200219204220.GA3488@sultan-book.localdomain> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 19, 2020 at 12:42:20PM -0800, Sultan Alsawaf wrote: > > Again, do you have more details about the workload and what was the > > cause of responsiveness issues? Because I would expect that the > > situation would be quite opposite because it is usually the direct > > reclaim that is a source of stalls visible from userspace. Or is this > > about a single CPU situation where kswapd saturates the single CPU and > > all other tasks are just not getting enough CPU cycles? > > The workload was having lots of applications open at once. At a certain point > when memory ran low, my system became sluggish and kswapd CPU usage skyrocketed. > I added printks into kswapd with this patch, and my premature exit in kswapd > kicked in quite often. > This could be watermark boosting run wild again. Can you test with sysctl vm.watermark_boost_factor=0 or the following patch? (preferably both to compare and contrast). diff --git a/mm/vmscan.c b/mm/vmscan.c index 572fb17c6273..71dd47172cef 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3462,6 +3462,25 @@ static bool pgdat_balanced(pg_data_t *pgdat, int order, int classzone_idx) return false; } +static void acct_boosted_reclaim(pg_data_t *pgdat, int classzone_idx, + unsigned long *zone_boosts) +{ + struct zone *zone; + unsigned long flags; + int i; + + for (i = 0; i <= classzone_idx; i++) { + if (!zone_boosts[i]) + continue; + + /* Increments are under the zone lock */ + zone = pgdat->node_zones + i; + spin_lock_irqsave(&zone->lock, flags); + zone->watermark_boost -= min(zone->watermark_boost, zone_boosts[i]); + spin_unlock_irqrestore(&zone->lock, flags); + } +} + /* Clear pgdat state for congested, dirty or under writeback. */ static void clear_pgdat_congested(pg_data_t *pgdat) { @@ -3654,9 +3673,17 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx) if (!nr_boost_reclaim && balanced) goto out; - /* Limit the priority of boosting to avoid reclaim writeback */ - if (nr_boost_reclaim && sc.priority == DEF_PRIORITY - 2) - raise_priority = false; + /* + * Abort boosting if reclaiming at higher priority is not + * working to avoid excessive reclaim due to lower zones + * being boosted. + */ + if (nr_boost_reclaim && sc.priority == DEF_PRIORITY - 2) { + acct_boosted_reclaim(pgdat, classzone_idx, zone_boosts); + boosted = false; + nr_boost_reclaim = 0; + goto restart; + } /* * Do not writeback or swap pages for boosted reclaim. The @@ -3738,18 +3765,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int classzone_idx) out: /* If reclaim was boosted, account for the reclaim done in this pass */ if (boosted) { - unsigned long flags; - - for (i = 0; i <= classzone_idx; i++) { - if (!zone_boosts[i]) - continue; - - /* Increments are under the zone lock */ - zone = pgdat->node_zones + i; - spin_lock_irqsave(&zone->lock, flags); - zone->watermark_boost -= min(zone->watermark_boost, zone_boosts[i]); - spin_unlock_irqrestore(&zone->lock, flags); - } + acct_boosted_reclaim(pgdat, classzone_idx, zone_boosts); /* * As there is now likely space, wakeup kcompact to defragment