From: Luis Chamberlain <mcgrof@kernel.org>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: david@redhat.com, patches@lists.linux.dev,
linux-modules@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, pmladek@suse.com,
petr.pavlu@suse.com, prarit@redhat.com,
torvalds@linux-foundation.org, rafael@kernel.org,
christophe.leroy@csgroup.eu, tglx@linutronix.de,
peterz@infradead.org, song@kernel.org, rppt@kernel.org,
willy@infradead.org, vbabka@suse.cz, mhocko@suse.com,
dave.hansen@linux.intel.com
Subject: Re: [PATCH 7/7] module: add debug stats to help identify memory pressure
Date: Tue, 28 Mar 2023 23:04:21 -0700 [thread overview]
Message-ID: <ZCPU5T1PD+BwI9ri@bombadil.infradead.org> (raw)
In-Reply-To: <ZCPQrouSMQbFc8D0@kroah.com>
On Wed, Mar 29, 2023 at 07:46:22AM +0200, Greg KH wrote:
> On Tue, Mar 28, 2023 at 10:31:49PM -0700, Luis Chamberlain wrote:
> > Loading modules with finit_module() can end up using vmalloc(), vmap()
> > and vmalloc() again, for a total of up to 3 separate allocations in the
> > worse case for a single module. We always kernel_read*() the module,
> > that's a vmalloc(). Then vmap() is used for the module decompression,
> > and if so the last read buffer is freed as we use the now decompressed
> > module buffer to stuff data into our copy module. The last one is
> > specific to architectures but pretty much that's generally a series
> > of vmalloc() for different ELF sections...
> >
> > Evaluation with new stress-ng module support [1] with just 100 ops
> > us proving that you can end up using GiBs of data easily even if
> > we are trying to be very careful not to load modules which are already
> > loaded. 100 ops seems to resemble the sort of pressure a system with
> > about 400 CPUs can create on modules. Although those issues for so
> > many concurrent loads per CPU is silly and are being fixed, we lack
> > proper tooling to help diagnose easily what happened, when it happened
> > and what likely are the culprits -- userspace or kernel module
> > autoloading.
> >
> > Provide an initial set of stats for debugfs which let us easily scrape
> > post-boot information about failed loads. This sort of information can
> > be used on production worklaods to try to optimize *avoiding* redundant
> > memory pressure using finit_module().
> >
> > Screen shot:
> >
> > root@kmod ~ # cat /sys/kernel/debug/modules/stats
> > Modules loaded 67
>
> Is this "loaded now", or "ever successfully loaded"? As in a
> modprobe/rmmod/modprobe would bump this by 2, right?
Ah, the later, so "how modules have I ever loaded". Maybe
Modules ever loaded
?
Will fix the nits, thanks!
> > diff --git a/kernel/module/debug.c b/kernel/module/debug.c
>
> Why is this a whole separate file?
It's just a style preference, no real hard reason other than
module.c was huge before and now its split up. I find that
easier to review / manage. Certainly overkill for such as
simple thing but if its debug I think I rather see that
then some ifdef eyesore. But that's just preference.
> And as MODULE_DEBUG does not reference debugfs,
That should be fixed thanks.
> > diff --git a/kernel/module/internal.h b/kernel/module/internal.h
> > index 6ae29bb8836f..a645cb3fafc7 100644
> > --- a/kernel/module/internal.h
> > +++ b/kernel/module/internal.h
> > @@ -143,6 +143,41 @@ static inline bool set_livepatch_module(struct module *mod)
> > #endif
> > }
> >
> > +#ifdef CONFIG_MODULE_STATS
> > +
> > +#define mod_stat_add64(count, var) atomic64_add(count, var)
> > +#define mod_stat_inc(name) atomic_inc(name)
>
> Ok, but:
>
> > +#define mod_stat_inc(name) atomic_inc(name)
>
> Why do you still increment the variable here if the option is not
> enabled?
Whoops, will fix!
> Also, didn't we have some sort of "we want to use an atomic variable as
> statistics" type somewhere in the kernel?
I didn't get the memo, nor do I recall, so it's not on my radar.
> Or did that never get accepted?
Not sure.
> And do all of these really need to be atomic variables? Don't you have
> locks for some of this to not need the atomic-ness of them? I guess it
> doesn't matter much as this isn't that fast of a code-path.
That was actually intentional, as this only *grows* I just care its not 0
so to help divide by the total number of modules to get average module
length and average module .text length. I used atomics and made it only
grow precisely to not have to lock anywhere.
Luis
prev parent reply other threads:[~2023-03-29 6:04 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-29 5:31 [PATCH 0/7] module: avoid userspace pressure on unwanted allocations Luis Chamberlain
2023-03-29 5:31 ` [PATCH 1/7] module: move finished_loading() Luis Chamberlain
2023-03-29 5:31 ` [PATCH 2/7] module: extract patient module check into helper Luis Chamberlain
2023-03-29 5:31 ` [PATCH 3/7] module: avoid allocation if module is already present and ready Luis Chamberlain
2023-03-29 5:31 ` [PATCH 4/7] sempahore: add a helper for a concurrency limiter Luis Chamberlain
2023-03-29 7:21 ` Peter Zijlstra
2023-03-29 7:51 ` Luis Chamberlain
2023-03-29 9:19 ` Peter Zijlstra
2023-03-29 9:49 ` Luis Chamberlain
2023-03-29 10:14 ` Peter Zijlstra
2023-03-29 16:50 ` Linus Torvalds
2023-03-30 11:56 ` Peter Zijlstra
2023-03-30 16:23 ` Linus Torvalds
2023-03-31 3:42 ` Sergey Senozhatsky
2023-03-31 8:05 ` Petr Mladek
2023-03-31 3:45 ` Luis Chamberlain
2023-03-31 4:06 ` Matthew Wilcox
2023-03-31 4:13 ` Luis Chamberlain
2023-03-31 4:11 ` Sergey Senozhatsky
2023-03-29 5:31 ` [PATCH 5/7] modules/kmod: replace implementation with a sempahore Luis Chamberlain
2023-03-29 5:31 ` [PATCH 6/7] debugfs: add debugfs_create_atomic64_t for atomic64_t Luis Chamberlain
2023-03-29 5:46 ` Greg KH
2023-03-29 5:31 ` [PATCH 7/7] module: add debug stats to help identify memory pressure Luis Chamberlain
2023-03-29 5:46 ` Greg KH
2023-03-29 6:04 ` Luis Chamberlain [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZCPU5T1PD+BwI9ri@bombadil.infradead.org \
--to=mcgrof@kernel.org \
--cc=christophe.leroy@csgroup.eu \
--cc=dave.hansen@linux.intel.com \
--cc=david@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-modules@vger.kernel.org \
--cc=mhocko@suse.com \
--cc=patches@lists.linux.dev \
--cc=peterz@infradead.org \
--cc=petr.pavlu@suse.com \
--cc=pmladek@suse.com \
--cc=prarit@redhat.com \
--cc=rafael@kernel.org \
--cc=rppt@kernel.org \
--cc=song@kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).