linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Anshuman Khandual <khandual@linux.vnet.ibm.com>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, mike.kravetz@oracle.com
Subject: [RFC] mm/mremap: Remove redundant checks inside vma_expandable()
Date: Mon, 10 Jul 2017 16:40:59 +0530	[thread overview]
Message-ID: <20170710111059.30795-1-khandual@linux.vnet.ibm.com> (raw)

As 'delta' is an unsigned long, 'end' (vma->vm_end + delta) cannot
be less than 'vma->vm_end'. Checking for availability of virtual
address range at the end of the VMA for the incremental size is
also reduntant at this point. Hence drop them both.

Signed-off-by: Anshuman Khandual <khandual@linux.vnet.ibm.com>
---

The following test program achieves fatser execution time with
this change.

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/time.h>

#define ALLOC_SIZE 0x10000UL
#define MAX_COUNT 1024 * 1024

int main(int argc, char *argv[])
{
        unsigned long count;
        char *ptr;

        ptr = mmap(NULL, ALLOC_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE| MAP_ANONYMOUS, -1, 0);
        if (ptr == MAP_FAILED) {
                perror("map() failed");
                return -1;
        }
        memset(ptr, 0, ALLOC_SIZE);

        for (count = 1; count <= MAX_COUNT; count++) {
                ptr =  (char *) mremap(ptr, ALLOC_SIZE * count, ALLOC_SIZE * (count + 1), 1);
                if (ptr == MAP_FAILED) {
                        perror("mremap() failed");
                        printf("At %lu size", ALLOC_SIZE * (count + 1));
                        return -1;
                }
                /*
                memset(ptr, 0, ALLOC_SIZE * (count + 1));
                */
        }


        for (count = MAX_COUNT; count > 1; count--) {
                ptr =  (char *) mremap(ptr, ALLOC_SIZE * count, ALLOC_SIZE * (count - 1), 1);
                if (ptr == MAP_FAILED) {
                        perror("mremap() failed");
                        printf("At %lu size", ALLOC_SIZE * (count - 1));
                        return -1;
                }
                /*
                memset(ptr, 0, ALLOC_SIZE * (count - 1));
                */
        }
        return 0;
}


 mm/mremap.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/mm/mremap.c b/mm/mremap.c
index cd8a1b1..b937c28 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -487,12 +487,9 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
 static int vma_expandable(struct vm_area_struct *vma, unsigned long delta)
 {
 	unsigned long end = vma->vm_end + delta;
-	if (end < vma->vm_end) /* overflow */
-		return 0;
-	if (vma->vm_next && vma->vm_next->vm_start < end) /* intersection */
-		return 0;
-	if (get_unmapped_area(NULL, vma->vm_start, end - vma->vm_start,
-			      0, MAP_FIXED) & ~PAGE_MASK)
+
+	/* Intersection with next VMA */
+	if (vma->vm_next && vma->vm_next->vm_start < end)
 		return 0;
 	return 1;
 }
-- 
1.8.5.2

--
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:[~2017-07-10 11:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-10 11:10 Anshuman Khandual [this message]
2017-07-10 13:49 ` [RFC] mm/mremap: Remove redundant checks inside vma_expandable() Michal Hocko
2017-07-11  4:28   ` Anshuman Khandual
2017-07-11  6:03     ` Michal Hocko
2017-07-11  6:26       ` Vlastimil Babka
2017-07-11  6:50         ` Michal Hocko
2017-07-11  6:56           ` Vlastimil Babka
2017-07-11  7:16             ` Michal Hocko
2017-07-11  7:22               ` Michal Hocko
2017-07-11 11:19                 ` Anshuman Khandual
2017-07-11 11:11               ` Anshuman Khandual
2017-07-11 11:08             ` Anshuman Khandual
2017-07-11 11:22               ` Michal Hocko
2017-07-19  6:49                 ` Anshuman Khandual
2017-07-11 11:06           ` Anshuman Khandual
2017-07-11  9:44         ` Anshuman Khandual
2017-07-11  4:29   ` Anshuman Khandual

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=20170710111059.30795-1-khandual@linux.vnet.ibm.com \
    --to=khandual@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.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).