Re: [PATCH] document optimizing macro for translating PROT_ to VM_ bits

From: Muli Ben-Yehuda (mulix_at_mulix.org)
Date: 09/30/03

  • Next message: Rick Lindsley: "[PATCH] update Documentation/iostats.txt for 2.6"
    Date:	Tue, 30 Sep 2003 10:10:05 +0300
    To: Jamie Lokier <jamie@shareable.org>
    
    
    

    On Mon, Sep 29, 2003 at 04:34:37PM +0100, Jamie Lokier wrote:

    > I agree with the intent of that comment, but the code in it is
    > unnecessarily complex. See if you like this, and if you do feel free
    > to submit it as a patch:

    Ah, much nicer, thank you. I'll submit it, but first, what do you
    think about this version? it keeps the optimization and enforces the
    "bit1 and bit2 must be single bits only" rule. It could probably be
    improved to be done at build time, if bit1 and bit2 and compile time
    constants. Against 2.6.0-t6-cvs, compiles and boots for me.

    --- linux-2.5/include/linux/mman.h Sun Sep 7 10:05:18 2003
    +++ calc-vm-bit-optimizing-macro-2.6.0-t6//include/linux/mman.h Tue Sep 30 10:02:01 2003
    @@ -28,10 +28,28 @@
             vm_acct_memory(-pages);
     }
     
    -/* Optimisation macro. */
    -#define _calc_vm_trans(x,bit1,bit2) \
    - ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1)) \
    - : ((x) & (bit1)) / ((bit1) / (bit2)))
    +/*
    + * assert that only a single bit is on in 'bit'
    + */
    +static inline void assert_single_bit(unsigned long bit)
    +{
    + BUG_ON(bit & (bit - 1));
    +}
    +/*
    + * Optimisation function. It is equivalent to:
    + * (x & bit1) ? bit2 : 0
    + * but this version is faster.
    + * ("bit1" and "bit2" must be single bits).
    + */
    +static inline unsigned long
    +_calc_vm_trans(unsigned long x, unsigned long bit1, unsigned long bit2)
    +{
    + assert_single_bit(bit1);
    + assert_single_bit(bit2);
    +
    + return ((bit1) <= (bit2) ? ((x) & (bit1)) * ((bit2) / (bit1))
    + : ((x) & (bit1)) / ((bit1) / (bit2)));
    +}
     
     /*
      * Combine the mmap "prot" argument into "vm_flags" used internally.

    -- 
    Muli Ben-Yehuda
    http://www.mulix.org
    
    

    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/



  • Next message: Rick Lindsley: "[PATCH] update Documentation/iostats.txt for 2.6"