Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CCAFC34056 for ; Wed, 19 Feb 2020 20:05:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 54234207FD for ; Wed, 19 Feb 2020 20:05:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 54234207FD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 031E86B0006; Wed, 19 Feb 2020 15:05:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F24C06B0007; Wed, 19 Feb 2020 15:05:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3AAB6B0008; Wed, 19 Feb 2020 15:05:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0106.hostedemail.com [216.40.44.106]) by kanga.kvack.org (Postfix) with ESMTP id CCB376B0006 for ; Wed, 19 Feb 2020 15:05:31 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 930D9824999B for ; Wed, 19 Feb 2020 20:05:31 +0000 (UTC) X-FDA: 76507956462.14.test08_6a5f0381f4c5b X-HE-Tag: test08_6a5f0381f4c5b X-Filterd-Recvd-Size: 5303 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Wed, 19 Feb 2020 20:05:30 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id z3so2058836wru.3 for ; Wed, 19 Feb 2020 12:05:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=9QZaWm6tm+vk1ztWHlhdEgHBJhECaJCRQq7v49/23SM=; b=fQcSOHvSHWRRjw65nPgK7dv2LEf7jLX7lom2rlCWS151NCPn8vIBMY6AZXWNddkFt7 uqIdKKMZrPqg+aHCwaDyBwZ7TkJHrC8PMERpxZhUD9m9Ep/MqEhfP4+T/UBK35aD+mS4 XIB7q8PNdeM44DFMYMgE/E9VJOAy8x6Gu0ffrzT0/T08vOMceyOEFMOwUxg7gETIdf1G 0dNrJ3wnXHyjX1GFY7LcY/SWlSVoLpAuYdYLzFo6KevCf7JJ6EgZ62XTmW/cCn7gtSAU kQu9N1nzmbkjDCcuRxUQsVFxgIkIbouzYF86VnLdtMvCdjaqCLHU3g6fh5eyj6AanXmm IIsw== X-Gm-Message-State: APjAAAVx6XzoULZTEnFbU2+1Sm3DLgGtSpSteVEd8uUlTqVkCVWa/2F+ CYW5olnk9LFWs8YBxNjhumA= X-Google-Smtp-Source: APXvYqwdo3/b888DT9z4zeiJK6HdstVQrqV0Q2qZiwl4mCTXqtkY08/Ulkfcg5vfITd0j88zfiuvCQ== X-Received: by 2002:adf:f484:: with SMTP id l4mr39326744wro.207.1582142729697; Wed, 19 Feb 2020 12:05:29 -0800 (PST) Received: from localhost (ip-37-188-133-21.eurotel.cz. [37.188.133.21]) by smtp.gmail.com with ESMTPSA id a8sm1117642wmc.20.2020.02.19.12.05.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 12:05:28 -0800 (PST) Date: Wed, 19 Feb 2020 21:05:27 +0100 From: Michal Hocko To: Sultan Alsawaf Cc: Dave Hansen , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mel Gorman , Johannes Weiner Subject: Re: [PATCH] mm: Stop kswapd early when nothing's waiting for it to free pages Message-ID: <20200219200527.GF11847@dhcp22.suse.cz> References: <20200219182522.1960-1-sultan@kerneltoast.com> <20200219194006.GA3075@sultan-book.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200219194006.GA3075@sultan-book.localdomain> 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: [Ups, for some reason I have missed Dave's response previously] On Wed 19-02-20 11:40:06, Sultan Alsawaf wrote: > On Wed, Feb 19, 2020 at 11:13:21AM -0800, Dave Hansen wrote: > > On 2/19/20 10:25 AM, Sultan Alsawaf wrote: > > > Keeping kswapd running when all the failed allocations that invoked it > > > are satisfied incurs a high overhead due to unnecessary page eviction > > > and writeback, as well as spurious VM pressure events to various > > > registered shrinkers. When kswapd doesn't need to work to make an > > > allocation succeed anymore, stop it prematurely to save resources. > > > > But kswapd isn't just to provide memory to waiters. It also serves to > > get free memory back up to the high watermark. This seems like it might > > result in more frequent allocation stalls and kswapd wakeups, which > > consumes extra resources. Agreed as expressed in my other reply > > I guess I'd wonder what positive effects you have observed as a result > > of this patch and whether you've gone looking for any negative effects. > > This patch essentially stops kswapd from going overboard when a failed > allocation fires up kswapd. Otherwise, when memory pressure is really high, > kswapd just chomps through CPU time freeing pages nonstop when it isn't needed. Could you be more specific please? kspwad should stop as soon as the high watermark is reached. If that is not the case then there is a bug which should be fixed. Sure it is quite possible that kswapd is busy for extended amount of time if the memory pressure is continuous. > On a constrained system I tested (mem=2G), this patch had the positive effect of > improving overall responsiveness at high memory pressure. 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? > On systems with more memory I tested (>=4G), kswapd becomes more expensive to > run at its higher scan depths, so stopping kswapd prematurely when there aren't > any memory allocations waiting for it prevents it from reaching the *really* > expensive scan depths and burning through even more resources. > > Combine a large amount of memory with a slow CPU and the current problematic > behavior of kswapd at high memory pressure shows. My personal test scenario for > this was an arm64 CPU with a variable amount of memory (up to 4G RAM + 2G swap). But still, somebody has to put the system into balanced state so who is going to do all the work? -- Michal Hocko SUSE Labs