linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Pekka Enberg <penberg@cs.helsinki.fi>
To: ngupta@vflare.org
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, linux-mm-cc@laptop.org
Subject: Re: [PATCH 1/4] compcache: xvmalloc memory allocator
Date: Mon, 24 Aug 2009 20:33:25 +0300	[thread overview]
Message-ID: <84144f020908241033l4af09e7h9caac47d8d9b7841@mail.gmail.com> (raw)
In-Reply-To: <200908241007.47910.ngupta@vflare.org>

Hi Nitin,

[ Nit: the name xmalloc() is usually reserved for non-failing allocators in
  user-space which is why xvmalloc() looks so confusing to me. Can we
  get a better name for the thing? Also, I'm not sure why xvmalloc is a
  separate module. Can't you just make it in-kernel or compile it in to the
  ramzswap module? ]

On Mon, Aug 24, 2009 at 7:37 AM, Nitin Gupta<ngupta@vflare.org> wrote:
> +/**
> + * xv_malloc - Allocate block of given size from pool.
> + * @pool: pool to allocate from
> + * @size: size of block to allocate
> + * @pagenum: page no. that holds the object
> + * @offset: location of object within pagenum
> + *
> + * On success, <pagenum, offset> identifies block allocated
> + * and 0 is returned. On failure, <pagenum, offset> is set to
> + * 0 and -ENOMEM is returned.
> + *
> + * Allocation requests with size > XV_MAX_ALLOC_SIZE will fail.
> + */
> +int xv_malloc(struct xv_pool *pool, u32 size, u32 *pagenum, u32 *offset,
> +                                                       gfp_t flags)
> +{
> +       int error;
> +       u32 index, tmpsize, origsize, tmpoffset;
> +       struct block_header *block, *tmpblock;
> +
> +       *pagenum = 0;
> +       *offset = 0;
> +       origsize = size;
> +
> +       if (unlikely(!size || size > XV_MAX_ALLOC_SIZE))
> +               return -ENOMEM;
> +
> +       size = ALIGN(size, XV_ALIGN);
> +
> +       spin_lock(&pool->lock);
> +
> +       index = find_block(pool, size, pagenum, offset);
> +
> +       if (!*pagenum) {
> +               spin_unlock(&pool->lock);
> +               if (flags & GFP_NOWAIT)
> +                       return -ENOMEM;
> +               error = grow_pool(pool, flags);
> +               if (unlikely(error))
> +                       return -ENOMEM;
> +
> +               spin_lock(&pool->lock);
> +               index = find_block(pool, size, pagenum, offset);
> +       }
> +
> +       if (!*pagenum) {
> +               spin_unlock(&pool->lock);
> +               return -ENOMEM;
> +       }
> +
> +       block = get_ptr_atomic(*pagenum, *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, *pagenum, 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;
> +}
> +EXPORT_SYMBOL_GPL(xv_malloc);

What's the purpose of passing PFNs around? There's quite a lot of PFN
to struct page conversion going on because of it. Wouldn't it make
more sense to return (and pass) a pointer to struct page instead?

                        Pekka

--
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>

  reply	other threads:[~2009-08-25 21:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-24  4:37 Nitin Gupta
2009-08-24 17:33 ` Pekka Enberg [this message]
2009-08-24 17:52   ` Nitin Gupta
2009-08-24 18:08     ` Pekka Enberg
2009-08-24 18:11       ` Nitin Gupta
2009-08-24 18:27         ` Pekka Enberg
2009-08-24 18:40           ` Nitin Gupta
2009-08-24 19:36   ` Nitin Gupta
2009-08-24 19:43     ` Pekka Enberg
2009-08-24 21:16       ` Nitin Gupta
2009-08-25  4:26         ` Pekka Enberg
2009-08-24 20:39     ` Hugh Dickins
2009-08-24 21:16       ` Nitin Gupta
2009-08-24 21:46         ` Hugh Dickins
2009-08-25 14:52           ` Nitin Gupta
2009-08-25 19:03             ` Nitin Gupta
2009-08-26 16:10               ` Christoph Lameter
2009-08-26 16:17                 ` Nitin Gupta
2009-08-26 16:19                 ` Pekka Enberg
2009-08-26 16:07     ` Christoph Lameter

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=84144f020908241033l4af09e7h9caac47d8d9b7841@mail.gmail.com \
    --to=penberg@cs.helsinki.fi \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm-cc@laptop.org \
    --cc=linux-mm@kvack.org \
    --cc=ngupta@vflare.org \
    /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