LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] mm: don't account shared file pages in user_reserve_pages
@ 2015-01-29 11:51 Roman Gushchin
2015-01-29 20:11 ` Andrew Shewmaker
0 siblings, 1 reply; 3+ messages in thread
From: Roman Gushchin @ 2015-01-29 11:51 UTC (permalink / raw)
To: linux-mm
Cc: linux-kernel, Roman Gushchin, Andrew Morton, Andrew Shewmaker,
Rik van Riel, Konstantin Khlebnikov
Shared file pages are never accounted in memory overcommit code,
so it isn't reasonable to count them in a code that limits the
maximal size of a process in OVERCOMMIT_NONE mode.
If a process has few large file mappings, the consequent attempts
to allocate anonymous memory may unexpectedly fail with -ENOMEM,
while there is free memory and overcommit limit if significantly
larger than the committed amount (as displayed in /proc/meminfo).
The problem is significantly smoothed by commit c9b1d0981fcc
("mm: limit growth of 3% hardcoded other user reserve"),
which limits the impact of this check with 128Mb (tunable via sysctl),
but it can still be a problem on small machines.
Signed-off-by: Roman Gushchin <klamm@yandex-team.ru>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andrew Shewmaker <agshew@gmail.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
---
mm/mmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/mmap.c b/mm/mmap.c
index 7f684d5..151fadf 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -220,7 +220,7 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
*/
if (mm) {
reserve = sysctl_user_reserve_kbytes >> (PAGE_SHIFT - 10);
- allowed -= min(mm->total_vm / 32, reserve);
+ allowed -= min((mm->total_vm - mm->shared_vm) / 32, reserve);
}
if (percpu_counter_read_positive(&vm_committed_as) < allowed)
--
2.1.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm: don't account shared file pages in user_reserve_pages
2015-01-29 11:51 [PATCH] mm: don't account shared file pages in user_reserve_pages Roman Gushchin
@ 2015-01-29 20:11 ` Andrew Shewmaker
2015-01-30 13:30 ` Konstantin Khlebnikov
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Shewmaker @ 2015-01-29 20:11 UTC (permalink / raw)
To: Roman Gushchin
Cc: linux-mm, linux-kernel, Andrew Morton, Rik van Riel,
Konstantin Khlebnikov
On Thu, Jan 29, 2015 at 02:51:27PM +0300, Roman Gushchin wrote:
> Shared file pages are never accounted in memory overcommit code,
> so it isn't reasonable to count them in a code that limits the
> maximal size of a process in OVERCOMMIT_NONE mode.
>
> If a process has few large file mappings, the consequent attempts
> to allocate anonymous memory may unexpectedly fail with -ENOMEM,
> while there is free memory and overcommit limit if significantly
> larger than the committed amount (as displayed in /proc/meminfo).
>
> The problem is significantly smoothed by commit c9b1d0981fcc
> ("mm: limit growth of 3% hardcoded other user reserve"),
> which limits the impact of this check with 128Mb (tunable via sysctl),
> but it can still be a problem on small machines.
>
> Signed-off-by: Roman Gushchin <klamm@yandex-team.ru>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Andrew Shewmaker <agshew@gmail.com>
> Cc: Rik van Riel <riel@redhat.com>
> Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
> ---
> mm/mmap.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 7f684d5..151fadf 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -220,7 +220,7 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
> */
> if (mm) {
> reserve = sysctl_user_reserve_kbytes >> (PAGE_SHIFT - 10);
> - allowed -= min(mm->total_vm / 32, reserve);
> + allowed -= min((mm->total_vm - mm->shared_vm) / 32, reserve);
> }
>
> if (percpu_counter_read_positive(&vm_committed_as) < allowed)
> --
> 2.1.0
You're two patches conflict, don't they? Maybe you should resend
them as a patch series such that they can both be applied?
Does mm->shared_vm include memory that's mapped MAP_ANONYMOUS in
conjunction with MAP_SHARED? If so, then subtracting it could
overcommit the system OVERCOMMIT_NEVER mode.
-Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm: don't account shared file pages in user_reserve_pages
2015-01-29 20:11 ` Andrew Shewmaker
@ 2015-01-30 13:30 ` Konstantin Khlebnikov
0 siblings, 0 replies; 3+ messages in thread
From: Konstantin Khlebnikov @ 2015-01-30 13:30 UTC (permalink / raw)
To: Andrew Shewmaker, Roman Gushchin
Cc: linux-mm, linux-kernel, Andrew Morton, Rik van Riel
On 29.01.2015 23:11, Andrew Shewmaker wrote:
> On Thu, Jan 29, 2015 at 02:51:27PM +0300, Roman Gushchin wrote:
>> Shared file pages are never accounted in memory overcommit code,
>> so it isn't reasonable to count them in a code that limits the
>> maximal size of a process in OVERCOMMIT_NONE mode.
>>
>> If a process has few large file mappings, the consequent attempts
>> to allocate anonymous memory may unexpectedly fail with -ENOMEM,
>> while there is free memory and overcommit limit if significantly
>> larger than the committed amount (as displayed in /proc/meminfo).
>>
>> The problem is significantly smoothed by commit c9b1d0981fcc
>> ("mm: limit growth of 3% hardcoded other user reserve"),
>> which limits the impact of this check with 128Mb (tunable via sysctl),
>> but it can still be a problem on small machines.
>>
>> Signed-off-by: Roman Gushchin <klamm@yandex-team.ru>
>> Cc: Andrew Morton <akpm@linux-foundation.org>
>> Cc: Andrew Shewmaker <agshew@gmail.com>
>> Cc: Rik van Riel <riel@redhat.com>
>> Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
>> ---
>> mm/mmap.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/mmap.c b/mm/mmap.c
>> index 7f684d5..151fadf 100644
>> --- a/mm/mmap.c
>> +++ b/mm/mmap.c
>> @@ -220,7 +220,7 @@ int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sys_admin)
>> */
>> if (mm) {
>> reserve = sysctl_user_reserve_kbytes >> (PAGE_SHIFT - 10);
>> - allowed -= min(mm->total_vm / 32, reserve);
>> + allowed -= min((mm->total_vm - mm->shared_vm) / 32, reserve);
>> }
>>
>> if (percpu_counter_read_positive(&vm_committed_as) < allowed)
>> --
>> 2.1.0
>
> You're two patches conflict, don't they? Maybe you should resend
> them as a patch series such that they can both be applied?
I think arithmetic overflow is more important. Upper bound 128M
for user reserve makes mis-accounting of shared memory mostly invisible.
>
> Does mm->shared_vm include memory that's mapped MAP_ANONYMOUS in
> conjunction with MAP_SHARED? If so, then subtracting it could
> overcommit the system OVERCOMMIT_NEVER mode.
Yep.
Moreover shared_vm also includes file mappings with MAP_PRIVATE.
It works more likely as "maybe shared", upper bound for "file-rss"
(MM_FILEPAGES).
I think we need here total size of vmas where VM_ACCOUNT is set --
writable private mappings mapped without MAP_NORESERVE or something
like that. But total_vm after limiting with 128Mb gives almost always
the same or similar value. So, let's keep it as is.
--
Konstantin
>
> -Andrew
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-01-30 13:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-29 11:51 [PATCH] mm: don't account shared file pages in user_reserve_pages Roman Gushchin
2015-01-29 20:11 ` Andrew Shewmaker
2015-01-30 13:30 ` Konstantin Khlebnikov
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).