All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: Markus Elfring <Markus.Elfring@web.de>,
	Liao Pingfang <liao.pingfang@zte.com.cn>,
	linuxppc-dev@lists.ozlabs.org, Joe Perches <joe@perches.com>,
	Allison Randal <allison@lohutok.net>,
	Anton Vorontsov <anton@enomsg.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Colin Cross <ccross@android.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Kees Cook <keescook@chromium.org>,
	Paul Mackerras <paulus@samba.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Tony Luck <tony.luck@intel.com>,
	Wang Liang <wang.liang82@zte.com.cn>,
	Xue Zhihong <xue.zhihong@zte.com.cn>,
	Yi Wang <wang.yi59@zte.com.cn>,
	LKML <linux-kernel@vger.kernel.org>,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] powerpc/nvram: Replace kmalloc with kzalloc in the error message
Date: Wed, 3 Jun 2020 16:18:41 +0300	[thread overview]
Message-ID: <20200603131841.GB22511@kadam> (raw)
In-Reply-To: <87tuzsgz2p.fsf@mpe.ellerman.id.au>

On Wed, Jun 03, 2020 at 09:37:18PM +1000, Michael Ellerman wrote:
> Dan Carpenter <dan.carpenter@oracle.com> writes:
> > On Tue, Jun 02, 2020 at 09:23:57PM +1000, Michael Ellerman wrote:
> >> Markus Elfring <Markus.Elfring@web.de> writes:
> >> >>>> Please just remove the message instead, it's a tiny allocation that's
> >> >>>> unlikely to ever fail, and the caller will print an error anyway.
> >> >>>
> >> >>> How do you think about to take another look at a previous update suggestion
> >> >>> like the following?
> >> >>>
> >> >>> powerpc/nvram: Delete three error messages for a failed memory allocation
> >> >>> https://patchwork.ozlabs.org/project/linuxppc-dev/patch/00845261-8528-d011-d3b8-e9355a231d3a@users.sourceforge.net/
> >> >>> https://lore.kernel.org/linuxppc-dev/00845261-8528-d011-d3b8-e9355a231d3a@users.sourceforge.net/
> >> >>> https://lore.kernel.org/patchwork/patch/752720/
> >> >>> https://lkml.org/lkml/2017/1/19/537
> >> >>
> >> >> That deleted the messages from nvram_scan_partitions(), but neither of
> >> >> the callers of nvram_scan_paritions() check its return value or print
> >> >> anything if it fails. So removing those messages would make those
> >> >> failures silent which is not what we want.
> >> >
> >> > * How do you think about information like the following?
> >> >   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=f359287765c04711ff54fbd11645271d8e5ff763#n883
> >> > “…
> >> > These generic allocation functions all emit a stack dump on failure when used
> >> > without __GFP_NOWARN so there is no use in emitting an additional failure
> >> > message when NULL is returned.
> >> > …”
> >> 
> >> Are you sure that's actually true?
> >> 
> >> A quick look around in slub.c leads me to:
> >> 
> >> slab_out_of_memory(struct kmem_cache *s, gfp_t gfpflags, int nid)
> >> {
> >> #ifdef CONFIG_SLUB_DEBUG
> >
> > You first have to enable EXPERT mode before you can disable SLUB_DEBUG.
> 
> I see ~175 defconfigs with CONFIG_EXPERT=y, so that's not really a high
> bar unfortunately.
> 
> And there's 38 defconfigs with SLUB_DEBUG=n.
> 
> So for kernels built with those defconfigs that documentation is plain
> wrong and misleading.
> 
> And then there's SLOB which doesn't dump stack anywhere AFAICS.
> 
> In fact slab_out_of_memory() doesn't emit a stack dump either, it just
> prints a bunch of slab related info!
> 
> > So that hopefully means you *really* want to save memory.  It doesn't
> > make sense to add a bunch of memory wasting printks when the users want
> > to go to extra lengths to conserve memory.
> 
> I agree that in many cases those printks are just a waste of space in
> the source and the binary and should be removed.
> 
> But I dislike being told "these generic allocation functions all emit a
> stack dump" only to find out that actually they don't, they print some
> other debug info, and depending on config settings they actually don't
> print _anything_.

Wait...  It *does* print a stack trace.  We must but looking at the
wrong function.  Huh...  The stack trace comes from warn_alloc().  What
happen is this:

mm/slub.c
  2673  
  2674          freelist = new_slab_objects(s, gfpflags, node, &c);
  2675  
  2676          if (unlikely(!freelist)) {
  2677                  slab_out_of_memory(s, gfpflags, node);
  2678                  return NULL;
  2679          }
  2680  

The new_slab_objects() will call allocate_slab() which calls
__alloc_pages_slowpath() which calls warn_alloc() on failure.

There are some error paths from alloc_pages() which look like they
could return without the stack dump, but those are impossible paths from
kmalloc or error injection.

regards,
dan carpenter


WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: Yi Wang <wang.yi59@zte.com.cn>, Tony Luck <tony.luck@intel.com>,
	Kees Cook <keescook@chromium.org>,
	Wang Liang <wang.liang82@zte.com.cn>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Anton Vorontsov <anton@enomsg.org>,
	kernel-janitors@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	Markus Elfring <Markus.Elfring@web.de>,
	Liao Pingfang <liao.pingfang@zte.com.cn>,
	Xue Zhihong <xue.zhihong@zte.com.cn>,
	Colin Cross <ccross@android.com>, Joe Perches <joe@perches.com>,
	Paul Mackerras <paulus@samba.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	linuxppc-dev@lists.ozlabs.org,
	Allison Randal <allison@lohutok.net>
Subject: Re: [PATCH] powerpc/nvram: Replace kmalloc with kzalloc in the error message
Date: Wed, 03 Jun 2020 13:18:41 +0000	[thread overview]
Message-ID: <20200603131841.GB22511@kadam> (raw)
In-Reply-To: <87tuzsgz2p.fsf@mpe.ellerman.id.au>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="windows-1254", Size: 3739 bytes --]

On Wed, Jun 03, 2020 at 09:37:18PM +1000, Michael Ellerman wrote:
> Dan Carpenter <dan.carpenter@oracle.com> writes:
> > On Tue, Jun 02, 2020 at 09:23:57PM +1000, Michael Ellerman wrote:
> >> Markus Elfring <Markus.Elfring@web.de> writes:
> >> >>>> Please just remove the message instead, it's a tiny allocation that's
> >> >>>> unlikely to ever fail, and the caller will print an error anyway.
> >> >>>
> >> >>> How do you think about to take another look at a previous update suggestion
> >> >>> like the following?
> >> >>>
> >> >>> powerpc/nvram: Delete three error messages for a failed memory allocation
> >> >>> https://patchwork.ozlabs.org/project/linuxppc-dev/patch/00845261-8528-d011-d3b8-e9355a231d3a@users.sourceforge.net/
> >> >>> https://lore.kernel.org/linuxppc-dev/00845261-8528-d011-d3b8-e9355a231d3a@users.sourceforge.net/
> >> >>> https://lore.kernel.org/patchwork/patch/752720/
> >> >>> https://lkml.org/lkml/2017/1/19/537
> >> >>
> >> >> That deleted the messages from nvram_scan_partitions(), but neither of
> >> >> the callers of nvram_scan_paritions() check its return value or print
> >> >> anything if it fails. So removing those messages would make those
> >> >> failures silent which is not what we want.
> >> >
> >> > * How do you think about information like the following?
> >> >   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?idó59287765c04711ff54fbd11645271d8e5ff763#n883
> >> > “…
> >> > These generic allocation functions all emit a stack dump on failure when used
> >> > without __GFP_NOWARN so there is no use in emitting an additional failure
> >> > message when NULL is returned.
> >> > …”
> >> 
> >> Are you sure that's actually true?
> >> 
> >> A quick look around in slub.c leads me to:
> >> 
> >> slab_out_of_memory(struct kmem_cache *s, gfp_t gfpflags, int nid)
> >> {
> >> #ifdef CONFIG_SLUB_DEBUG
> >
> > You first have to enable EXPERT mode before you can disable SLUB_DEBUG.
> 
> I see ~175 defconfigs with CONFIG_EXPERT=y, so that's not really a high
> bar unfortunately.
> 
> And there's 38 defconfigs with SLUB_DEBUG=n.
> 
> So for kernels built with those defconfigs that documentation is plain
> wrong and misleading.
> 
> And then there's SLOB which doesn't dump stack anywhere AFAICS.
> 
> In fact slab_out_of_memory() doesn't emit a stack dump either, it just
> prints a bunch of slab related info!
> 
> > So that hopefully means you *really* want to save memory.  It doesn't
> > make sense to add a bunch of memory wasting printks when the users want
> > to go to extra lengths to conserve memory.
> 
> I agree that in many cases those printks are just a waste of space in
> the source and the binary and should be removed.
> 
> But I dislike being told "these generic allocation functions all emit a
> stack dump" only to find out that actually they don't, they print some
> other debug info, and depending on config settings they actually don't
> print _anything_.

Wait...  It *does* print a stack trace.  We must but looking at the
wrong function.  Huh...  The stack trace comes from warn_alloc().  What
happen is this:

mm/slub.c
  2673  
  2674          freelist = new_slab_objects(s, gfpflags, node, &c);
  2675  
  2676          if (unlikely(!freelist)) {
  2677                  slab_out_of_memory(s, gfpflags, node);
  2678                  return NULL;
  2679          }
  2680  

The new_slab_objects() will call allocate_slab() which calls
__alloc_pages_slowpath() which calls warn_alloc() on failure.

There are some error paths from alloc_pages() which look like they
could return without the stack dump, but those are impossible paths from
kmalloc or error injection.

regards,
dan carpenter

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: Yi Wang <wang.yi59@zte.com.cn>, Tony Luck <tony.luck@intel.com>,
	Kees Cook <keescook@chromium.org>,
	Wang Liang <wang.liang82@zte.com.cn>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Anton Vorontsov <anton@enomsg.org>,
	kernel-janitors@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	Markus Elfring <Markus.Elfring@web.de>,
	Liao Pingfang <liao.pingfang@zte.com.cn>,
	Xue Zhihong <xue.zhihong@zte.com.cn>,
	Colin Cross <ccross@android.com>, Joe Perches <joe@perches.com>,
	Paul Mackerras <paulus@samba.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	linuxppc-dev@lists.ozlabs.org,
	Allison Randal <allison@lohutok.net>
Subject: Re: [PATCH] powerpc/nvram: Replace kmalloc with kzalloc in the error message
Date: Wed, 3 Jun 2020 16:18:41 +0300	[thread overview]
Message-ID: <20200603131841.GB22511@kadam> (raw)
In-Reply-To: <87tuzsgz2p.fsf@mpe.ellerman.id.au>

On Wed, Jun 03, 2020 at 09:37:18PM +1000, Michael Ellerman wrote:
> Dan Carpenter <dan.carpenter@oracle.com> writes:
> > On Tue, Jun 02, 2020 at 09:23:57PM +1000, Michael Ellerman wrote:
> >> Markus Elfring <Markus.Elfring@web.de> writes:
> >> >>>> Please just remove the message instead, it's a tiny allocation that's
> >> >>>> unlikely to ever fail, and the caller will print an error anyway.
> >> >>>
> >> >>> How do you think about to take another look at a previous update suggestion
> >> >>> like the following?
> >> >>>
> >> >>> powerpc/nvram: Delete three error messages for a failed memory allocation
> >> >>> https://patchwork.ozlabs.org/project/linuxppc-dev/patch/00845261-8528-d011-d3b8-e9355a231d3a@users.sourceforge.net/
> >> >>> https://lore.kernel.org/linuxppc-dev/00845261-8528-d011-d3b8-e9355a231d3a@users.sourceforge.net/
> >> >>> https://lore.kernel.org/patchwork/patch/752720/
> >> >>> https://lkml.org/lkml/2017/1/19/537
> >> >>
> >> >> That deleted the messages from nvram_scan_partitions(), but neither of
> >> >> the callers of nvram_scan_paritions() check its return value or print
> >> >> anything if it fails. So removing those messages would make those
> >> >> failures silent which is not what we want.
> >> >
> >> > * How do you think about information like the following?
> >> >   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=f359287765c04711ff54fbd11645271d8e5ff763#n883
> >> > “…
> >> > These generic allocation functions all emit a stack dump on failure when used
> >> > without __GFP_NOWARN so there is no use in emitting an additional failure
> >> > message when NULL is returned.
> >> > …”
> >> 
> >> Are you sure that's actually true?
> >> 
> >> A quick look around in slub.c leads me to:
> >> 
> >> slab_out_of_memory(struct kmem_cache *s, gfp_t gfpflags, int nid)
> >> {
> >> #ifdef CONFIG_SLUB_DEBUG
> >
> > You first have to enable EXPERT mode before you can disable SLUB_DEBUG.
> 
> I see ~175 defconfigs with CONFIG_EXPERT=y, so that's not really a high
> bar unfortunately.
> 
> And there's 38 defconfigs with SLUB_DEBUG=n.
> 
> So for kernels built with those defconfigs that documentation is plain
> wrong and misleading.
> 
> And then there's SLOB which doesn't dump stack anywhere AFAICS.
> 
> In fact slab_out_of_memory() doesn't emit a stack dump either, it just
> prints a bunch of slab related info!
> 
> > So that hopefully means you *really* want to save memory.  It doesn't
> > make sense to add a bunch of memory wasting printks when the users want
> > to go to extra lengths to conserve memory.
> 
> I agree that in many cases those printks are just a waste of space in
> the source and the binary and should be removed.
> 
> But I dislike being told "these generic allocation functions all emit a
> stack dump" only to find out that actually they don't, they print some
> other debug info, and depending on config settings they actually don't
> print _anything_.

Wait...  It *does* print a stack trace.  We must but looking at the
wrong function.  Huh...  The stack trace comes from warn_alloc().  What
happen is this:

mm/slub.c
  2673  
  2674          freelist = new_slab_objects(s, gfpflags, node, &c);
  2675  
  2676          if (unlikely(!freelist)) {
  2677                  slab_out_of_memory(s, gfpflags, node);
  2678                  return NULL;
  2679          }
  2680  

The new_slab_objects() will call allocate_slab() which calls
__alloc_pages_slowpath() which calls warn_alloc() on failure.

There are some error paths from alloc_pages() which look like they
could return without the stack dump, but those are impossible paths from
kmalloc or error injection.

regards,
dan carpenter


  reply	other threads:[~2020-06-03 13:19 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-29 18:50 [PATCH] powerpc/nvram: Replace kmalloc with kzalloc in the error message Markus Elfring
2020-05-29 18:50 ` Markus Elfring
2020-05-29 18:50 ` Markus Elfring
2020-06-02  2:57 ` Michael Ellerman
2020-06-02  2:57   ` Michael Ellerman
2020-06-02  2:57   ` Michael Ellerman
2020-06-02  5:01   ` Markus Elfring
2020-06-02  5:01     ` Markus Elfring
2020-06-02  5:01     ` Markus Elfring
2020-06-02 11:23     ` Michael Ellerman
2020-06-02 11:23       ` Michael Ellerman
2020-06-02 11:23       ` Michael Ellerman
2020-06-02 11:41       ` Dan Carpenter
2020-06-02 11:41         ` Dan Carpenter
2020-06-02 11:41         ` Dan Carpenter
2020-06-03 11:37         ` Michael Ellerman
2020-06-03 11:37           ` Michael Ellerman
2020-06-03 11:37           ` Michael Ellerman
2020-06-03 13:18           ` Dan Carpenter [this message]
2020-06-03 13:18             ` Dan Carpenter
2020-06-03 13:18             ` Dan Carpenter
  -- strict thread matches above, loose matches on Subject: below --
2020-05-29  1:02 Yi Wang
2020-05-29  1:02 ` Yi Wang
2020-05-29  4:04 ` Michael Ellerman
2020-05-29  4:04   ` Michael Ellerman

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=20200603131841.GB22511@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=Markus.Elfring@web.de \
    --cc=allison@lohutok.net \
    --cc=anton@enomsg.org \
    --cc=benh@kernel.crashing.org \
    --cc=ccross@android.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=joe@perches.com \
    --cc=keescook@chromium.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=liao.pingfang@zte.com.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=wang.liang82@zte.com.cn \
    --cc=wang.yi59@zte.com.cn \
    --cc=xue.zhihong@zte.com.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.