Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp906981ybv; Wed, 19 Feb 2020 11:40:32 -0800 (PST) X-Google-Smtp-Source: APXvYqyreSdNhUU/w8CriQWvyOxP/FpkQEbnkphk0pOF93XYHI0Z6xHqRu9fYaGUQa/30ahtIB10 X-Received: by 2002:a54:4f14:: with SMTP id e20mr5500793oiy.84.1582141232545; Wed, 19 Feb 2020 11:40:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582141232; cv=none; d=google.com; s=arc-20160816; b=Q7+0wiHR/Of1fWMTLWFaGWX7yMxc9ypCVQco6K6xwDBR2UQiskPYwIPXqnt2aI1RNb 3RNPyI8MtRhy5cWCP+VYVY8Yb23JLOscL7fw4OlwlJCtHPSvnKOifA2jUg+XoUx3SJxv 2/DYInP6DrZWF0pP9uTqOkT7jFfH9ZurZELMctVMmM+5k52BN/RYy4dGJEHeDFOZ7+Ra arew+CDXqa+1TSyZfkGwEhHcFGTToBf0penzGhBVkozI2aWvwBc3sULKV7nHTe5NYy9Z yIHA8Pxna0c7URdkJ95G7SCbCnH3Q0tLLJOQ9x6R04o6CsGzfY6bb+8j3PQxz3eDCVfn r2hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=xk3FQWFLEA9Ivw7eQtk1E45ebBr0l+OsXJaKdMkwewM=; b=hkrbBo7WDexc5J2uqEvHFbn2uGhyS/UccaSrCszDLfqU1pB2EL4mmTGyjOkSOqtEfR X6N/5j/rUqNiG0uehrfHF0XNEE7QR8EuQ5TYMeHq9gYnxLUby70oOn0ipWwHBCImH0So Z6DTzUrx0hQa9Aw11HkMJVWmJ5ankLbUp0Or2MCntPtxB50Jf9W3E5SUaibRwrMgcPkG CyUJ8KwmhBxBs9cMfQqJPsDgn+qwO90vn0sAUwYRs8jPv8qPA1ukh8Du3SSfVjPPHRfy 2yQFENxghmugROlF8HjedwST5gkNH1TZX1nos8fPDEO9WcmkDyeGQoDhYZG99aGSfLuu bDvg== 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 o25si412871otk.28.2020.02.19.11.40.19; Wed, 19 Feb 2020 11:40:32 -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 S1726750AbgBSTkJ (ORCPT + 99 others); Wed, 19 Feb 2020 14:40:09 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:35329 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726648AbgBSTkJ (ORCPT ); Wed, 19 Feb 2020 14:40:09 -0500 Received: by mail-pg1-f194.google.com with SMTP id v23so617684pgk.2 for ; Wed, 19 Feb 2020 11:40:09 -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=xk3FQWFLEA9Ivw7eQtk1E45ebBr0l+OsXJaKdMkwewM=; b=BNI586195ZP8T82iJbf2C4Sl/o1HqxAbd92AUN1QIWxx/EXBfK0Kx5AAqhzBsK5w6G vW4oKRzRhSyJALzQHRUNoG4KPFMuwBitA9QxGC0C7gjDbvRsegbsENC53K+RBZjhF5Pc 5UHu0dkbmzl5MzdUfqhL+bjD8jdPGZupUj+NtjSveDhBwAKYi9pYOuztaIYPCZrYYPrn IPiSd9cRyXY9GIlA3kfHVJKkW4hsvOkBAXzTSIKmr47j7f9VPte8C22mxpAfKwr7fk5d Zf1mFi3cbLU4loFzzgW0XOz7SHn3VKeX18i22iwJxgyjeOAeJPBpKvuHMSltnAyh8QZG R0sA== X-Gm-Message-State: APjAAAUdpn/KP1FkNSF45ZrC24Xyyf5bztHWvM9CdV6bXegO8+q9Lg4z CmydayL7zQND9/9EnMtsuAw= X-Received: by 2002:a62:486:: with SMTP id 128mr28636963pfe.236.1582141208801; Wed, 19 Feb 2020 11:40:08 -0800 (PST) Received: from sultan-book.localdomain ([104.200.129.62]) by smtp.gmail.com with ESMTPSA id c8sm510530pgq.30.2020.02.19.11.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 11:40:08 -0800 (PST) Date: Wed, 19 Feb 2020 11:40:06 -0800 From: Sultan Alsawaf To: Dave Hansen Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: Stop kswapd early when nothing's waiting for it to free pages Message-ID: <20200219194006.GA3075@sultan-book.localdomain> References: <20200219182522.1960-1-sultan@kerneltoast.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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. > > 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. On a constrained system I tested (mem=2G), this patch had the positive effect of improving overall responsiveness at high memory pressure. 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). Sultan