From patchwork Wed Aug 3 10:05:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: CGEL X-Patchwork-Id: 12935349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72AA2C19F28 for ; Wed, 3 Aug 2022 10:05:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1370A8E0002; Wed, 3 Aug 2022 06:05:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E6B46B0072; Wed, 3 Aug 2022 06:05:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF0C38E0002; Wed, 3 Aug 2022 06:05:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id DEC3B6B0071 for ; Wed, 3 Aug 2022 06:05:46 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A7C251213FF for ; Wed, 3 Aug 2022 10:05:46 +0000 (UTC) X-FDA: 79757849892.14.1DF4364 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf14.hostedemail.com (Postfix) with ESMTP id 1F978100126 for ; Wed, 3 Aug 2022 10:05:23 +0000 (UTC) Received: by mail-pf1-f177.google.com with SMTP id q19so6667828pfg.8 for ; Wed, 03 Aug 2022 03:05:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=V7yMXZa3MywkOFBvlYMPqSqmCaZ5JNGIAqlkaSLZ/kM=; b=ipjbvHg48fVyW4jVX5gIjrnxkQ8/Uun3HS5plAciRpFp9N9V56WtAuDOfPwusWnA0M Ra3acdntu7vD9oDei3ZjYZSowPGpmY07igPy8HRpVLkeTkcf31OxvmQ+go0em31ADw2e xdPeXir+TMMAUQfNFeBjzEWoAsiIjC4BmO0xeqiO4pqM8SABLHZjevqyqoxRcIqtfqsO QpROXLlVD+2olAHOIGCTIU5YWCf1IkbU4LJf1AEX7ZQI0AHQPwQRKNc9+Tr6t91wITSV W9wIQoLg2vLppCaaIrBWQx3tzEu90iHp/9ztRKJxAbAa4Jj6VCf5dDziuLsHdXDuscqC Zwzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=V7yMXZa3MywkOFBvlYMPqSqmCaZ5JNGIAqlkaSLZ/kM=; b=8InVsFFSB/ACQR4ubaPzYPqTRjjf6dkaq01p2Cd8pduDtBHw93o/EO96QKiUuV5RJC Zl+Pp2iezAhsoHVsotJkAD4piLOqmKNLPYZ5hKmPX1e2SNNwf6ZAUWP4GlqGiiB3It7p XI61Bs4ZnX2Paz8q4uz9vsIoro61yqI4tMvKDOEZS3zS8D6z/wTnFR7ul/YwxLcEjtcm zjXA43EFgY2GaeewM9Z3UDSz4dMPVesPrlygXHIH9dMk9kAE/RPglZYm/Y1rYViFr8D0 dldRJL0CSpS8iRgHtuE2nnbD7+5He0TA646k3M978cUc9HCfQEvzGAUdo7QoT7WR1GNp JBCg== X-Gm-Message-State: AJIora+pUlkb91Vkp3dLxWGm34i6Xy5k6XWEq3OYbzMfRyjvLNXmaX0k rasv5OnfAu//gAmNBkCXbQs= X-Google-Smtp-Source: AGRyM1saowNGHUEc91GATroNAs1Ulpr9zGAqAodgHMmGAOrGXpFhOyI9NrSJEWMx+FVvZRavoC9blg== X-Received: by 2002:a63:c10a:0:b0:41b:f15:f9c4 with SMTP id w10-20020a63c10a000000b0041b0f15f9c4mr20763742pgf.72.1659521123115; Wed, 03 Aug 2022 03:05:23 -0700 (PDT) Received: from localhost.localdomain ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id k14-20020a170902d58e00b0016b90620910sm1455917plh.71.2022.08.03.03.05.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Aug 2022 03:05:22 -0700 (PDT) From: cgel.zte@gmail.com X-Google-Original-From: xu.xin16@zte.con.cn To: akpm@linux-foundation.org Cc: hughd@google.com, izik.eidus@ravellosystems.com, willy@infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, xu xin , CGEL Subject: [RFC PATCH 1/4] ksm: propose a auto-run mode of ksm Date: Wed, 3 Aug 2022 10:05:14 +0000 Message-Id: <20220803100514.1653440-1-xu.xin16@zte.con.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220803100306.1653382-1-xu.xin16@zte.con.cn> References: <20220803100306.1653382-1-xu.xin16@zte.con.cn> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659521142; a=rsa-sha256; cv=none; b=TsD0+H11IoWOotA3X5OyRmLfTipmshamdsSEGkjpitqUaIBaaTIOs9urqXnqNjJvEE6jC1 EufJO510JvzJM+6NMcYvafk/c9TPz7ygJZ2woBRUdMQ2AjFMq6Grxwx5u+LMjIqi/kmhmm g14+skHa3oyeZMEQP9Xd5xr2WmwYdyw= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ipjbvHg4; spf=pass (imf14.hostedemail.com: domain of cgel.zte@gmail.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=cgel.zte@gmail.com; dmarc=temperror reason="query timed out" header.from=gmail.com (policy=temperror) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659521142; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=V7yMXZa3MywkOFBvlYMPqSqmCaZ5JNGIAqlkaSLZ/kM=; b=KlutWqPvqWMmw+tZjHzMW0MdBXmzPNlxHA/V76ODP2tZi6gRDhzGEce0+JV9dEPu+t9lFN mSfkMJOga/PXOq5q5MwNMf1A0Rkdd9KTWrk4kNCdr1XRt3KLNTfCSv6HSL0bU6b75DLe3j YUwEvpdyxi/hE75B5lUd2pfwJ3945hw= X-Rspam-User: X-Stat-Signature: gug9q6bmrxhea78e196y1e5qy5zjgsrh X-Rspamd-Queue-Id: 1F978100126 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ipjbvHg4; spf=pass (imf14.hostedemail.com: domain of cgel.zte@gmail.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=cgel.zte@gmail.com; dmarc=temperror reason="query timed out" header.from=gmail.com (policy=temperror) X-Rspamd-Server: rspam02 X-HE-Tag: 1659521123-155292 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: From: xu xin Add a new running state auto-mode to ksm. This is to pave the way for subsequent real optimization features. Use it by: echo 8 > /sys/kernel/mm/ksm/run Signed-off-by: xu xin Signed-off-by: CGEL --- mm/ksm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 2f315c69fa2c..c80d908221a4 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -290,6 +290,7 @@ static int ksm_nr_node_ids = 1; #define KSM_RUN_MERGE 1 #define KSM_RUN_UNMERGE 2 #define KSM_RUN_OFFLINE 4 +#define KSM_RUN_AUTO 8 static unsigned long ksm_run = KSM_RUN_STOP; static void wait_while_offlining(void); @@ -2416,7 +2417,9 @@ static void ksm_do_scan(unsigned int scan_npages) static int ksmd_should_run(void) { - return (ksm_run & KSM_RUN_MERGE) && !list_empty(&ksm_mm_head.mm_list); + if (!list_empty(&ksm_mm_head.mm_list)) + return ksm_run & KSM_RUN_AUTO || ksm_run & KSM_RUN_MERGE; + return 0; } static int ksm_scan_thread(void *nothing) @@ -2916,7 +2919,7 @@ static ssize_t run_store(struct kobject *kobj, struct kobj_attribute *attr, err = kstrtouint(buf, 10, &flags); if (err) return -EINVAL; - if (flags > KSM_RUN_UNMERGE) + if (flags > KSM_RUN_UNMERGE && flags != KSM_RUN_AUTO) return -EINVAL; /* @@ -2942,7 +2945,7 @@ static ssize_t run_store(struct kobject *kobj, struct kobj_attribute *attr, } mutex_unlock(&ksm_thread_mutex); - if (flags & KSM_RUN_MERGE) + if (flags & KSM_RUN_MERGE || flags & KSM_RUN_AUTO) wake_up_interruptible(&ksm_thread_wait); return count;