Currently gcc seems to inline devtmpfs_setup() into devtmpfsd(), so
its memory footprint isn't reclaimed as intended. Mark it noinline to
make sure it gets put in .init.text.
While here, setup_done can also be put in .init.data: After complete()
releases the internal spinlock, the completion object is never touched
again by that thread, and the waiting thread doesn't proceed until it
observes ->done while holding that spinlock.
This is now the same pattern as for kthreadd_done in init/main.c:
complete() is done in a __ref function, while the corresponding
wait_for_completion() is in an __init function.
Signed-off-by: Rasmus Villemoes <[email protected]>
---
drivers/base/devtmpfs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
index aedeb2dc1a18..8be352ab4ddb 100644
--- a/drivers/base/devtmpfs.c
+++ b/drivers/base/devtmpfs.c
@@ -371,7 +371,7 @@ int __init devtmpfs_mount(void)
return err;
}
-static DECLARE_COMPLETION(setup_done);
+static __initdata DECLARE_COMPLETION(setup_done);
static int handle(const char *name, umode_t mode, kuid_t uid, kgid_t gid,
struct device *dev)
@@ -405,7 +405,7 @@ static void __noreturn devtmpfs_work_loop(void)
}
}
-static int __init devtmpfs_setup(void *p)
+static noinline int __init devtmpfs_setup(void *p)
{
int err;
--
2.29.2
On Fri, Mar 12, 2021 at 11:30:27AM +0100, Rasmus Villemoes wrote:
> Currently gcc seems to inline devtmpfs_setup() into devtmpfsd(), so
> its memory footprint isn't reclaimed as intended. Mark it noinline to
> make sure it gets put in .init.text.
>
> While here, setup_done can also be put in .init.data: After complete()
> releases the internal spinlock, the completion object is never touched
> again by that thread, and the waiting thread doesn't proceed until it
> observes ->done while holding that spinlock.
>
> This is now the same pattern as for kthreadd_done in init/main.c:
> complete() is done in a __ref function, while the corresponding
> wait_for_completion() is in an __init function.
I'm not sure if this matters in any way, but it does look fine to me:
Reviewed-by: Christoph Hellwig <[email protected]>