Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp873252ybh; Wed, 11 Mar 2020 12:32:52 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtD8b7CarHBbCf60t6MocHmDyZxOS1sTE3T1+u9gZDs/6eQPLcVAWBeoXRTBDcMVSHY+G6i X-Received: by 2002:a9d:336:: with SMTP id 51mr3553754otv.202.1583955171940; Wed, 11 Mar 2020 12:32:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583955171; cv=none; d=google.com; s=arc-20160816; b=0bdPrA7SMgAUMBE+5qMLiegPHHyfV5IHph8NPtkayVrkOyL1nh0SH95n9bvMfVXVJF fky5M8gZPhgtUm1vtGf+X6FIdVXaNr5AIBl6bnhUIsOz8EFtigphTp1D7nvRk9y+BZrt FZKeYaLvd8epIYVRR0J4eFinR/nHqNi+qKv8ZxyG8eCsZrpbL1A7Ug8SF8FEg8/4xl70 o4jUDtMm+HOEZneHkR/5dOYZajUPM3hYvjOkJ/lbL+YHmRzOqaPKh8FsT747WAmOJl08 oor2iPUE0pjkpYvn446ZgLa4ulMd86LmpR6WzqsuPJy5Ph8S7LUGS5VFp7X7blZCf8Al +CaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=nrr0UrVgn5X3zlkkY/AvuhDFOpNyA1sBfPxPwX99Zio=; b=iBWPfXkrXdSrI0qXId+3loIvYxeD9v8OM0o4Jzh7LlOao/Z/yUZxwAGq2hIfX/OYpN AvpCS1w/8NFKsHRlvx25XZok8EXhaBXB1m716pn+BKw2XEdobdFQw/IcAlqy2AIb3o16 kpWuYHWZ3S5p/cJvmyCAQdEgh6vR0vWIZ7kcdsfCl7m0uS8CD0NcCpqu/WoA3vYHOYH5 k/nW6o7IaxpAN1T4iBxyV0pkxwmqpWUESlb9MphIppO2cSQ6WP8W+v08epcqiidoC4IQ zCecBQLzzhTKgf3lbmch9ME+t4whK5Jt6Pw5tfkv6nclN6e9OtuslYmgKxahS0tlN+L0 0koA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=DWMg+i0R; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s207si1532260oih.255.2020.03.11.12.32.22; Wed, 11 Mar 2020 12:32:51 -0700 (PDT) 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; dkim=pass header.i=@google.com header.s=20161025 header.b=DWMg+i0R; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731097AbgCKTb6 (ORCPT + 99 others); Wed, 11 Mar 2020 15:31:58 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40795 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730705AbgCKTb5 (ORCPT ); Wed, 11 Mar 2020 15:31:57 -0400 Received: by mail-pf1-f196.google.com with SMTP id l184so1892128pfl.7 for ; Wed, 11 Mar 2020 12:31:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=nrr0UrVgn5X3zlkkY/AvuhDFOpNyA1sBfPxPwX99Zio=; b=DWMg+i0RW/xutS/C0lrLv5qkdOkRJdJrd7AEzJ+nhuFzo5UDID2I7osmZjKepfTMG4 QQ67+/sCPNIZ7NiaU8mRmDgy1xa+7fBGAeZZZkoTx0ai5DVbYNyxHYdGOZP0auhU1pUF UePGYNNb68RUudvV922Q5HtVehqC2USEIk+jpbQq+gqi7fI8y+o1huJ0sJdj4YlbDaNc a+tkRUGnWS+VXaa4CUwX7hR+D1hdRnZIhTJ92Lgzzk3/jj1uAGlq0dC5KMSpGWJr/Wmn sId2NEwJHNKE/JOvxQjgupkfsriJZ9/JR7Q0YcDQmyz76MrrEKq3+0syQOUAMb6O47t8 CX2Q== 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:in-reply-to:message-id :references:user-agent:mime-version; bh=nrr0UrVgn5X3zlkkY/AvuhDFOpNyA1sBfPxPwX99Zio=; b=XJUvYkuFLIHYQw1qZbPXPDumUmJFAkj1kIisaTglSWQjyg8WuJhX3Qe2cu3Spdbh+s xDA5a12iAUXGaGBpWjQZUpwDiDlJgl+8QGrii0/N/qviPZXu1BJ9I+2abAngYH1X4Edf BgB9kF06iEaUDfV117rUBbWEXPhaN7T9t6xI/trhVfjGj2tq3masY91LtHX7DDgkVlHT 8LjqxcC7JoaE0JvGa6vDc5pZEuuhMhnGljQXKfn/BTJjpsDBffeR5n99eCPoBGu4yydh plTxRyFd0KfGK3FBMzBGGHERAbxxbPvl9UTrqcd+1POOU2rephZSptScbkREdhBBCpNF UYcg== X-Gm-Message-State: ANhLgQ2ETs5dTj5nfaMg0NnkEoIelwDkdHA65Ln57PRZFFL01PMeJksh m0v7h3Mrrt+1SZQq2Jmamjq/DQ== X-Received: by 2002:a62:7f8f:: with SMTP id a137mr4368557pfd.145.1583955115898; Wed, 11 Mar 2020 12:31:55 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id k20sm29707459pfk.123.2020.03.11.12.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2020 12:31:54 -0700 (PDT) Date: Wed, 11 Mar 2020 12:31:53 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Ivan Teterevkov cc: "corbet@lwn.net" , "akpm@linux-foundation.org" , "mchehab+samsung@kernel.org" , "tglx@linutronix.de" , "jpoimboe@redhat.com" , "pawan.kumar.gupta@linux.intel.com" , "jgross@suse.com" , "oneukum@suse.com" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" Subject: Re: [PATCH] mm/vmscan: add vm_swappiness configuration knobs In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 11 Mar 2020, Ivan Teterevkov wrote: > This patch adds a couple of knobs: > > - The configuration option (CONFIG_VM_SWAPPINESS). > - The command line parameter (vm_swappiness). > > The default value is preserved, but now defined by CONFIG_VM_SWAPPINESS. > > Historically, the default swappiness is set to the well-known value 60, > and this works well for the majority of cases. The vm_swappiness is also > exposed as the kernel parameter that can be changed at runtime too, e.g. > with sysctl. > > This approach might not suit well some configurations, e.g. systemd-based > distros, where systemd is put in charge of the cgroup controllers, > including the memory one. In such cases, the default swappiness 60 > is copied across the cgroup subtrees early at startup, when systemd > is arranging the slices for its services, before the sysctl.conf > or tmpfiles.d/*.conf changes are applied. > Seems like something that can be fully handled by an initscript that would set the sysctl and then iterate the memcg hierarchy propagating the non-default value. I don't think that's too much of an ask if userspace wants to manipulate the swappiness value. Or maybe we can be more clever: have memcg->swappiness store -1 by default unless it is changed by the user explicitly and then have mem_cgroup_swappiness() return vm_swappiness for this value. If the user overwrites it, it's intended. So there are a couple options here but I don't think one of them is to add a new config option or kernel command line option. > One could run a script to traverse the cgroup trees later and set the > desired memory.swappiness individually in each occurrence when the runtime > is set up, but this would require some amount of work to implement > properly. Instead, why not set the default swappiness as early as possible? > > Signed-off-by: Ivan Teterevkov > --- > .../admin-guide/kernel-parameters.txt | 4 ++++ > mm/Kconfig | 10 ++++++++ > mm/vmscan.c | 24 ++++++++++++++++++- > 3 files changed, 37 insertions(+), 1 deletion(-) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index c07815d230bc..5d54a4303522 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -5317,6 +5317,10 @@ > P Enable page structure init time poisoning > - Disable all of the above options > > + vm_swappiness= [KNL] > + Sets the default vm_swappiness. > + Ranges from 0 to 100, the default value is 60. > + > vmalloc=nn[KMG] [KNL,BOOT] Forces the vmalloc area to have an exact > size of . This can be used to increase the > minimum size (128MB on x86). It can also be used to diff --git a/mm/Kconfig b/mm/Kconfig index ab80933be65f..ec59c19e578e 100644 > --- a/mm/Kconfig > +++ b/mm/Kconfig > @@ -739,4 +739,14 @@ config ARCH_HAS_HUGEPD config MAPPING_DIRTY_HELPERS > bool > > +config VM_SWAPPINESS > + int "Default memory swappiness" > + default 60 > + range 0 100 > + help > + Sets the default vm_swappiness, that could be changed later > + in the runtime, e.g. kernel command line, sysctl, etc. > + > + Higher value means more swappy. Historically, defaults to 60. > + > endmenu > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 876370565455..7d2d3550f698 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -163,7 +163,29 @@ struct scan_control { > /* > * From 0 .. 100. Higher means more swappy. > */ > -int vm_swappiness = 60; > +int vm_swappiness = CONFIG_VM_SWAPPINESS; > + > +static int __init swappiness_cmdline(char *str) { > + int val, err; > + > + if (!str) > + return -EINVAL; > + > + err = kstrtoint(str, 10, &val); > + if (err) > + return -EINVAL; > + > + if (val < 0 || val > 100) > + return -EINVAL; > + > + vm_swappiness = val; > + > + return 0; > +} > + > +early_param("vm_swappiness", swappiness_cmdline); > + > /* > * The total number of pages which are beyond the high watermark within all > * zones.