All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Fernandes <agnel.joel@gmail.com>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joel Fernandes <joel.opensrc@gmail.com>,
	Jisheng Zhang <jszhang@marvell.com>,
	npiggin@kernel.dk,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-mm@kvack.org, rientjes@google.com,
	Andrew Morton <akpm@linux-foundation.org>,
	mgorman@techsingularity.net, iamjoonsoo.kim@lge.com,
	Linux ARM Kernel List <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH] mm/vmalloc: reduce the number of lazy_max_pages to reduce latency
Date: Mon, 10 Oct 2016 22:06:25 -0700	[thread overview]
Message-ID: <CAD=GYpZQOQYE7x0kGTmLSeybh4Tn-CCEDouzkFVkdevq02j3SA@mail.gmail.com> (raw)
In-Reply-To: <20161009192610.GB2718@nuc-i3427.alporthouse.com>

On Sun, Oct 9, 2016 at 12:26 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> On Sun, Oct 09, 2016 at 12:00:31PM -0700, Joel Fernandes wrote:
>> Ok. So I'll submit a patch with mutex for purge_lock and use
>> cond_resched_lock for the vmap_area_lock as you suggested. I'll also
>> drop the lazy_max_pages to 8MB as Andi suggested to reduce the lock
>> hold time. Let me know if you have any objections.
>
> The downside of using a mutex here though, is that we may be called
> from contexts that cannot sleep (alloc_vmap_area), or reschedule for
> that matter! If we change the notion of purged, we can forgo the mutex
> in favour of spinning on the direct reclaim path. That just leaves the
> complication of whether to use cond_resched_lock() or a lock around
> the individual __free_vmap_area().

Good point. I agree with you. I think we still need to know if purging
is in progress to preserve previous trylock behavior. How about
something like the following diff? (diff is untested).

This drops the purge lock and uses a ref count to indicate if purging
is in progress, so that callers who don't want to purge if purging is
already in progress can be kept happy. Also I am reducing vmap_lazy_nr
as we go, and, not all at once, so that we don't reduce the counter
too soon as we're not holding purge lock anymore. Lastly, I added the
cond_resched as you suggested.

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index f2481cb..5616ca4 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -626,7 +626,7 @@ void set_iounmap_nonlazy(void)
 static void __purge_vmap_area_lazy(unsigned long *start, unsigned long *end,
                                        int sync, int force_flush)
 {
-       static DEFINE_SPINLOCK(purge_lock);
+       static atomic_t purging;
        struct llist_node *valist;
        struct vmap_area *va;
        struct vmap_area *n_va;
@@ -638,10 +638,10 @@ static void __purge_vmap_area_lazy(unsigned long
*start, unsigned long *end,
         * the case that isn't actually used at the moment anyway.
         */
        if (!sync && !force_flush) {
-               if (!spin_trylock(&purge_lock))
+               if (atomic_cmpxchg(&purging, 0, 1))
                        return;
        } else
-               spin_lock(&purge_lock);
+               atomic_inc(&purging);

        if (sync)
                purge_fragmented_blocks_allcpus();
@@ -655,9 +655,6 @@ static void __purge_vmap_area_lazy(unsigned long
*start, unsigned long *end,
                nr += (va->va_end - va->va_start) >> PAGE_SHIFT;
        }

-       if (nr)
-               atomic_sub(nr, &vmap_lazy_nr);
-
        if (nr || force_flush)
                flush_tlb_kernel_range(*start, *end);

@@ -665,9 +662,11 @@ static void __purge_vmap_area_lazy(unsigned long
*start, unsigned long *end,
                spin_lock(&vmap_area_lock);
                llist_for_each_entry_safe(va, n_va, valist, purge_list)
                        __free_vmap_area(va);
+               atomic_sub(1, &vmap_lazy_nr);
+               cond_resched_lock(&vmap_area_lock);
                spin_unlock(&vmap_area_lock);
        }
-       spin_unlock(&purge_lock);
+       atomic_dec(&purging);
 }

WARNING: multiple messages have this Message-ID (diff)
From: Joel Fernandes <agnel.joel@gmail.com>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joel Fernandes <joel.opensrc@gmail.com>,
	Jisheng Zhang <jszhang@marvell.com>,
	npiggin@kernel.dk,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-mm@kvack.org, rientjes@google.com,
	Andrew Morton <akpm@linux-foundation.org>,
	mgorman@techsingularity.net, iamjoonsoo.kim@lge.com,
	Linux ARM Kernel List <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH] mm/vmalloc: reduce the number of lazy_max_pages to reduce latency
Date: Mon, 10 Oct 2016 22:06:25 -0700	[thread overview]
Message-ID: <CAD=GYpZQOQYE7x0kGTmLSeybh4Tn-CCEDouzkFVkdevq02j3SA@mail.gmail.com> (raw)
In-Reply-To: <20161009192610.GB2718@nuc-i3427.alporthouse.com>

On Sun, Oct 9, 2016 at 12:26 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> On Sun, Oct 09, 2016 at 12:00:31PM -0700, Joel Fernandes wrote:
>> Ok. So I'll submit a patch with mutex for purge_lock and use
>> cond_resched_lock for the vmap_area_lock as you suggested. I'll also
>> drop the lazy_max_pages to 8MB as Andi suggested to reduce the lock
>> hold time. Let me know if you have any objections.
>
> The downside of using a mutex here though, is that we may be called
> from contexts that cannot sleep (alloc_vmap_area), or reschedule for
> that matter! If we change the notion of purged, we can forgo the mutex
> in favour of spinning on the direct reclaim path. That just leaves the
> complication of whether to use cond_resched_lock() or a lock around
> the individual __free_vmap_area().

Good point. I agree with you. I think we still need to know if purging
is in progress to preserve previous trylock behavior. How about
something like the following diff? (diff is untested).

This drops the purge lock and uses a ref count to indicate if purging
is in progress, so that callers who don't want to purge if purging is
already in progress can be kept happy. Also I am reducing vmap_lazy_nr
as we go, and, not all at once, so that we don't reduce the counter
too soon as we're not holding purge lock anymore. Lastly, I added the
cond_resched as you suggested.

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index f2481cb..5616ca4 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -626,7 +626,7 @@ void set_iounmap_nonlazy(void)
 static void __purge_vmap_area_lazy(unsigned long *start, unsigned long *end,
                                        int sync, int force_flush)
 {
-       static DEFINE_SPINLOCK(purge_lock);
+       static atomic_t purging;
        struct llist_node *valist;
        struct vmap_area *va;
        struct vmap_area *n_va;
@@ -638,10 +638,10 @@ static void __purge_vmap_area_lazy(unsigned long
*start, unsigned long *end,
         * the case that isn't actually used at the moment anyway.
         */
        if (!sync && !force_flush) {
-               if (!spin_trylock(&purge_lock))
+               if (atomic_cmpxchg(&purging, 0, 1))
                        return;
        } else
-               spin_lock(&purge_lock);
+               atomic_inc(&purging);

        if (sync)
                purge_fragmented_blocks_allcpus();
@@ -655,9 +655,6 @@ static void __purge_vmap_area_lazy(unsigned long
*start, unsigned long *end,
                nr += (va->va_end - va->va_start) >> PAGE_SHIFT;
        }

-       if (nr)
-               atomic_sub(nr, &vmap_lazy_nr);
-
        if (nr || force_flush)
                flush_tlb_kernel_range(*start, *end);

@@ -665,9 +662,11 @@ static void __purge_vmap_area_lazy(unsigned long
*start, unsigned long *end,
                spin_lock(&vmap_area_lock);
                llist_for_each_entry_safe(va, n_va, valist, purge_list)
                        __free_vmap_area(va);
+               atomic_sub(1, &vmap_lazy_nr);
+               cond_resched_lock(&vmap_area_lock);
                spin_unlock(&vmap_area_lock);
        }
-       spin_unlock(&purge_lock);
+       atomic_dec(&purging);
 }

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

WARNING: multiple messages have this Message-ID (diff)
From: agnel.joel@gmail.com (Joel Fernandes)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] mm/vmalloc: reduce the number of lazy_max_pages to reduce latency
Date: Mon, 10 Oct 2016 22:06:25 -0700	[thread overview]
Message-ID: <CAD=GYpZQOQYE7x0kGTmLSeybh4Tn-CCEDouzkFVkdevq02j3SA@mail.gmail.com> (raw)
In-Reply-To: <20161009192610.GB2718@nuc-i3427.alporthouse.com>

On Sun, Oct 9, 2016 at 12:26 PM, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> On Sun, Oct 09, 2016 at 12:00:31PM -0700, Joel Fernandes wrote:
>> Ok. So I'll submit a patch with mutex for purge_lock and use
>> cond_resched_lock for the vmap_area_lock as you suggested. I'll also
>> drop the lazy_max_pages to 8MB as Andi suggested to reduce the lock
>> hold time. Let me know if you have any objections.
>
> The downside of using a mutex here though, is that we may be called
> from contexts that cannot sleep (alloc_vmap_area), or reschedule for
> that matter! If we change the notion of purged, we can forgo the mutex
> in favour of spinning on the direct reclaim path. That just leaves the
> complication of whether to use cond_resched_lock() or a lock around
> the individual __free_vmap_area().

Good point. I agree with you. I think we still need to know if purging
is in progress to preserve previous trylock behavior. How about
something like the following diff? (diff is untested).

This drops the purge lock and uses a ref count to indicate if purging
is in progress, so that callers who don't want to purge if purging is
already in progress can be kept happy. Also I am reducing vmap_lazy_nr
as we go, and, not all at once, so that we don't reduce the counter
too soon as we're not holding purge lock anymore. Lastly, I added the
cond_resched as you suggested.

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index f2481cb..5616ca4 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -626,7 +626,7 @@ void set_iounmap_nonlazy(void)
 static void __purge_vmap_area_lazy(unsigned long *start, unsigned long *end,
                                        int sync, int force_flush)
 {
-       static DEFINE_SPINLOCK(purge_lock);
+       static atomic_t purging;
        struct llist_node *valist;
        struct vmap_area *va;
        struct vmap_area *n_va;
@@ -638,10 +638,10 @@ static void __purge_vmap_area_lazy(unsigned long
*start, unsigned long *end,
         * the case that isn't actually used at the moment anyway.
         */
        if (!sync && !force_flush) {
-               if (!spin_trylock(&purge_lock))
+               if (atomic_cmpxchg(&purging, 0, 1))
                        return;
        } else
-               spin_lock(&purge_lock);
+               atomic_inc(&purging);

        if (sync)
                purge_fragmented_blocks_allcpus();
@@ -655,9 +655,6 @@ static void __purge_vmap_area_lazy(unsigned long
*start, unsigned long *end,
                nr += (va->va_end - va->va_start) >> PAGE_SHIFT;
        }

-       if (nr)
-               atomic_sub(nr, &vmap_lazy_nr);
-
        if (nr || force_flush)
                flush_tlb_kernel_range(*start, *end);

@@ -665,9 +662,11 @@ static void __purge_vmap_area_lazy(unsigned long
*start, unsigned long *end,
                spin_lock(&vmap_area_lock);
                llist_for_each_entry_safe(va, n_va, valist, purge_list)
                        __free_vmap_area(va);
+               atomic_sub(1, &vmap_lazy_nr);
+               cond_resched_lock(&vmap_area_lock);
                spin_unlock(&vmap_area_lock);
        }
-       spin_unlock(&purge_lock);
+       atomic_dec(&purging);
 }

  reply	other threads:[~2016-10-11  5:06 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-29  7:34 [PATCH] mm/vmalloc: reduce the number of lazy_max_pages to reduce latency Jisheng Zhang
2016-09-29  7:34 ` Jisheng Zhang
2016-09-29  7:34 ` Jisheng Zhang
2016-09-29  8:18 ` Chris Wilson
2016-09-29  8:18   ` Chris Wilson
2016-09-29  8:18   ` Chris Wilson
2016-09-29  8:28   ` Jisheng Zhang
2016-09-29  8:28     ` Jisheng Zhang
2016-09-29  8:28     ` Jisheng Zhang
2016-09-29 11:07     ` Chris Wilson
2016-09-29 11:07       ` Chris Wilson
2016-09-29 11:07       ` Chris Wilson
2016-09-29 11:18       ` Jisheng Zhang
2016-09-29 11:18         ` Jisheng Zhang
2016-09-29 11:18         ` Jisheng Zhang
2016-10-09  3:43   ` Joel Fernandes
2016-10-09  3:43     ` Joel Fernandes
2016-10-09  3:43     ` Joel Fernandes
2016-10-09 12:42     ` Chris Wilson
2016-10-09 12:42       ` Chris Wilson
2016-10-09 12:42       ` Chris Wilson
2016-10-09 19:00       ` Joel Fernandes
2016-10-09 19:00         ` Joel Fernandes
2016-10-09 19:00         ` Joel Fernandes
2016-10-09 19:26         ` Chris Wilson
2016-10-09 19:26           ` Chris Wilson
2016-10-09 19:26           ` Chris Wilson
2016-10-11  5:06           ` Joel Fernandes [this message]
2016-10-11  5:06             ` Joel Fernandes
2016-10-11  5:06             ` Joel Fernandes
2016-10-11  5:34             ` Joel Fernandes
2016-10-11  5:34               ` Joel Fernandes
2016-10-11  5:34               ` Joel Fernandes

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='CAD=GYpZQOQYE7x0kGTmLSeybh4Tn-CCEDouzkFVkdevq02j3SA@mail.gmail.com' \
    --to=agnel.joel@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=chris@chris-wilson.co.uk \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=joel.opensrc@gmail.com \
    --cc=jszhang@marvell.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=npiggin@kernel.dk \
    --cc=rientjes@google.com \
    /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.