From: Andrew Morton <akpm@linux-foundation.org>
To: Andi Kleen <andi@firstfloor.org>
Cc: linux-mm@kvack.org, Andrea Arcangeli <aarcange@redhat.com>,
Rik van Riel <riel@redhat.com>,
tim.c.chen@linux.intel.com, torvalds@linux-foundation.org,
lwoodman@redhat.com, mel@csn.ul.ie,
Andi Kleen <ak@linux.intel.com>
Subject: Re: [PATCH 1/4] VM/RMAP: Add infrastructure for batching the rmap chain locking
Date: Mon, 9 May 2011 14:43:24 -0700 [thread overview]
Message-ID: <20110509144324.8e79654a.akpm@linux-foundation.org> (raw)
In-Reply-To: <1304623972-9159-2-git-send-email-andi@firstfloor.org>
On Thu, 5 May 2011 12:32:49 -0700
Andi Kleen <andi@firstfloor.org> wrote:
> From: Andi Kleen <ak@linux.intel.com>
>
> In fork and exit it's quite common to take same rmap chain locks
> again and again when the whole address space is processed for a
> address space that has a lot of sharing. Also since the locking
> has changed to always lock the root anon_vma this can be very
> contended.
>
> This patch adds a simple wrapper to batch these lock acquisitions
> and only reaquire the lock when another is needed. The main
> advantage is that when multiple processes are doing this in
> parallel they will avoid a lot of communication overhead
> on the lock cache line.
>
> I added a simple lock break (100 locks) for paranoia reason,
> but it's unclear if that's needed or not.
>
> Cc: Andrea Arcangeli <aarcange@redhat.com>
> Cc: Rik van Riel <riel@redhat.com>
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> ---
> include/linux/rmap.h | 38 ++++++++++++++++++++++++++++++++++++++
> 1 files changed, 38 insertions(+), 0 deletions(-)
>
> diff --git a/include/linux/rmap.h b/include/linux/rmap.h
> index 830e65d..d5bb9f8 100644
> --- a/include/linux/rmap.h
> +++ b/include/linux/rmap.h
> @@ -113,6 +113,44 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
> spin_unlock(&anon_vma->root->lock);
> }
>
> +/*
> + * Batched locking for anon VMA chains to avoid too much cache line
> + * bouncing.
> + */
> +
> +#define AVL_LOCKBREAK 500
> +
> +struct anon_vma_lock_state {
> + struct anon_vma *root_anon_vma;
> + int counter;
> +};
> +
> +static inline void init_anon_vma_lock_batch(struct anon_vma_lock_state *avs)
> +{
> + avs->root_anon_vma = NULL;
> + avs->counter = 0;
> +}
This should be called anon_vma_lock_batch_init().
> +static inline void anon_vma_lock_batch(struct anon_vma *anon_vma,
> + struct anon_vma_lock_state *state)
> +{
> + if (state->root_anon_vma == anon_vma->root &&
> + state->counter++ < AVL_LOCKBREAK)
> + return;
> + if (state->root_anon_vma) {
> + state->counter = 0;
> + spin_unlock(&state->root_anon_vma->lock);
> + }
> + state->root_anon_vma = anon_vma->root;
> + spin_lock(&state->root_anon_vma->lock);
> +}
hm, that's a bit large for inlining.
> +static inline void anon_vma_unlock_batch(struct anon_vma_lock_state *avs)
> +{
> + if (avs->root_anon_vma)
> + spin_unlock(&avs->root_anon_vma->lock);
> +}
> +
> /*
> * anon_vma helper functions.
> */
The code doesn't build - the patchset forgot to add `spinlock_t lock'
to the anon_vma.
After fixing that and doing an allnoconfig x86_64 build, the patchset
takes rmap.o's .text from 6167 bytes to 6551. This is likely to be a
regression for uniprocessor machines. What can we do about this?
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2011-05-09 21:44 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-05 19:32 Batch locking for rmap fork/exit processing Andi Kleen
2011-05-05 19:32 ` [PATCH 1/4] VM/RMAP: Add infrastructure for batching the rmap chain locking Andi Kleen
2011-05-06 15:59 ` Rik van Riel
2011-05-09 21:43 ` Andrew Morton [this message]
2011-05-09 22:23 ` Andi Kleen
2011-05-09 22:28 ` Andrew Morton
2011-05-09 23:02 ` Andi Kleen
2011-05-09 23:16 ` Andrew Morton
2011-05-10 0:05 ` Andi Kleen
2011-05-10 1:26 ` Andrew Morton
2011-05-10 1:27 ` Rik van Riel
2011-05-10 1:48 ` Andrew Morton
2011-05-05 19:32 ` [PATCH 2/4] VM/RMAP: Batch anon vma chain root locking in fork Andi Kleen
2011-05-06 15:59 ` Rik van Riel
2011-05-05 19:32 ` [PATCH 3/4] VM/RMAP: Batch anon_vma_unlink in exit Andi Kleen
2011-05-06 16:48 ` Rik van Riel
2011-05-05 19:32 ` [PATCH 4/4] VM/RMAP: Move avc freeing outside the lock Andi Kleen
2011-05-06 16:52 ` Rik van Riel
2011-05-06 16:44 ` Batch locking for rmap fork/exit processing Linus Torvalds
2011-05-06 17:05 ` Andi Kleen
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=20110509144324.8e79654a.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=aarcange@redhat.com \
--cc=ak@linux.intel.com \
--cc=andi@firstfloor.org \
--cc=linux-mm@kvack.org \
--cc=lwoodman@redhat.com \
--cc=mel@csn.ul.ie \
--cc=riel@redhat.com \
--cc=tim.c.chen@linux.intel.com \
--cc=torvalds@linux-foundation.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