linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Linux MM <linux-mm@kvack.org>,
	Quentin Casasnovas <quentin.casasnovas@oracle.com>,
	Vegard Nossum <vegard.nossum@oracle.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linuxfoundation.org>,
	Willy Tarreau <w@1wt.eu>, Andy Lutomirski <luto@amacapital.net>,
	Kees Cook <keescook@google.com>,
	Vladimir Davydov <vdavydov@virtuozzo.com>,
	Konstantin Khlebnikov <koct9i@gmail.com>,
	Pavel Emelyanov <xemul@virtuozzo.com>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>
Subject: Re: [PATCH RFC] mm: Rework virtual memory accounting
Date: Mon, 28 Dec 2015 15:10:02 -0800	[thread overview]
Message-ID: <20151228151002.0a8e44199d31f7a4fa7fc414@linux-foundation.org> (raw)
In-Reply-To: <20151228211015.GL2194@uranus>

On Tue, 29 Dec 2015 00:10:15 +0300 Cyrill Gorcunov <gorcunov@gmail.com> wrote:

> When inspecting a vague code inside prctl(PR_SET_MM_MEM)
> call (which testing the RLIMIT_DATA value to figure out
> if we're allowed to assign new @start_brk, @brk, @start_data,
> @end_data from mm_struct) it's been commited that RLIMIT_DATA
> in a form it's implemented now doesn't do anything useful
> because most of user-space libraries use mmap() syscall
> for dynamic memory allocations.
> 
> Linus suggested to convert RLIMIT_DATA rlimit into something
> suitable for anonymous memory accounting. But in this patch
> we go further, and the changes are bundled together as:
> 
>  * keep vma counting if CONFIG_PROC_FS=n, will be used for limits
>  * replace mm->shared_vm with better defined mm->data_vm
>  * account anonymous executable areas as executable
>  * account file-backed growsdown/up areas as stack
>  * drop struct file* argument from vm_stat_account
>  * enforce RLIMIT_DATA for size of data areas
> 
> This way code looks cleaner: now code/stack/data
> classification depends only on vm_flags state:
> 
>  VM_EXEC & ~VM_WRITE            -> code  (VmExe + VmLib in proc)
>  VM_GROWSUP | VM_GROWSDOWN      -> stack (VmStk)
>  VM_WRITE & ~VM_SHARED & !stack -> data  (VmData)
> 
> The rest (VmSize - VmData - VmStk - VmExe - VmLib) could be
> called "shared", but that might be strange beast like
> readonly-private or VM_IO area.
> 
>  - RLIMIT_AS            limits whole address space "VmSize"
>  - RLIMIT_STACK         limits stack "VmStk" (but each vma individually)
>  - RLIMIT_DATA          now limits "VmData"

This clashes with
mm-mmapc-remove-redundant-local-variables-for-may_expand_vm.patch,
below.  I resolved it thusly:

bool may_expand_vm(struct mm_struct *mm, vm_flags_t flags, unsigned long npages)
{
	if (mm->total_vm + npages > rlimit(RLIMIT_AS) >> PAGE_SHIFT)
		return false;

	if ((flags & (VM_WRITE | VM_SHARED | (VM_STACK_FLAGS &
				(VM_GROWSUP | VM_GROWSDOWN)))) == VM_WRITE)
		return mm->data_vm + npages <= rlimit(RLIMIT_DATA);

	return true;
}



From: Chen Gang <gang.chen.5i5j@gmail.com>
Subject: mm/mmap.c: remove redundant local variables for may_expand_vm()

Simplify may_expand_vm()

[akpm@linux-foundation.org: further simplification, per Naoya Horiguchi]
Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/mmap.c |    9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff -puN mm/mmap.c~mm-mmapc-remove-redundant-local-variables-for-may_expand_vm mm/mmap.c
--- a/mm/mmap.c~mm-mmapc-remove-redundant-local-variables-for-may_expand_vm
+++ a/mm/mmap.c
@@ -2988,14 +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)
-		return 0;
-	return 1;
+	return mm->total_vm + npages <= rlimit(RLIMIT_AS) >> PAGE_SHIFT;
 }
 
 static int special_mapping_fault(struct vm_area_struct *vma,
_

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

  parent reply	other threads:[~2015-12-28 23:10 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-28 21:10 Cyrill Gorcunov
2015-12-28 22:22 ` Linus Torvalds
2015-12-29  9:43   ` Cyrill Gorcunov
2016-01-22 19:42   ` Christian Borntraeger
2016-01-22 20:20     ` Cyrill Gorcunov
2016-01-22 20:21     ` Andrew Morton
2016-01-22 20:30     ` Linus Torvalds
2015-12-28 23:10 ` Andrew Morton [this message]
2015-12-29  9:48   ` Cyrill Gorcunov
  -- strict thread matches above, loose matches on Subject: below --
2015-12-14  8:12 [RFC 1/2] [RFC] mm: Account anon mappings as RLIMIT_DATA Konstantin Khlebnikov
2015-12-14  8:12 ` [PATCH RFC] mm: rework virtual memory accounting Konstantin Khlebnikov
2015-12-14  9:08   ` Cyrill Gorcunov

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=20151228151002.0a8e44199d31f7a4fa7fc414@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linuxfoundation.org \
    --cc=gorcunov@gmail.com \
    --cc=keescook@google.com \
    --cc=koct9i@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@amacapital.net \
    --cc=quentin.casasnovas@oracle.com \
    --cc=torvalds@linux-foundation.org \
    --cc=vdavydov@virtuozzo.com \
    --cc=vegard.nossum@oracle.com \
    --cc=w@1wt.eu \
    --cc=xemul@virtuozzo.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