mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH -next] cgroup/pids: replace can_attach and cancel_attach with attach hook
@ 2024-05-24  9:18 Xiu Jianfeng
  2024-05-24  9:34 ` xiujianfeng
  0 siblings, 1 reply; 2+ messages in thread
From: Xiu Jianfeng @ 2024-05-24  9:18 UTC (permalink / raw)
  To: tj, lizefan.x, hannes; +Cc: cgroups, linux-kernel

Currently pids_can_attach() always returns 0 and never fails, so the
can_attach() and cancel_attach() hooks can be replaced by attach(),
since attach() is guaranteed to succeed and don't need to fallback.

Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
 kernel/cgroup/pids.c | 25 ++-----------------------
 1 file changed, 2 insertions(+), 23 deletions(-)

diff --git a/kernel/cgroup/pids.c b/kernel/cgroup/pids.c
index 0e5ec7d59b4d..86d06f709957 100644
--- a/kernel/cgroup/pids.c
+++ b/kernel/cgroup/pids.c
@@ -186,7 +186,7 @@ static int pids_try_charge(struct pids_cgroup *pids, int num)
 	return -EAGAIN;
 }
 
-static int pids_can_attach(struct cgroup_taskset *tset)
+static void pids_attach(struct cgroup_taskset *tset)
 {
 	struct task_struct *task;
 	struct cgroup_subsys_state *dst_css;
@@ -207,26 +207,6 @@ static int pids_can_attach(struct cgroup_taskset *tset)
 		pids_charge(pids, 1);
 		pids_uncharge(old_pids, 1);
 	}
-
-	return 0;
-}
-
-static void pids_cancel_attach(struct cgroup_taskset *tset)
-{
-	struct task_struct *task;
-	struct cgroup_subsys_state *dst_css;
-
-	cgroup_taskset_for_each(task, dst_css, tset) {
-		struct pids_cgroup *pids = css_pids(dst_css);
-		struct cgroup_subsys_state *old_css;
-		struct pids_cgroup *old_pids;
-
-		old_css = task_css(task, pids_cgrp_id);
-		old_pids = css_pids(old_css);
-
-		pids_charge(old_pids, 1);
-		pids_uncharge(pids, 1);
-	}
 }
 
 /*
@@ -374,8 +354,7 @@ static struct cftype pids_files[] = {
 struct cgroup_subsys pids_cgrp_subsys = {
 	.css_alloc	= pids_css_alloc,
 	.css_free	= pids_css_free,
-	.can_attach 	= pids_can_attach,
-	.cancel_attach 	= pids_cancel_attach,
+	.attach		= pids_attach,
 	.can_fork	= pids_can_fork,
 	.cancel_fork	= pids_cancel_fork,
 	.release	= pids_release,
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH -next] cgroup/pids: replace can_attach and cancel_attach with attach hook
  2024-05-24  9:18 [PATCH -next] cgroup/pids: replace can_attach and cancel_attach with attach hook Xiu Jianfeng
@ 2024-05-24  9:34 ` xiujianfeng
  0 siblings, 0 replies; 2+ messages in thread
From: xiujianfeng @ 2024-05-24  9:34 UTC (permalink / raw)
  To: tj, lizefan.x, hannes; +Cc: cgroups, linux-kernel

Sorry, it's a mistake, please ignore this patch :(

On 2024/5/24 17:18, Xiu Jianfeng wrote:
> Currently pids_can_attach() always returns 0 and never fails, so the
> can_attach() and cancel_attach() hooks can be replaced by attach(),
> since attach() is guaranteed to succeed and don't need to fallback.
> 
> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
> ---
>  kernel/cgroup/pids.c | 25 ++-----------------------
>  1 file changed, 2 insertions(+), 23 deletions(-)
> 
> diff --git a/kernel/cgroup/pids.c b/kernel/cgroup/pids.c
> index 0e5ec7d59b4d..86d06f709957 100644
> --- a/kernel/cgroup/pids.c
> +++ b/kernel/cgroup/pids.c
> @@ -186,7 +186,7 @@ static int pids_try_charge(struct pids_cgroup *pids, int num)
>  	return -EAGAIN;
>  }
>  
> -static int pids_can_attach(struct cgroup_taskset *tset)
> +static void pids_attach(struct cgroup_taskset *tset)
>  {
>  	struct task_struct *task;
>  	struct cgroup_subsys_state *dst_css;
> @@ -207,26 +207,6 @@ static int pids_can_attach(struct cgroup_taskset *tset)
>  		pids_charge(pids, 1);
>  		pids_uncharge(old_pids, 1);
>  	}
> -
> -	return 0;
> -}
> -
> -static void pids_cancel_attach(struct cgroup_taskset *tset)
> -{
> -	struct task_struct *task;
> -	struct cgroup_subsys_state *dst_css;
> -
> -	cgroup_taskset_for_each(task, dst_css, tset) {
> -		struct pids_cgroup *pids = css_pids(dst_css);
> -		struct cgroup_subsys_state *old_css;
> -		struct pids_cgroup *old_pids;
> -
> -		old_css = task_css(task, pids_cgrp_id);
> -		old_pids = css_pids(old_css);
> -
> -		pids_charge(old_pids, 1);
> -		pids_uncharge(pids, 1);
> -	}
>  }
>  
>  /*
> @@ -374,8 +354,7 @@ static struct cftype pids_files[] = {
>  struct cgroup_subsys pids_cgrp_subsys = {
>  	.css_alloc	= pids_css_alloc,
>  	.css_free	= pids_css_free,
> -	.can_attach 	= pids_can_attach,
> -	.cancel_attach 	= pids_cancel_attach,
> +	.attach		= pids_attach,
>  	.can_fork	= pids_can_fork,
>  	.cancel_fork	= pids_cancel_fork,
>  	.release	= pids_release,

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-24  9:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-24  9:18 [PATCH -next] cgroup/pids: replace can_attach and cancel_attach with attach hook Xiu Jianfeng
2024-05-24  9:34 ` xiujianfeng

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®