* [PATCH v2] delayacct: optimize delayacct init
@ 2021-09-15 6:30 cgel.zte
0 siblings, 0 replies; only message in thread
From: cgel.zte @ 2021-09-15 6:30 UTC (permalink / raw)
To: bsingharora; +Cc: linux-kernel, Yang Yang, Zeal Robot
From: Yang Yang <yang.yang29@zte.com.cn>
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@zte.com.cn>
Tested-by: Zeal Robot <zealci@zte.com.cn>
---
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-09-15 6:31 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-15 6:30 [PATCH v2] delayacct: optimize delayacct init cgel.zte
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).