Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp3056714rdb; Mon, 4 Dec 2023 15:49:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IFyPyj0TlOSObsSOPPV3Wd8ZvbXBIjhUChHfh2ma20DroncIFxS8GUdtQx44SeUElgLeumA X-Received: by 2002:a05:6a00:27aa:b0:6cd:df27:9519 with SMTP id bd42-20020a056a0027aa00b006cddf279519mr488586pfb.34.1701733791423; Mon, 04 Dec 2023 15:49:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701733791; cv=none; d=google.com; s=arc-20160816; b=NQrRGSPhBvIMOt0wULDkFFVv3ZqG2YuKJMi0M3Nsi1G2dWqtaELVfFynyoWR1gzgzK n1KHyHrCZRrNBMiwaDjIxunb0SPH3Dg4f1oTWNavNHW5zFLtF1MHr1yztR+BEZFD3DmV H5No92l6pBy0xVxgTqqNmNR2kEIy6YcQ5CMQRsl/ckNe6+ktuNkAAqdEhgb87Aq+2qSf zCAOcPfgLPZMM386HdFxaRauJ5rHWyJiZnUWGZ+cpQsIhk9FQVwjzpofRO9WK/6QIcqQ wzg4Lq4nbxbVmCertMPbRoNsjiWfeUmnGpdb95ItIbWQ6dyd1EYQK4VHuN1s2MHNT0nj /sXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lSOH/I2hSe0+XvfrQBNIjBmF6L0o2lUHd9hlQ8s2gkY=; fh=sS+J4OyOC0EcVLWJpS3mBHGeO+0+dYZJ+ImCUfzsrH4=; b=BGnNLySLmatB2mYF8U8vdmr1zNn4Db30cz+j/6qNdB3eSPlKL5hOIcbU9eBaPRDXg5 n1p0VqrRYW04BLv305cGcp/ueFZmDjBD34cSjCUN3O5Au2sZq2Py6WkYaUfDaNhRi1TV a4n5NpCv4xaKXL6B+mhKghhqB8Li8w3QH0O2w2Vd3NPrcBD4tmSLQ9CvMcaJRWDoVYOO gpoNWJ8g7bc+Oeo1XgCuEBELer2/1sSpllZmrQiiWx0mO8X8qbNqTVXUonmsT9OUUYmc it1KBDeAaQjR09NUuqJdLbDpEXo0ft7bR/OQ8/9larcfexhmQQBM1M7bR2XAKnj7SEVq yeJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id u28-20020a056a00099c00b006ce06fc9968si5868430pfg.233.2023.12.04.15.49.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 15:49:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id CD441809FEFE; Mon, 4 Dec 2023 15:49:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343526AbjLDXtT (ORCPT + 99 others); Mon, 4 Dec 2023 18:49:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234754AbjLDXtP (ORCPT ); Mon, 4 Dec 2023 18:49:15 -0500 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F6B0FA for ; Mon, 4 Dec 2023 15:49:21 -0800 (PST) Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id E345C105D3A87; Mon, 4 Dec 2023 15:49:09 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, akpm@linux-foundation.org, david@redhat.com, hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v3 2/4] mm/ksm: add sysfs knobs for advisor Date: Mon, 4 Dec 2023 15:49:04 -0800 Message-Id: <20231204234906.1237478-3-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231204234906.1237478-1-shr@devkernel.io> References: <20231204234906.1237478-1-shr@devkernel.io> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 04 Dec 2023 15:49:46 -0800 (PST) This adds four new knobs for the KSM advisor to influence its behaviour. The knobs are: - advisor_mode: none: no advisor (default) scan-time: scan time advisor - advisor_max_cpu: 70 (default, cpu usage percent) - advisor_min_pages: 500 (default) - advisor_max_pages: 30000 (default) - advisor_target_scan_time: 200 (default in seconds) The new values will take effect on the next scan round. Signed-off-by: Stefan Roesch --- mm/ksm.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/mm/ksm.c b/mm/ksm.c index b27010fa2e946..18b7185bbc65b 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3735,6 +3735,128 @@ static ssize_t smart_scan_store(struct kobject *k= obj, } KSM_ATTR(smart_scan); =20 +static ssize_t advisor_mode_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + const char *output; + + if (ksm_advisor =3D=3D KSM_ADVISOR_NONE) + output =3D "[none] scan-time"; + else if (ksm_advisor =3D=3D KSM_ADVISOR_SCAN_TIME) + output =3D "none [scan-time]"; + + return sysfs_emit(buf, "%s\n", output); +} + +static ssize_t advisor_mode_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, + size_t count) +{ + if (sysfs_streq("scan-time", buf)) + ksm_advisor =3D KSM_ADVISOR_SCAN_TIME; + else if (sysfs_streq("none", buf)) + ksm_advisor =3D KSM_ADVISOR_NONE; + else + return -EINVAL; + + /* Set advisor default values */ + init_advisor(); + set_advisor_defaults(); + + return count; +} +KSM_ATTR(advisor_mode); + +static ssize_t advisor_max_cpu_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%u\n", ksm_advisor_max_cpu); +} + +static ssize_t advisor_max_cpu_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int err; + unsigned long value; + + err =3D kstrtoul(buf, 10, &value); + if (err) + return -EINVAL; + + ksm_advisor_max_cpu =3D value; + return count; +} +KSM_ATTR(advisor_max_cpu); + +static ssize_t advisor_min_pages_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%lu\n", ksm_advisor_min_pages); +} + +static ssize_t advisor_min_pages_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int err; + unsigned long value; + + err =3D kstrtoul(buf, 10, &value); + if (err) + return -EINVAL; + + ksm_advisor_min_pages =3D value; + return count; +} +KSM_ATTR(advisor_min_pages); + +static ssize_t advisor_max_pages_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%lu\n", ksm_advisor_max_pages); +} + +static ssize_t advisor_max_pages_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int err; + unsigned long value; + + err =3D kstrtoul(buf, 10, &value); + if (err) + return -EINVAL; + + ksm_advisor_max_pages =3D value; + return count; +} +KSM_ATTR(advisor_max_pages); + +static ssize_t advisor_target_scan_time_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "%lu\n", ksm_advisor_target_scan_time); +} + +static ssize_t advisor_target_scan_time_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + int err; + unsigned long value; + + err =3D kstrtoul(buf, 10, &value); + if (err) + return -EINVAL; + if (value < 1) + return -EINVAL; + + ksm_advisor_target_scan_time =3D value; + return count; +} +KSM_ATTR(advisor_target_scan_time); + static struct attribute *ksm_attrs[] =3D { &sleep_millisecs_attr.attr, &pages_to_scan_attr.attr, @@ -3757,6 +3879,11 @@ static struct attribute *ksm_attrs[] =3D { &use_zero_pages_attr.attr, &general_profit_attr.attr, &smart_scan_attr.attr, + &advisor_mode_attr.attr, + &advisor_max_cpu_attr.attr, + &advisor_min_pages_attr.attr, + &advisor_max_pages_attr.attr, + &advisor_target_scan_time_attr.attr, NULL, }; =20 --=20 2.39.3