linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Uladzislau Rezki (Sony)" <urezki@gmail.com>
To: linux-mm@kvack.org
Cc: LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	Thomas Garnier <thgarnie@google.com>,
	Oleksiy Avramchenko <oleksiy.avramchenko@sonymobile.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Uladzislau Rezki (Sony)" <urezki@gmail.com>
Subject: [RFC v1] mm: add the preempt check into alloc_vmap_area()
Date: Tue, 27 Feb 2018 11:22:59 +0100	[thread overview]
Message-ID: <20180227102259.4629-1-urezki@gmail.com> (raw)

During finding a suitable hole in the vmap_area_list
there is an explicit rescheduling check for latency reduction.
We do it, since there are workloads which are sensitive for
long (more than 1 millisecond) preemption off scenario.

Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
---
 mm/vmalloc.c | 57 +++++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 45 insertions(+), 12 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 673942094328..60a57752f8fc 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -325,6 +325,7 @@ EXPORT_SYMBOL(vmalloc_to_pfn);
 
 #define VM_LAZY_FREE	0x02
 #define VM_VM_AREA	0x04
+#define VM_LAZY_FREE_DEFER	0x08
 
 static DEFINE_SPINLOCK(vmap_area_lock);
 /* Export for kexec only */
@@ -491,6 +492,20 @@ static struct vmap_area *alloc_vmap_area(unsigned long size,
 		if (addr + size < addr)
 			goto overflow;
 
+		/*
+		 * Put on hold this VA preventing it from being
+		 * removed from the list because of dropping the
+		 * vmap_area_lock. It means we are save to proceed
+		 * the search after the lock is taken again if we
+		 * were scheduled out or the spin needed a break.
+		 */
+		if (gfpflags_allow_blocking(gfp_mask) &&
+				!(first->flags & VM_LAZY_FREE_DEFER)) {
+			first->flags |= VM_LAZY_FREE_DEFER;
+			cond_resched_lock(&vmap_area_lock);
+			first->flags &= ~VM_LAZY_FREE_DEFER;
+		}
+
 		if (list_is_last(&first->list, &vmap_area_list))
 			goto found;
 
@@ -586,16 +601,6 @@ static void __free_vmap_area(struct vmap_area *va)
 }
 
 /*
- * Free a region of KVA allocated by alloc_vmap_area
- */
-static void free_vmap_area(struct vmap_area *va)
-{
-	spin_lock(&vmap_area_lock);
-	__free_vmap_area(va);
-	spin_unlock(&vmap_area_lock);
-}
-
-/*
  * Clear the pagetable entries of a given vmap_area
  */
 static void unmap_vmap_area(struct vmap_area *va)
@@ -678,6 +683,7 @@ static bool __purge_vmap_area_lazy(unsigned long start, unsigned long end)
 	struct vmap_area *va;
 	struct vmap_area *n_va;
 	bool do_free = false;
+	int va_nr_pages;
 
 	lockdep_assert_held(&vmap_purge_lock);
 
@@ -697,10 +703,19 @@ static bool __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) {
-		int nr = (va->va_end - va->va_start) >> PAGE_SHIFT;
+		if (unlikely(va->flags & VM_LAZY_FREE_DEFER)) {
+			/*
+			 * Put deferred VA back to the vmap_purge_list.
+			 * We do not need to modify vmap_lazy_nr since
+			 * the va will not be removed now.
+			 */
+			llist_add(&va->purge_list, &vmap_purge_list);
+			continue;
+		}
 
+		va_nr_pages = (va->va_end - va->va_start) >> PAGE_SHIFT;
 		__free_vmap_area(va);
-		atomic_sub(nr, &vmap_lazy_nr);
+		atomic_sub(va_nr_pages, &vmap_lazy_nr);
 		cond_resched_lock(&vmap_area_lock);
 	}
 	spin_unlock(&vmap_area_lock);
@@ -750,6 +765,24 @@ static void free_vmap_area_noflush(struct vmap_area *va)
 }
 
 /*
+ * Free a region of KVA allocated by alloc_vmap_area
+ */
+static void free_vmap_area(struct vmap_area *va)
+{
+	bool do_lazy_free = false;
+
+	spin_lock(&vmap_area_lock);
+	if (unlikely(va->flags & VM_LAZY_FREE_DEFER))
+		do_lazy_free = true;
+	else
+		__free_vmap_area(va);
+	spin_unlock(&vmap_area_lock);
+
+	if (unlikely(do_lazy_free))
+		free_vmap_area_noflush(va);
+}
+
+/*
  * Free and unmap a vmap area
  */
 static void free_unmap_vmap_area(struct vmap_area *va)
-- 
2.11.0

             reply	other threads:[~2018-02-27 10:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-27 10:22 Uladzislau Rezki (Sony) [this message]
2018-02-27 13:06 ` [RFC v1] mm: add the preempt check into alloc_vmap_area() Matthew Wilcox
2018-02-28 12:40   ` Uladzislau Rezki
2018-03-02 23:34   ` Andrew Morton
2018-03-03 21:18     ` Uladzislau Rezki

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=20180227102259.4629-1-urezki@gmail.com \
    --to=urezki@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@redhat.com \
    --cc=oleksiy.avramchenko@sonymobile.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=thgarnie@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).