linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-mm@kvack.org
Subject: Re: [bug report] mm, slab/slub: introduce kmalloc-reclaimable caches
Date: Tue, 13 Nov 2018 20:02:07 +0300	[thread overview]
Message-ID: <20181113170207.GA22791@unbuntlaptop> (raw)
In-Reply-To: <a6c8eeff-801c-3773-6b96-533f519ef9f4@suse.cz>

On Fri, Nov 09, 2018 at 06:28:44PM +0100, Vlastimil Babka wrote:
> On 11/9/18 6:17 PM, Dan Carpenter wrote:
> >    315  static __always_inline enum kmalloc_cache_type kmalloc_type(gfp_t flags)
> >    316  {
> >    317          int is_dma = 0;
> >    318          int type_dma = 0;
> >    319          int is_reclaimable;
> >    320  
> >    321  #ifdef CONFIG_ZONE_DMA
> >    322          is_dma = !!(flags & __GFP_DMA);
> >    323          type_dma = is_dma * KMALLOC_DMA;
> >                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > 
> > KMALLOC_DMA is the last possible valid index.
> 
> Yes, but type_dma gains the value of KMALLOC_DMA only when is_dma is 1.
> 
> >    324  #endif
> >    325  
> >    326          is_reclaimable = !!(flags & __GFP_RECLAIMABLE);
> >    327  
> >    328          /*
> >    329           * If an allocation is both __GFP_DMA and __GFP_RECLAIMABLE, return
> >    330           * KMALLOC_DMA and effectively ignore __GFP_RECLAIMABLE
> >    331           */
> >    332          return type_dma + (is_reclaimable & !is_dma) * KMALLOC_RECLAIM;
> >                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > 
> > We're adding one to it.
> 
> Only when !is_dma is 1, which means then that type_dma is 0. So it's safe.
> 
> > This is mm/ so I assume this works,
> 
> I'll... take that as a compliment :D
> 

Yes, of course.

> > but it's
> > pretty confusing.
> 
> Indeed. Static checkers seem to hate my too clever code, so it's already
> going away [1]. Maybe your static checker can be improved to evaluate
> this better? There's already a gcc bug [2] inspired by the whole thing.
> 

It's cool that the GCC developers think they can handle this code.  I
would have to rethink how Smatch handles math entirely...

regards,
dan carpenter

      reply	other threads:[~2018-11-13 17:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-09 17:17 Dan Carpenter
2018-11-09 17:28 ` Vlastimil Babka
2018-11-13 17:02   ` Dan Carpenter [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=20181113170207.GA22791@unbuntlaptop \
    --to=dan.carpenter@oracle.com \
    --cc=linux-mm@kvack.org \
    --cc=vbabka@suse.cz \
    /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