All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Shaohua Li <shli@kernel.org>
Cc: linux-mm@kvack.org, hughd@google.com, riel@redhat.com
Subject: Re: [RFC 1/2]swap: add a simple buddy allocator
Date: Mon, 22 Oct 2012 14:10:21 -0700	[thread overview]
Message-ID: <20121022141021.40cac432.akpm@linux-foundation.org> (raw)
In-Reply-To: <20121022023051.GA20255@kernel.org>

On Mon, 22 Oct 2012 10:30:51 +0800
Shaohua Li <shli@kernel.org> wrote:

> I'm using a fast SSD to do swap. scan_swap_map() sometimes uses up to 20~30%
> CPU time (when cluster is hard to find), which becomes a bottleneck.
> scan_swap_map() scans a byte array to search a 256 page cluster, which is very
> slow.
> 
> Here I introduced a simple buddy allocator. Since we only care about 256 pages
> cluster, we can just use a counter to implement the buddy allocator. Every 256
> pages use one int to store the counter, so searching cluster is very efficient.
> With this, scap_swap_map() overhead disappears.
> 
> This might help low end SD card swap too. Because if the cluster is aligned, SD
> firmware can do flash erase more efficiently.
> 
> The downside is the cluster must be aligned to 256 pages, which will reduce the
> chance to find a cluster.
> 

hm.  How serious is this downside?

>
> ...
>
> @@ -2020,12 +2052,19 @@ SYSCALL_DEFINE2(swapon, const char __use
>  		goto bad_swap;
>  	}
>  
> +	swap_cluster_count = vzalloc(DIV_ROUND_UP(maxpages, SWAPFILE_CLUSTER) *
> +					sizeof(int));

[ Actually sizeof(unsigned int).  Or, probably safer, sizeof(*swap_cluster_count)]

How large is this allocation?  swap-size-in-bytes/256k, methinks.  So
64kbytes for a 16G swap partition?  That sounds acceptable.  Something
like lib/flex_array.c could be used here perhaps, although that would
involve memory allocations at awkward times.

> +	if (!swap_cluster_count) {
> +		error = -ENOMEM;
> +		goto bad_swap;
> +	}

I shall await Hugh review on this patchset ;)

--
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:[~2012-10-22 21:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-22  2:30 [RFC 1/2]swap: add a simple buddy allocator Shaohua Li
2012-10-22 21:10 ` Andrew Morton [this message]
2012-10-25  0:20 ` Minchan Kim
2012-10-26  2:29   ` Shaohua Li
2012-10-25 11:35 ` Ni zhan Chen

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=20121022141021.40cac432.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=linux-mm@kvack.org \
    --cc=riel@redhat.com \
    --cc=shli@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.