linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/mmap.c: optimization of do_mmap_pgoff function
@ 2015-06-06  9:54 Piotr Kwapulinski
  2015-06-08  8:17 ` Michal Hocko
  2015-06-08 15:42 ` Rik van Riel
  0 siblings, 2 replies; 3+ messages in thread
From: Piotr Kwapulinski @ 2015-06-06  9:54 UTC (permalink / raw)
  To: akpm
  Cc: kirill.shutemov, riel, mhocko, sasha.levin, dave, koct9i, pfeiner,
	dh.herrmann, vishnu.ps, linux-mm, linux-kernel, Piotr Kwapulinski

The simple check for zero length memory mapping may be performed
earlier. It causes that in case of zero length memory mapping some
unnecessary code is not executed at all. It does not make the code less
readable and saves some CPU cycles.

Signed-off-by: Piotr Kwapulinski <kwapulinski.piotr@gmail.com>
---
 mm/mmap.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index bb50cac..aa632ad 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1258,6 +1258,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
 
 	*populate = 0;
 
+	if (!len)
+		return -EINVAL;
+
 	/*
 	 * Does the application expect PROT_READ to imply PROT_EXEC?
 	 *
@@ -1268,9 +1271,6 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
 		if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
 			prot |= PROT_EXEC;
 
-	if (!len)
-		return -EINVAL;
-
 	if (!(flags & MAP_FIXED))
 		addr = round_hint_to_min(addr);
 
-- 
2.3.7

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/mmap.c: optimization of do_mmap_pgoff function
  2015-06-06  9:54 [PATCH] mm/mmap.c: optimization of do_mmap_pgoff function Piotr Kwapulinski
@ 2015-06-08  8:17 ` Michal Hocko
  2015-06-08 15:42 ` Rik van Riel
  1 sibling, 0 replies; 3+ messages in thread
From: Michal Hocko @ 2015-06-08  8:17 UTC (permalink / raw)
  To: Piotr Kwapulinski
  Cc: akpm, kirill.shutemov, riel, sasha.levin, dave, koct9i, pfeiner,
	dh.herrmann, vishnu.ps, linux-mm, linux-kernel

On Sat 06-06-15 11:54:32, Piotr Kwapulinski wrote:
> The simple check for zero length memory mapping may be performed
> earlier. It causes that in case of zero length memory mapping some
> unnecessary code is not executed at all. It does not make the code less
> readable and saves some CPU cycles.
> 
> Signed-off-by: Piotr Kwapulinski <kwapulinski.piotr@gmail.com>

Acked-by: Michal Hocko <mhocko@suse.cz>

> ---
>  mm/mmap.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/mmap.c b/mm/mmap.c
> index bb50cac..aa632ad 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -1258,6 +1258,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
>  
>  	*populate = 0;
>  
> +	if (!len)
> +		return -EINVAL;
> +
>  	/*
>  	 * Does the application expect PROT_READ to imply PROT_EXEC?
>  	 *
> @@ -1268,9 +1271,6 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
>  		if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
>  			prot |= PROT_EXEC;
>  
> -	if (!len)
> -		return -EINVAL;
> -
>  	if (!(flags & MAP_FIXED))
>  		addr = round_hint_to_min(addr);
>  
> -- 
> 2.3.7
> 

-- 
Michal Hocko
SUSE Labs

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/mmap.c: optimization of do_mmap_pgoff function
  2015-06-06  9:54 [PATCH] mm/mmap.c: optimization of do_mmap_pgoff function Piotr Kwapulinski
  2015-06-08  8:17 ` Michal Hocko
@ 2015-06-08 15:42 ` Rik van Riel
  1 sibling, 0 replies; 3+ messages in thread
From: Rik van Riel @ 2015-06-08 15:42 UTC (permalink / raw)
  To: Piotr Kwapulinski, akpm
  Cc: kirill.shutemov, mhocko, sasha.levin, dave, koct9i, pfeiner,
	dh.herrmann, vishnu.ps, linux-mm, linux-kernel

On 06/06/2015 05:54 AM, Piotr Kwapulinski wrote:
> The simple check for zero length memory mapping may be performed
> earlier. It causes that in case of zero length memory mapping some
> unnecessary code is not executed at all. It does not make the code less
> readable and saves some CPU cycles.
> 
> Signed-off-by: Piotr Kwapulinski <kwapulinski.piotr@gmail.com>

Acked-by: Rik van Riel <riel@redhat.com>

-- 
All rights reversed

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-06-08 15:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-06  9:54 [PATCH] mm/mmap.c: optimization of do_mmap_pgoff function Piotr Kwapulinski
2015-06-08  8:17 ` Michal Hocko
2015-06-08 15:42 ` Rik van Riel

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