mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: shisiyuan <shisiyuan19870131@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: shisiyuan <shisiyuan@xiaomi.com>, Tejun Heo <tj@kernel.org>,
	Li Zefan <lizefan@huawei.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] cgroup: Return if dst_cgrp equals to src_cgrp
Date: Sat, 21 May 2022 01:02:00 +0800	[thread overview]
Message-ID: <1653066120-21262-1-git-send-email-shisiyuan@xiaomi.com> (raw)

In function cgroup_migrate_add_src(), if dst_cgrp
equals to src_cgroup which the tasks link, dont
go on migrating tasks to another css_set.
This can save the cost of unnecessary migration.

Signed-off-by: shisiyuan <shisiyuan@xiaomi.com>
---
 kernel/cgroup/cgroup.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 6139460..97d7f68 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -2634,6 +2634,9 @@ void cgroup_migrate_add_src(struct css_set *src_cset,
 
 	src_cgrp = cset_cgroup_from_root(src_cset, dst_cgrp->root);
 
+	if (src_cgrp == dst_cgrp)
+		return;
+
 	if (!list_empty(&src_cset->mg_preload_node))
 		return;
 
@@ -2780,6 +2783,9 @@ int cgroup_attach_task(struct cgroup *dst_cgrp, struct task_struct *leader,
 	rcu_read_unlock();
 	spin_unlock_irq(&css_set_lock);
 
+	if (list_empty(&mgctx.preloaded_src_csets))
+		return ret;
+
 	/* prepare dst csets and commit */
 	ret = cgroup_migrate_prepare_dst(&mgctx);
 	if (!ret)
@@ -2927,7 +2933,7 @@ static int cgroup_update_dfl_csses(struct cgroup *cgrp)
 	struct cgroup_subsys_state *d_css;
 	struct cgroup *dsct;
 	struct css_set *src_cset;
-	int ret;
+	int ret = 0;
 
 	lockdep_assert_held(&cgroup_mutex);
 
@@ -2943,6 +2949,9 @@ static int cgroup_update_dfl_csses(struct cgroup *cgrp)
 	}
 	spin_unlock_irq(&css_set_lock);
 
+	if (list_empty(&mgctx.preloaded_src_csets))
+		goto out_finish;
+
 	/* NULL dst indicates self on default hierarchy */
 	ret = cgroup_migrate_prepare_dst(&mgctx);
 	if (ret)
-- 
2.7.4


             reply	other threads:[~2022-05-20 17:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-20 17:02 shisiyuan [this message]
2022-05-25 22:51 ` Michal Koutný
     [not found]   ` <CAC=y0ud7oPtFqj=dqBSicoWwoN0knAwA6svidiYjbFn9BJMR3w@mail.gmail.com>
2022-05-26 11:22     ` Michal Koutný

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1653066120-21262-1-git-send-email-shisiyuan@xiaomi.com \
    --to=shisiyuan19870131@gmail.com \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=shisiyuan@xiaomi.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®