[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4FA7C2BC.2090400@vflare.org>
Date: Mon, 07 May 2012 08:40:28 -0400
From: Nitin Gupta <ngupta@...are.org>
To: Pekka Enberg <penberg@...nel.org>
CC: Minchan Kim <minchan@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Seth Jennings <sjenning@...ux.vnet.ibm.com>,
Dan Magenheimer <dan.magenheimer@...cle.com>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org, linux-mm@...ck.org,
cl@...ux-foundation.org
Subject: Re: [PATCH 4/4] zsmalloc: zsmalloc: align cache line size
On 5/7/12 3:41 AM, Pekka Enberg wrote:
> On Fri, 4 May 2012, Minchan Kim wrote:
>>>> It's a overkill to align pool size with PAGE_SIZE to avoid
>>>> false-sharing. This patch aligns it with just cache line size.
>>>>
>>>> Signed-off-by: Minchan Kim<minchan@...nel.org>
>>>> ---
>>>> drivers/staging/zsmalloc/zsmalloc-main.c | 6 +++---
>>>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/drivers/staging/zsmalloc/zsmalloc-main.c
>>>> b/drivers/staging/zsmalloc/zsmalloc-main.c
>>>> index 51074fa..3991b03 100644
>>>> --- a/drivers/staging/zsmalloc/zsmalloc-main.c
>>>> +++ b/drivers/staging/zsmalloc/zsmalloc-main.c
>>>> @@ -489,14 +489,14 @@ fail:
>>>>
>>>> struct zs_pool *zs_create_pool(const char *name, gfp_t flags)
>>>> {
>>>> - int i, error, ovhd_size;
>>>> + int i, error;
>>>> struct zs_pool *pool;
>>>>
>>>> if (!name)
>>>> return NULL;
>>>>
>>>> - ovhd_size = roundup(sizeof(*pool), PAGE_SIZE);
>>>> - pool = kzalloc(ovhd_size, GFP_KERNEL);
>>>> + pool = kzalloc(ALIGN(sizeof(*pool), cache_line_size()),
>>>> + GFP_KERNEL);
>>>
>>> a basic question:
>>> Is rounding off allocation size to cache_line_size enough to ensure
>>> that the object is cache-line-aligned? Isn't it possible that even
>>> though the object size is multiple of cache-line, it may still not be
>>> properly aligned and end up sharing cache line with some other
>>> read-mostly object?
>>
>> AFAIK, SLAB allocates object aligned cache-size so I think that problem cannot happen.
>> But needs double check.
>> Cced Pekka.
>
> The kmalloc(size) function only gives you the following guarantees:
>
> (1) The allocated object is _at least_ 'size' bytes.
>
> (2) The returned pointer is aligned to ARCH_KMALLOC_MINALIGN.
>
> Anything beyond that is implementation detail and probably will break if
> you switch between SLAB/SLUB/SLOB.
>
> Pekka
So, we can probably leave it as is (PAGE_SIZE aligned) or use
kmem_cache_create(...,SLAB_HWCACHE_ALIGN,...) for allocating 'struct
zs_pool's.
zcache can potentially create a lot of pools, so the latter will save
some memory.
Thanks,
Nitin
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists