Re: [PATCH] slab.h: Avoid using & for logical and of booleans

From: Bart Van Assche
Date: Mon Nov 05 2018 - 17:47:22 EST


On Mon, 2018-11-05 at 23:14 +-0100, Rasmus Villemoes wrote:
+AD4 Won't that pessimize the cases where gfp is a constant to actually do
+AD4 the table lookup, and add 16 bytes to every translation unit?
+AD4
+AD4 Another option is to add a fake KMALLOC+AF8-DMA+AF8-RECLAIM so the
+AD4 kmalloc+AF8-caches+AFsAXQ array has size 4, then assign the same dma
+AD4 kmalloc+AF8-cache pointer to +AFs-2+AF0AWw-i+AF0 and +AFs-3+AF0AWw-i+AF0 (so that costs perhaps a
+AD4 dozen pointers in .data), and then just compute kmalloc+AF8-type() as
+AD4
+AD4 ((flags +ACY +AF8AXw-GFP+AF8-RECLAIMABLE) +AD4APg someshift) +AHw ((flags +ACY +AF8AXw-GFP+AF8-DMA) +AD4APg
+AD4 someothershift).
+AD4
+AD4 Perhaps one could even shuffle the GFP flags so the two shifts are the same.

How about this version, still untested? My compiler is able to evaluate
the switch expression if the argument is constant.

static +AF8AXw-always+AF8-inline enum kmalloc+AF8-cache+AF8-type kmalloc+AF8-type(gfp+AF8-t flags)
+AHs
- int is+AF8-dma +AD0 0+ADs
- int type+AF8-dma +AD0 0+ADs
- int is+AF8-reclaimable+ADs
+- unsigned int dr +AD0 +ACEAIQ(flags +ACY +AF8AXw-GFP+AF8-RECLAIMABLE)+ADs

+ACM-ifdef CONFIG+AF8-ZONE+AF8-DMA
- is+AF8-dma +AD0 +ACEAIQ(flags +ACY +AF8AXw-GFP+AF8-DMA)+ADs
- type+AF8-dma +AD0 is+AF8-dma +ACo KMALLOC+AF8-DMA+ADs
+- dr +AHwAPQ +ACEAIQ(flags +ACY +AF8AXw-GFP+AF8-DMA) +ADwAPA 1+ADs
+ACM-endif

- is+AF8-reclaimable +AD0 +ACEAIQ(flags +ACY +AF8AXw-GFP+AF8-RECLAIMABLE)+ADs
-
/+ACo
+ACo If an allocation is both +AF8AXw-GFP+AF8-DMA and +AF8AXw-GFP+AF8-RECLAIMABLE, return
+ACo KMALLOC+AF8-DMA and effectively ignore +AF8AXw-GFP+AF8-RECLAIMABLE
+ACo-/
- return type+AF8-dma +- (is+AF8-reclaimable +ACY +ACE-is+AF8-dma) +ACo KMALLOC+AF8-RECLAIM+ADs
+- switch (dr) +AHs
+- default:
+- case 0:
+- return 0+ADs
+- case 1:
+- return KMALLOC+AF8-RECLAIM+ADs
+- case 2:
+- case 3:
+- return KMALLOC+AF8-DMA+ADs
+- +AH0
+AH0

Bart.