[Devel] [PATCH v3 RH9] cgroup_freezer: print information about unfreezable process

nb nikolay.borisov at virtuozzo.com
Wed Dec 7 15:27:18 MSK 2022



On 30.11.22 г. 13:22 ч., Pavel Tikhomirov wrote:
> Add a sysctl kernel.freeze_cgroup_timeout (default value 30 * HZ).
> 
> If one writes FROZEN to freezer.state file and after a timeout of
> kernel.freeze_cgroup_timeout one still reads FREEZING from freezer.state
> file (meaning that kernel does not succeed to freeze cgroup processes
> still) - let's print a warning with information about the problem, e.g.:
> 
> [ 7196.621368] Freeze of /test took 0 sec, due to unfreezable process 13732:bash, stack:
> [ 7196.621396] [<ffffffffa2df9556>] retint_careful+0x14/0x32
> [ 7196.621431] [<ffffffffffffffff>] 0xffffffffffffffff
> 
> The output includes:
> - path to problematic freezer cgroup
> - timeout in seconds
> - unfeezable process pid, comm and stack
> 
> https://jira.sw.ru/browse/PSBM-142970
> 
> Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
> ---
> v3: use kmalloc for entries and freezer_cg_name + reformat
> ---
>   include/linux/sysctl.h         |  2 +
>   kernel/cgroup/legacy_freezer.c | 71 ++++++++++++++++++++++++++++++++--
>   kernel/sysctl.c                | 10 +++++
>   3 files changed, 80 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
> index 8fd2d3c217c2..b641dd2bba82 100644
> --- a/include/linux/sysctl.h
> +++ b/include/linux/sysctl.h
> @@ -188,6 +188,8 @@ struct ctl_path {
>   };
>   
>   extern int trusted_exec;
> +#define DEFAULT_FREEZE_TIMEOUT (30 * HZ)
> +extern int sysctl_freeze_timeout;
>   
>   extern int ve_allow_module_load;
>   
> diff --git a/kernel/cgroup/legacy_freezer.c b/kernel/cgroup/legacy_freezer.c
> index 08236798d173..eea2f0b924f1 100644
> --- a/kernel/cgroup/legacy_freezer.c
> +++ b/kernel/cgroup/legacy_freezer.c
> @@ -22,6 +22,10 @@
>   #include <linux/freezer.h>
>   #include <linux/seq_file.h>
>   #include <linux/mutex.h>
> +#include <linux/jiffies.h>
> +#include <linux/ratelimit.h>
> +#include <linux/stacktrace.h>
> +#include <linux/sysctl.h>
>   
>   /*
>    * A cgroup is freezing if any FREEZING flags are set.  FREEZING_SELF is
> @@ -43,6 +47,7 @@ enum freezer_state_flags {
>   struct freezer {
>   	struct cgroup_subsys_state	css;
>   	unsigned int			state;
> +	unsigned long			freeze_jiffies;
>   };
>   
>   static DEFINE_MUTEX(freezer_mutex);
> @@ -225,6 +230,60 @@ static void freezer_fork(struct task_struct *task)
>   	mutex_unlock(&freezer_mutex);
>   }
>   
> +#define MAX_STACK_TRACE_DEPTH   64
> +
> +static void check_freezer_timeout(struct cgroup_subsys_state *css,
> +				  struct task_struct *task)
> +
> +{
> +	static DEFINE_RATELIMIT_STATE(freeze_timeout_rs,
> +				      DEFAULT_FREEZE_TIMEOUT, 1);
> +	int __freeze_timeout = READ_ONCE(sysctl_freeze_timeout);
> +	struct freezer *freezer = css_freezer(css);
> +	unsigned long nr_entries;
> +	unsigned long *entries;
> +	char *freezer_cg_name;
> +	pid_t tgid;
> +	int i;
> +
> +	if (!freezer->freeze_jiffies ||
> +	    freezer->freeze_jiffies + __freeze_timeout > get_jiffies_64())
> +		return;

Don't you want to execute the logic if freeze_jiffies + __freeze_timeout 
is larger than get_jiffies_64() ? Because this means the timeout has 
elapsed and you consider the freezer hung?

<snip>


More information about the Devel mailing list