[PATCH v2] delayacct: optimize delayacct init

From: cgel . zte
Date: Wed Sep 15 2021 - 02:31:15 EST


From: Yang Yang <yang.yang29@xxxxxxxxxx>

In delayacct_init(), first there is no need to assign delayacct_on to
delayacct_on in set_delayacct(). Second if delayacct_on is 0, there
is no need call delayacct_tsk_init().

Signed-off-by: Yang Yang <yang.yang29@xxxxxxxxxx>
Tested-by: Zeal Robot <zealci@xxxxxxxxxx>
---
v2: move set_delayacct() in CONFIG_PROC_SYSCTL now
---
kernel/delayacct.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/kernel/delayacct.c b/kernel/delayacct.c
index 51530d5b15a8..1135a551edd1 100644
--- a/kernel/delayacct.c
+++ b/kernel/delayacct.c
@@ -18,17 +18,6 @@ DEFINE_STATIC_KEY_FALSE(delayacct_key);
int delayacct_on __read_mostly; /* Delay accounting turned on/off */
struct kmem_cache *delayacct_cache;

-static void set_delayacct(bool enabled)
-{
- if (enabled) {
- static_branch_enable(&delayacct_key);
- delayacct_on = 1;
- } else {
- delayacct_on = 0;
- static_branch_disable(&delayacct_key);
- }
-}
-
static int __init delayacct_setup_enable(char *str)
{
delayacct_on = 1;
@@ -39,11 +28,26 @@ __setup("delayacct", delayacct_setup_enable);
void delayacct_init(void)
{
delayacct_cache = KMEM_CACHE(task_delay_info, SLAB_PANIC|SLAB_ACCOUNT);
+ if (delayacct_on)
+ static_branch_enable(&delayacct_key);
+ else
+ return;
+
delayacct_tsk_init(&init_task);
- set_delayacct(delayacct_on);
}

#ifdef CONFIG_PROC_SYSCTL
+static void set_delayacct(bool enabled)
+{
+ if (enabled) {
+ static_branch_enable(&delayacct_key);
+ delayacct_on = 1;
+ } else {
+ delayacct_on = 0;
+ static_branch_disable(&delayacct_key);
+ }
+}
+
int sysctl_delayacct(struct ctl_table *table, int write, void *buffer,
size_t *lenp, loff_t *ppos)
{
--
2.25.1