* [PATCH] mm/mmap.c: Remove redundant local variables for may_expand_vm()
@ 2015-11-09 21:41 Chen Gang
2015-11-10 1:39 ` Naoya Horiguchi
2015-11-10 22:40 ` Chen Gang
0 siblings, 2 replies; 4+ messages in thread
From: Chen Gang @ 2015-11-09 21:41 UTC (permalink / raw)
To: Andrew Morton, oleg, kirill.shutemov, dave, aarcange
Cc: Linux Memory, kernel mailing list
[-- Attachment #1: Type: text/plain, Size: 938 bytes --]
>From 7050c267d8dda220226067039d815593d2f9a874 Mon Sep 17 00:00:00 2001
From: Chen Gang <gang.chen.5i5j@gmail.com>
Date: Tue, 10 Nov 2015 05:32:38 +0800
Subject: [PATCH] mm/mmap.c: Remove redundant local variables for may_expand_vm()
After merge the related code into one line, the code is still simple and
meaningful enough.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
mm/mmap.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/mm/mmap.c b/mm/mmap.c
index 2ce04a6..a515260 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2988,12 +2988,7 @@ out:
*/
int may_expand_vm(struct mm_struct *mm, unsigned long npages)
{
- unsigned long cur = mm->total_vm; /* pages */
- unsigned long lim;
-
- lim = rlimit(RLIMIT_AS)>> PAGE_SHIFT;
-
- if (cur + npages> lim)
+ if (mm->total_vm + npages> (rlimit(RLIMIT_AS)>> PAGE_SHIFT))
return 0;
return 1;
}
--
1.9.3
[-- Attachment #2: 0001-mm-mmap.c-Remove-redundant-local-variables-for-may_e.patch --]
[-- Type: application/octet-stream, Size: 895 bytes --]
From 7050c267d8dda220226067039d815593d2f9a874 Mon Sep 17 00:00:00 2001
From: Chen Gang <gang.chen.5i5j@gmail.com>
Date: Tue, 10 Nov 2015 05:32:38 +0800
Subject: [PATCH] mm/mmap.c: Remove redundant local variables for may_expand_vm()
After merge the related code into one line, the code is still simple and
meaningful enough.
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
mm/mmap.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/mm/mmap.c b/mm/mmap.c
index 2ce04a6..a515260 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2988,12 +2988,7 @@ out:
*/
int may_expand_vm(struct mm_struct *mm, unsigned long npages)
{
- unsigned long cur = mm->total_vm; /* pages */
- unsigned long lim;
-
- lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
-
- if (cur + npages > lim)
+ if (mm->total_vm + npages > (rlimit(RLIMIT_AS) >> PAGE_SHIFT))
return 0;
return 1;
}
--
1.9.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/mmap.c: Remove redundant local variables for may_expand_vm()
2015-11-09 21:41 [PATCH] mm/mmap.c: Remove redundant local variables for may_expand_vm() Chen Gang
@ 2015-11-10 1:39 ` Naoya Horiguchi
2015-11-10 22:22 ` Chen Gang
2015-11-10 22:40 ` Chen Gang
1 sibling, 1 reply; 4+ messages in thread
From: Naoya Horiguchi @ 2015-11-10 1:39 UTC (permalink / raw)
To: Chen Gang
Cc: Andrew Morton, oleg, kirill.shutemov, dave, aarcange,
Linux Memory, kernel mailing list
On Tue, Nov 10, 2015 at 05:41:08AM +0800, Chen Gang wrote:
> From 7050c267d8dda220226067039d815593d2f9a874 Mon Sep 17 00:00:00 2001
> From: Chen Gang <gang.chen.5i5j@gmail.com>
> Date: Tue, 10 Nov 2015 05:32:38 +0800
> Subject: [PATCH] mm/mmap.c: Remove redundant local variables for may_expand_vm()
>
> After merge the related code into one line, the code is still simple and
> meaningful enough.
>
> Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
I agree that this function can be cleaned up.
> ---
> mm/mmap.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 2ce04a6..a515260 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2988,12 +2988,7 @@ out:
> */
> int may_expand_vm(struct mm_struct *mm, unsigned long npages)
marking inline?
> {
> - unsigned long cur = mm->total_vm; /* pages */
> - unsigned long lim;
> -
> - lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
> -
> - if (cur + npages > lim)
> + if (mm->total_vm + npages > (rlimit(RLIMIT_AS) >> PAGE_SHIFT))
> return 0;
> return 1;
How about doing simply
return mm->total_vm + npages <= (rlimit(RLIMIT_AS) >> PAGE_SHIFT);
? These changes save some bytes :)
text data bss dec hex filename
20566 2250 40 22856 5948 mm/mmap.o (before)
text data bss dec hex filename
20542 2250 40 22832 5930 mm/mmap.o (after)
Thanks,
Naoya Horiguchi
--
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] 4+ messages in thread
* Re: [PATCH] mm/mmap.c: Remove redundant local variables for may_expand_vm()
2015-11-10 1:39 ` Naoya Horiguchi
@ 2015-11-10 22:22 ` Chen Gang
0 siblings, 0 replies; 4+ messages in thread
From: Chen Gang @ 2015-11-10 22:22 UTC (permalink / raw)
To: Naoya Horiguchi
Cc: Andrew Morton, oleg, kirill.shutemov, dave, aarcange,
Linux Memory, kernel mailing list
On 11/10/15 09:39, Naoya Horiguchi wrote:
> On Tue, Nov 10, 2015 at 05:41:08AM +0800, Chen Gang wrote:
>> diff --git a/mm/mmap.c b/mm/mmap.c
>> index 2ce04a6..a515260 100644
>> --- a/mm/mmap.c
>> +++ b/mm/mmap.c
>> @@ -2988,12 +2988,7 @@ out:
>> */
>> int may_expand_vm(struct mm_struct *mm, unsigned long npages)
>
> marking inline?
>
For me, inline is OK. But I guess, it depends on the members tastes: "It
is used at 5 areas within mm, inline will expand the binary size".
>> {
>> - unsigned long cur = mm->total_vm; /* pages */
>> - unsigned long lim;
>> -
>> - lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
>> -
>> - if (cur + npages > lim)
>> + if (mm->total_vm + npages > (rlimit(RLIMIT_AS) >> PAGE_SHIFT))
>> return 0;
>> return 1;
>
> How about doing simply
>
> return mm->total_vm + npages <= (rlimit(RLIMIT_AS) >> PAGE_SHIFT);
>
For me, only one line is OK. But I guess, it also depends on the members
tastes: does it let code a little complex?
If we can use bool instead of int for may_epand_mm() return value, I
guess, one line implementation (your idea) will be OK to all members.
> ? These changes save some bytes :)
>
> text data bss dec hex filename
> 20566 2250 40 22856 5948 mm/mmap.o (before)
>
> text data bss dec hex filename
> 20542 2250 40 22832 5930 mm/mmap.o (after)
>
> Thanks,
> Naoya Horiguchi
>
Thanks.
--
Chen Gang (陈刚)
Open, share, and attitude like air, water, and life which God blessed
--
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] 4+ messages in thread
* Re: [PATCH] mm/mmap.c: Remove redundant local variables for may_expand_vm()
2015-11-09 21:41 [PATCH] mm/mmap.c: Remove redundant local variables for may_expand_vm() Chen Gang
2015-11-10 1:39 ` Naoya Horiguchi
@ 2015-11-10 22:40 ` Chen Gang
1 sibling, 0 replies; 4+ messages in thread
From: Chen Gang @ 2015-11-10 22:40 UTC (permalink / raw)
To: Andrew Morton, oleg, kirill.shutemov, dave, aarcange
Cc: Linux Memory, kernel mailing list
Next, I shall read through another files.
I should not only send trivial patches to community, I should continue
learning mm.
Until now, I did not spend enough time resources on mm. So next, I
should spend a little more my free time resources on mm.
Welcome any ideas, suggestions, and completions from any members.
Thanks.
On 11/10/15 05:41, Chen Gang wrote:
> From 7050c267d8dda220226067039d815593d2f9a874 Mon Sep 17 00:00:00 2001
> From: Chen Gang <gang.chen.5i5j@gmail.com>
> Date: Tue, 10 Nov 2015 05:32:38 +0800
> Subject: [PATCH] mm/mmap.c: Remove redundant local variables for may_expand_vm()
>
> After merge the related code into one line, the code is still simple and
> meaningful enough.
>
> Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
> ---
> mm/mmap.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 2ce04a6..a515260 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2988,12 +2988,7 @@ out:
> */
> int may_expand_vm(struct mm_struct *mm, unsigned long npages)
> {
> - unsigned long cur = mm->total_vm; /* pages */
> - unsigned long lim;
> -
> - lim = rlimit(RLIMIT_AS)>> PAGE_SHIFT;
> -
> - if (cur + npages> lim)
> + if (mm->total_vm + npages> (rlimit(RLIMIT_AS)>> PAGE_SHIFT))
> return 0;
> return 1;
> }
> --
> 1.9.3
>
>
>
--
Chen Gang (陈刚)
Open, share, and attitude like air, water, and life which God blessed
--
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] 4+ messages in thread
end of thread, other threads:[~2015-11-10 22:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-09 21:41 [PATCH] mm/mmap.c: Remove redundant local variables for may_expand_vm() Chen Gang
2015-11-10 1:39 ` Naoya Horiguchi
2015-11-10 22:22 ` Chen Gang
2015-11-10 22:40 ` Chen Gang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox