Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2688517ybh; Mon, 16 Mar 2020 07:55:02 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuERkObFFlTOER3kCVmkZc/uiuoY5j4NHwYh5pHK43CaMLk6i6DzCN9aBcA1ih1xU3MsIXE X-Received: by 2002:a9d:23a1:: with SMTP id t30mr22513154otb.253.1584370502240; Mon, 16 Mar 2020 07:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584370502; cv=none; d=google.com; s=arc-20160816; b=InFJDfl20Oih6nnv8bwVLna+kEsWQh7Hi8+WmFGy8Ug7rr3YNp2DXxpi5STipumy1w +5h96C5ULDmajqtQ3/nZYbqNyeEhk8ki0UG9vh8DyfXK5UfqxSXdhbxz3MDq4ol4yVkR z+o0kO9KmGEskfOZ8F2nS2q0RMl7q7lPk5IuZAM+qMTnXJIVxOrz/BVBPmut8SpXK4/9 VVPIryte8agVLnEd/NN/l+T5b+RbM5bLnm65cGrtatsDbs1LHkq5JpfXEwarTA6zdc1t py+641JllEsTvkXw25bxme1walJEtrgmBlf6CddktHLOrIWcgAk6ZH4PalA0khRKkE3o R+9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:subject:from; bh=cQF1d/Atrs2TJvd3cCPUJrRAq8tQeMlT6kHOcyF2wgQ=; b=mrSzqkZ5aJ0/2RIG1Mvwd32HtYTe4feQhIrHniiXqRmMnS9uP8abxqUVJ60j11Umbm sRXkblcCkW9E4+yRdV4FBO8fheX9TK0gFGovUABQB+CTtqK02Z2sKLBDPEhjSxTu0TrM BdC/ggTrYX/khWysUp6+93Wk0zQcyI4wUCkGHOfdjNHdPRG8sF+xhk6tt05F88YZld4Q HgxOdXA3PuVzT7OMiOz/i7MHxiicHznLmOilH82daLumPYBsm8H853rFAXjUvUsX/eLC 7PBGmFwM7ljvvlJesZtRprHDHZZBJd5BQtRK4LoRQGRYvHWH+Bjva/VJRQXVk63U/MHz LtCQ== 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 94si74620otb.114.2020.03.16.07.54.49; Mon, 16 Mar 2020 07:55:02 -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; 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 S1731672AbgCPOxZ (ORCPT + 99 others); Mon, 16 Mar 2020 10:53:25 -0400 Received: from mx2.suse.de ([195.135.220.15]:58298 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731631AbgCPOxZ (ORCPT ); Mon, 16 Mar 2020 10:53:25 -0400 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 76FE1AD72; Mon, 16 Mar 2020 14:53:22 +0000 (UTC) From: Vlastimil Babka Subject: Re: [PATCH] mm/vmscan: add vm_swappiness configuration knobs To: Michal Hocko , 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" References: <20200312092531.GU23944@dhcp22.suse.cz> <20200312132642.GW23944@dhcp22.suse.cz> Message-ID: <4ea2e014-17ea-6d1e-a6cd-775fb6550cd2@suse.cz> Date: Mon, 16 Mar 2020 15:53:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200312132642.GW23944@dhcp22.suse.cz> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/12/20 2:26 PM, Michal Hocko wrote: > On Thu 12-03-20 12:54:19, Ivan Teterevkov wrote: >> >> Absolutely agree, the semantics of the vm_swappiness is perplexing. >> Moreover, the same get_scan_count treats vm_swappiness and cgroups >> memory.swappiness differently, in particular, 0 disables the memcg swap. >> >> Certainly, the patch adds some additional exposure to a parameter that >> is not trivial to tackle but it's already getting created with a magic >> number which is also confusing. Is there any harm to be done by the patch >> considering the already existing sysctl interface to that knob? > > Like any other config option/kernel parameter. It is adding the the > overall config space size problem and unless this is really needed I > would rather not make it worse. Setting the vm_swappiness specific case aside, I wonder if if would be useful to be able to emulate any sysctl with a kernel parameter, i.e. boot the kernel with sysctl.vm.swappiness=X There are already some options that provide kernel parameter as well as sysctl, why not just support all. Quick and dirty proof of concept: ----8<----- diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 02fa84493f23..62ae963a5c0c 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -206,6 +206,7 @@ struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, void unregister_sysctl_table(struct ctl_table_header * table); extern int sysctl_init(void); +int process_sysctl_arg(char *param, char *val, const char *unused, void *arg); extern struct ctl_table sysctl_mount_point[]; diff --git a/init/main.c b/init/main.c index ee4947af823f..c1544ff4ec5b 100644 --- a/init/main.c +++ b/init/main.c @@ -1345,6 +1345,23 @@ void __weak free_initmem(void) free_initmem_default(POISON_FREE_INITMEM); } +static void do_sysctl_args(void) +{ + size_t len = strlen(saved_command_line) + 1; + char *command_line; + + command_line = kzalloc(len, GFP_KERNEL); + if (!command_line) + panic("%s: Failed to allocate %zu bytes\n", __func__, len); + + strcpy(command_line, saved_command_line); + + parse_args("Setting sysctl args", command_line, + NULL, 0, -1, -1, NULL, process_sysctl_arg); + + kfree(command_line); +} + static int __ref kernel_init(void *unused) { int ret; @@ -1367,6 +1384,8 @@ static int __ref kernel_init(void *unused) rcu_end_inkernel_boot(); + do_sysctl_args(); + if (ramdisk_execute_command) { ret = run_init_process(ramdisk_execute_command); if (!ret) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index ad5b88a53c5a..5b3b520d29a8 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1980,6 +1980,66 @@ int __init sysctl_init(void) return 0; } +int process_sysctl_arg(char *param, char *val, + const char *unused, void *arg) +{ + size_t count; + char *tmp; + int err; + loff_t ppos = 0; + struct ctl_table *base, *child = NULL, *found = NULL; + + if (strncmp(param, "sysctl.", sizeof("sysctl.") - 1)) + return 0; + + param += (sizeof("sysctl.") - 1); + + pr_notice("sysctl: %s=%s", param, val); + + tmp = strchr(param, '.'); + if (!tmp) { + pr_notice("invalid sysctl param '%s' on command line", param); + return 0; + } + + *tmp = '\0'; + + for (base = &sysctl_base_table[0]; base->procname != 0; base++) { + if (strcmp(param, base->procname) == 0) { + child = base->child; + break; + } + } + + if (!child) { + pr_notice("unknown sysctl prefix '%s' on command line", param); + return 0; + } + + tmp++; + + for (; child->procname != 0; child++) { + if (strcmp(tmp, child->procname) == 0) { + found = child; + break; + } + } + + if (!found) { + pr_notice("unknown sysctl param '%s.%s' on command line", param, tmp); + return 0; + } + + count = strlen(val); + err = found->proc_handler(found, 1, val, &count, &ppos); + + if (err) + pr_notice("error %d setting sysctl '%s.%s' from command line", + err, param, tmp); + + return 0; +} + #endif /* CONFIG_SYSCTL */ /* -- 2.25.1