erofs: lazily initialize per-CPU workers and CPU hotplug hooks
Sandeep Dhavale
reviewerPATCH v2 1/1 erofs: lazily initialize per-CPU workers and CPU hotplug hooks
Currently, when EROFS is built with per-CPU workers, the workers are started and CPU hotplug hooks are registered during module initialization. This leads to unnecessary worker start/stop cycles during CPU hotplug events, particularly on Android devices that frequently suspend and resume.
This change defers the initialization of per-CPU workers and the registration of CPU hotplug hooks until the first EROFS mount. This ensures that these resources are only allocated and managed when EROFS is actually in use.
The tear down of per-CPU workers and unregistration of CPU hotplug hooks still occurs during z_erofs_exit_subsystem(), but only if they were initialized.
---
v1: https://lore.kernel.org/linux-erofs/[email protected]/
Changes since v1:
- Get rid of erofs_mount_count based init and tear down of resources
- Initialize resource in z_erofs_init_super() as suggested by Gao
- Introduce z_erofs_init_workers_once() and track it using atomic bool
- Improve commit message
fs/erofs/internal.h | 2 ++ fs/erofs/zdata.c | 57 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 13 deletions(-)
fs/erofs/internal.h +2 -0
@@ -450,6 +450,7 @@ int z_erofs_gbuf_growsize(unsigned int nrpages);int __init z_erofs_gbuf_init (void );void z_erofs_gbuf_exit (void );int z_erofs_parse_cfgs (struct super_block *sb,struct erofs_super_block *dsb); +int z_erofs_init_workers_once (void );#else static inline void erofs_shrinker_register (struct super_block *sb) {}static inline void erofs_shrinker_unregister (struct super_block *sb) {}
@@ -458,6 +459,7 @@ static inline void erofs_exit_shrinker(void) {}static inline int z_erofs_init_subsystem (void ) {return 0 ; }static inline void z_erofs_exit_subsystem (void ) {}static inline int z_erofs_init_super (struct super_block *sb) {return 0 ; } +static inline int z_erofs_init_workers_once (void ) {return 0 ; };#endif /* !CONFIG_EROFS_FS_ZIP */ #ifdef CONFIG_EROFS_FS_BACKED_BY_FILE
fs/erofs/zdata.c +44 -13
85 lines not on this page · raw message
Signature · 1 line
2.49.0.472.ge94155a9ec-goog
Sandeep Dhavale
reviewerHi,
Gentle ping for review in case this slipped through the list.
Thanks,
Sandeep.
Hi Sandeep,
Quoted 2 lines · Sandeep Dhavale
Hi,
Gentle ping for review in case this slipped through the list.
I'm working on internal stuffs (unrelated to erofs, currently I have to handle erofs stuffs totally in my spare time), also does it really need to be resolved now?
It's not like a bugfix, if it's not urgent it will be landed upstream in the next merge window.
Thanks,
Gao Xiang
Quoted 3 lines
Thanks,
Sandeep.
Sandeep Dhavale
reviewerQuoted 3 lines · Gao Xiang
Hi Sandeep,
Hi Gao,
Quoted 8 lines · Sandeep Dhavale
Quoted 2 lines
Hi,
Gentle ping for review in case this slipped through the list.I'm working on internal stuffs (unrelated to erofs, currently I have to handle erofs stuffs totally in my spare time), also does it really need to be resolved now?
I totally understand.
Quoted 3 lines
It's not like a bugfix, if it's not urgent it will be landed upstream in the next merge window.
Yes, the next merge window is fine. I was just making sure that I collect feedback in case you think this needs any more refinements.
Thanks,
Sandeep.
Quoted 6 lines
Thanks,
Gao XiangQuoted 3 lines
Thanks,
Sandeep.
Hi,
Quoted 40 lines · Sandeep Dhavale
Currently, when EROFS is built with per-CPU workers, the workers are started and CPU hotplug hooks are registered during module initialization. This leads to unnecessary worker start/stop cycles during CPU hotplug events, particularly on Android devices that frequently suspend and resume.
This change defers the initialization of per-CPU workers and the registration of CPU hotplug hooks until the first EROFS mount. This ensures that these resources are only allocated and managed when EROFS is actually in use.
The tear down of per-CPU workers and unregistration of CPU hotplug hooks still occurs during
z_erofs_exit_subsystem(), but only if they were initialized.Signed-off-by Sandeep Dhavale <[email protected]>---
v1: https://lore.kernel.org/linux-erofs/[email protected]/
Changes since v1:
- Get rid oferofs_mount_countbased init and tear down of resources
- Initialize resource inz_erofs_init_super()as suggested by Gao
- Introducez_erofs_init_workers_once()and track it using atomic bool
- Improve commit messagefs/erofs/internal.h | 2 ++ fs/erofs/zdata.c | 57 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 13 deletions(-)fs/erofs/internal.h +1
-0@@ -450,6 +450,7 @@ int z_erofs_gbuf_growsize(unsigned int nrpages);int __init z_erofs_gbuf_init (void );void z_erofs_gbuf_exit (void );int z_erofs_parse_cfgs (struct super_block *sb,struct erofs_super_block *dsb); +int z_erofs_init_workers_once (void );#else static inline void erofs_shrinker_register (struct super_block *sb) {}static inline void erofs_shrinker_unregister (struct super_block *sb) {}
fs/erofs/internal.h static inline void erofs_exit_shrinker(void) {} · line 462
Quoted 4 lines
fs/erofs/internal.h +1
-0@@ -458,6 +459,7 @@ static inline void erofs_exit_shrinker(void) {}static inline int z_erofs_init_subsystem (void ) {return 0 ; }static inline void z_erofs_exit_subsystem (void ) {}static inline int z_erofs_init_super (struct super_block *sb) {return 0 ; } +static inline int z_erofs_init_workers_once (void ) {return 0 ; };
Why we need this? I think it's unused if decompression subsystem is disabled.
Quoted 16 lines
fs/erofs/internal.h +0
-0#endif /* !CONFIG_EROFS_FS_ZIP */ #ifdef CONFIG_EROFS_FS_BACKED_BY_FILE fs/erofs/zdata.c +1
-0@@ -11,6 +11,7 @@#define Z_EROFS_PCLUSTER_MAX_PAGES (Z_EROFS_PCLUSTER_MAX_SIZE / PAGE_SIZE)#define Z_EROFS_INLINE_BVECS 2 +static atomic_t erofs_percpu_workers_initialized =ATOMIC_INIT (0 );struct z_erofs_bvec {struct page *page;
fs/erofs/zdata.c static inline int erofs_cpu_hotplug_init(void) { return 0; } · line 404
Quoted 1 line
fs/erofs/zdata.c +0
-0@@ -403,10 +404,44 @@ static inline int erofs_cpu_hotplug_init(void) { return 0; }static inline void erofs_cpu_hotplug_destroy (void ) {}
I wonder those helpers are still needed since we have z_erofs_init_pcpu_workers().
fs/erofs/zdata.c static inline int erofs_cpu_hotplug_init(void) { return 0; } · line 407
Quoted 4 lines
fs/erofs/zdata.c +1
-1#endif -void z_erofs_exit_subsystem (void ) +static int z_erofs_init_workers (void )
I think we need to rename it asstatic int z_erofs_init_pcpu_workers(void)
Quoted 11 lines
fs/erofs/zdata.c +9
-1{ -erofs_cpu_hotplug_destroy (); +int err; + + err =erofs_init_percpu_workers (); +if (err) + goto err_init_percpu_workers; + + err =erofs_cpu_hotplug_init (); +if (err <0 ) + goto err_cpuhp_init;
fs/erofs/zdata.c static inline int erofs_cpu_hotplug_init(void) { return 0; } · line 427
Quoted 10 lines
fs/erofs/zdata.c +9
-0+return err; + +err_cpuhp_init:erofs_destroy_percpu_workers (); +err_init_percpu_workers: +atomic_set (&erofs_percpu_workers_initialized,0 ); +return err; +} + +int z_erofs_init_workers_once (void )
I'd like to inline them into z_erofs_init_super().
fs/erofs/zdata.c static inline int erofs_cpu_hotplug_init(void) { return 0; } · line 434
Quoted 7 lines
fs/erofs/zdata.c +7
-0+{ +if (atomic_xchg (&erofs_percpu_workers_initialized,1 )) +return 0 ; +return z_erofs_init_workers (); +} + +static void z_erofs_destroy_workers (void )
z_erofs_destroy_pcpu_workers()
fs/erofs/zdata.c static inline int erofs_cpu_hotplug_init(void) { return 0; } · line 436
Quoted 2 lines
fs/erofs/zdata.c +2
-0+{ +if (atomic_xchg (&erofs_percpu_workers_initialized,0 )) {
if (atomic_xchg(&erofs_percpu_workers_initialized, 0)) return;
Quoted 32 lines
fs/erofs/zdata.c +8
-11+erofs_cpu_hotplug_destroy (); +erofs_destroy_percpu_workers (); + } +} + +void z_erofs_exit_subsystem (void ) +{ +z_erofs_destroy_workers ();destroy_workqueue (z_erofs_workqueue);z_erofs_destroy_pcluster_pool ();z_erofs_exit_decompressor ();@@ -430,19 +465,8 @@ int __init z_erofs_init_subsystem(void) goto err_workqueue_init; } - err =erofs_init_percpu_workers (); -if (err) - goto err_pcpu_worker; - - err =erofs_cpu_hotplug_init (); -if (err <0 ) - goto err_cpuhp_init;return err; -err_cpuhp_init: -erofs_destroy_percpu_workers (); -err_pcpu_worker: -destroy_workqueue (z_erofs_workqueue); err_workqueue_init:z_erofs_destroy_pcluster_pool (); err_pcluster_pool:
fs/erofs/zdata.c static const struct address_space_operations z_erofs_cache_aops = { · line 672
Quoted 4 lines
fs/erofs/zdata.c +1
-0@@ -645,6 +669,13 @@ static const struct address_space_operations z_erofs_cache_aops = {int z_erofs_init_super (struct super_block *sb) {struct inode *const inode =new_inode (sb); +int err;
struct inode *inode; int err; err = z_erofs_init_workers_once(); if (err) return err; inode = new_inode(sb); ...
fs/erofs/zdata.c static const struct address_space_operations z_erofs_cache_aops = { · line 676
Quoted 4 lines
fs/erofs/zdata.c +4
-0+ + err =z_erofs_init_workers_once (); +if (err) { +iput (inode);
To avoid such unnecessary iput() here...
Thanks,
Gao Xiang
Sandeep Dhavale
reviewerHi Gao,
Thanks for the review. I have addressed the comments and did further cleanup in v3 at
https://lore.kernel.org/linux-erofs/[email protected]/
Thanks,
Sandeep.