From: Nitin Gupta <ngupta@vflare.org>
To: Marcin Slusarz <marcin.slusarz@gmail.com>
Cc: Greg KH <greg@kroah.com>,
Andrew Morton <akpm@linux-foundation.org>,
Pekka Enberg <penberg@cs.helsinki.fi>, Ed Tomlinson <edt@aei.ca>,
linux-kernel <linux-kernel@vger.kernel.org>,
linux-mm <linux-mm@kvack.org>,
linux-mm-cc <linux-mm-cc@laptop.org>
Subject: Re: [PATCH 1/4] xvmalloc memory allocator
Date: Tue, 22 Sep 2009 09:20:36 +0530 [thread overview]
Message-ID: <4AB8498C.6040804@vflare.org> (raw)
In-Reply-To: <4AB3F60D.2030808@gmail.com>
Sorry for late reply. I nearly missed this mail. My comments inline.
On 09/19/2009 02:35 AM, Marcin Slusarz wrote:
> Nitin Gupta wrote:
>> (...)
>> +
>> +/*
>> + * Allocate a memory page. Called when a pool needs to grow.
>> + */
>> +static struct page *xv_alloc_page(gfp_t flags)
>> +{
>> + struct page *page;
>> +
>> + page = alloc_page(flags);
>> + if (unlikely(!page))
>> + return 0;
>> +
>> + return page;
>> +}
>
> When alloc_page returns 0 it returns 0, when not - it returns page.
> Why not call alloc_page directly?
>
We now call alloc_page() and __free_page directly. Removed these wrappers.
>> (...)
>> +/*
>> + * Remove block from freelist. Index 'slindex' identifies the freelist.
>> + */
>> +static void remove_block(struct xv_pool *pool, struct page *page, u32 offset,
>> + struct block_header *block, u32 slindex)
>> +{
>> + u32 flindex;
>> + struct block_header *tmpblock;
<snip>
>> +
>> + return;
>> +}
>
> needless return
>
Removed.
>> +int xv_malloc(struct xv_pool *pool, u32 size, struct page **page,
>> + u32 *offset, gfp_t flags)
>> +{
>> + int error;
>> +
<snip>
>> + if (!*page) {
>> + spin_unlock(&pool->lock);
>> + if (flags & GFP_NOWAIT)
>> + return -ENOMEM;
>> + error = grow_pool(pool, flags);
>> + if (unlikely(error))
>> + return -ENOMEM;
>
> shouldn't it return error? (grow_pool returns 0 or -ENOMEM for now but...)
>
Yes, it should return error. Corrected.
>> +
>> + spin_lock(&pool->lock);
>> + index = find_block(pool, size, page, offset);
>> + }
>> +
>> + if (!*page) {
>> + spin_unlock(&pool->lock);
>> + return -ENOMEM;
>> + }
>> +
>> + block = get_ptr_atomic(*page, *offset, KM_USER0);
>> +
>> + remove_block_head(pool, block, index);
>> +
>> + /* Split the block if required */
>> + tmpoffset = *offset + size + XV_ALIGN;
>> + tmpsize = block->size - size;
>> + tmpblock = (struct block_header *)((char *)block + size + XV_ALIGN);
>> + if (tmpsize) {
>> + tmpblock->size = tmpsize - XV_ALIGN;
>> + set_flag(tmpblock, BLOCK_FREE);
>> + clear_flag(tmpblock, PREV_FREE);
>> +
>> + set_blockprev(tmpblock, *offset);
>> + if (tmpblock->size >= XV_MIN_ALLOC_SIZE)
>> + insert_block(pool, *page, tmpoffset, tmpblock);
>> +
>> + if (tmpoffset + XV_ALIGN + tmpblock->size != PAGE_SIZE) {
>> + tmpblock = BLOCK_NEXT(tmpblock);
>> + set_blockprev(tmpblock, tmpoffset);
>> + }
>> + } else {
>> + /* This block is exact fit */
>> + if (tmpoffset != PAGE_SIZE)
>> + clear_flag(tmpblock, PREV_FREE);
>> + }
>> +
>> + block->size = origsize;
>> + clear_flag(block, BLOCK_FREE);
>> +
>> + put_ptr_atomic(block, KM_USER0);
>> + spin_unlock(&pool->lock);
>> +
>> + *offset += XV_ALIGN;
>> +
>> + return 0;
>> +}
>> +
>> +/*
>> + * Free block identified with <page, offset>
>> + */
>> +void xv_free(struct xv_pool *pool, struct page *page, u32 offset)
>> +{
<snip>
>> + return;
>> +}
>
> needless return
>
>
Removed.
Regarding your comments on page_zero_filled: I'm not sure if using unsigned
long is better or just u64 irrespective of arch. I just changed it to ulong
-- some bechmarks can help decide which one is optimal. Maybe we need arch
specific optimized versions which means moving it to lib/ or something.
Thanks for your feedback.
Nitin
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2009-09-22 3:51 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-17 22:43 [PATCH 0/4] compcache: in-memory compressed swapping v3 Nitin Gupta
2009-09-17 22:43 ` [PATCH 1/4] xvmalloc memory allocator Nitin Gupta
2009-09-18 21:05 ` Marcin Slusarz
2009-09-22 3:50 ` Nitin Gupta [this message]
2009-09-17 22:43 ` [PATCH 2/4] send callback when swap slot is freed Nitin Gupta
2009-09-18 6:53 ` Pekka Enberg
2009-09-18 7:17 ` Hugh Dickins
2009-09-18 7:55 ` Pekka Enberg
2009-09-18 7:59 ` Hugh Dickins
2009-09-18 9:33 ` Pekka Enberg
2009-09-18 15:04 ` Nitin Gupta
2009-09-19 7:27 ` Pekka Enberg
2009-09-20 15:02 ` Nitin Gupta
2009-09-21 11:17 ` Hugh Dickins
2009-09-21 11:07 ` Hugh Dickins
2009-09-21 11:12 ` Pekka Enberg
2009-09-21 11:55 ` Hugh Dickins
2009-09-21 12:01 ` Pekka Enberg
2009-09-22 3:04 ` Nitin Gupta
2009-09-21 12:08 ` Pekka Enberg
2009-09-21 12:29 ` Nitin Gupta
2009-09-18 9:59 ` Nitin Gupta
2009-09-19 5:47 ` Nitin Gupta
2009-09-24 1:39 ` KAMEZAWA Hiroyuki
2009-09-17 22:43 ` [PATCH 3/4] virtual block device driver (ramzswap) Nitin Gupta
2009-09-18 20:48 ` Marcin Slusarz
2009-09-17 22:43 ` [PATCH 4/4] documentation Nitin Gupta
2009-09-18 16:43 ` [PATCH] ramzswap prefix for swap free callback Nitin Gupta
[not found] <200909100215.36350.ngupta@vflare.org>
2009-09-09 21:53 ` [PATCH 1/4] xvmalloc memory allocator Nitin Gupta
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=4AB8498C.6040804@vflare.org \
--to=ngupta@vflare.org \
--cc=akpm@linux-foundation.org \
--cc=edt@aei.ca \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm-cc@laptop.org \
--cc=linux-mm@kvack.org \
--cc=marcin.slusarz@gmail.com \
--cc=penberg@cs.helsinki.fi \
/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