[ snip]
>>> Yes, you will always get aligned addressess on your x86 Linux system
>>> that supports
>>> posix_memalign() call. The comment says what it says because it will
>>> make some memory allocation tricks in case posix_memalign() is not
>>> available (Windows, some MacOS, maybe some Linux systems (not sure))
>>> and the address will not be aligned it this case.
>>
>> I also verified the other case when posix_memalign isn't available and
>> even in that case it returns the address aligned on CACHE_LINE_SIZE
>> boundary. I will send out a patch to use xzalloc_cacheline for allocating
>> the
>memory.
>
>I don't know how you tested this, because it is impossible:
>
> 1. OVS allocates some memory:
> base = xmalloc(...);
>
> 2. Rounds it up to the cache line start:
> payload = (void **) ROUND_UP((uintptr_t) base,
>CACHE_LINE_SIZE);
>
> 3. Returns the pointer increased by 8 bytes:
> return (char *) payload + MEM_ALIGN;
>
>So, unless you redefined MEM_ALIGN to zero, you will never get aligned
>memory address while allocating by xmalloc_cacheline() on system without
>posix_memalign().
>
Hmmm, I didn't set MEM_ALIGN to zero instead used below test code to get
aligned addresses
when posix_memalign() isn't available. We can't set MEM_ALIGN to zero so have
to do this
hack to get aligned address and store the initial address (original address
allocated by malloc) in a place before the
aligned location so that it can be freed by later call to free(). (I should
have mentioned in my previous mail).
-------------------------------------------------------------------------------------------------
void **payload;
void *base;
base = xmalloc(CACHE_LINE_SIZE + size + MEM_ALIGN);
/* Address aligned on CACHE_LINE_SIZE boundary. */
payload = (void**)(((uintptr_t) base + CACHE_LINE_SIZE + MEM_ALIGN) &
~(CACHE_LINE_SIZE - 1));
/* Store the original address so it can be freed later. */
payload[-1] = base;
return (char *)payload;
-------------------------------------------------------------------------------------------------
- Bhanuprakash.
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev