From: Andrew Morton <akpm@linux-foundation.org>
To: Markus Metzger <markus.t.metzger@intel.com>
Cc: a.p.zijlstra@chello.nl, markus.t.metzger@gmail.com,
roland@redhat.com, eranian@googlemail.com, oleg@redhat.com,
juan.villacis@intel.com, ak@linux.jf.intel.com,
linux-kernel@vger.kernel.org, mingo@elte.hu, tglx@linutronix.de,
hpa@zytor.com
Subject: Re: [rfc 1/2] x86, bts, mm: buffer allocation
Date: Fri, 24 Apr 2009 01:03:26 -0700 [thread overview]
Message-ID: <20090424010326.e85ddb93.akpm@linux-foundation.org> (raw)
In-Reply-To: <20090424095143.A30265@sedona.ch.intel.com>
On Fri, 24 Apr 2009 09:51:43 +0200 Markus Metzger <markus.t.metzger@intel.com> wrote:
> --- a/mm/mlock.c
> +++ b/mm/mlock.c
> @@ -629,38 +629,36 @@ void user_shm_unlock(size_t size, struct
> free_uid(user);
> }
>
> -void *alloc_locked_buffer(size_t size)
> +int account_locked_memory(struct mm_struct *mm, struct rlimit *rlim,
> + size_t size)
> {
> - unsigned long rlim, vm, pgsz;
> - void *buffer = NULL;
> + unsigned long lim, vm, pgsz;
> + int error = -ENOMEM;
>
> pgsz = PAGE_ALIGN(size) >> PAGE_SHIFT;
>
> - down_write(¤t->mm->mmap_sem);
> -
> - rlim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
> - vm = current->mm->total_vm + pgsz;
> - if (rlim < vm)
> - goto out;
> + down_write(&mm->mmap_sem);
>
> - rlim = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
> - vm = current->mm->locked_vm + pgsz;
> - if (rlim < vm)
> + lim = rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
> + vm = mm->total_vm + pgsz;
> + if (lim < vm)
> goto out;
>
> - buffer = kzalloc(size, GFP_KERNEL);
> - if (!buffer)
> + lim = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
> + vm = mm->locked_vm + pgsz;
> + if (lim < vm)
> goto out;
>
> - current->mm->total_vm += pgsz;
> - current->mm->locked_vm += pgsz;
> + mm->total_vm += pgsz;
> + mm->locked_vm += pgsz;
>
> + error = 0;
> out:
> - up_write(¤t->mm->mmap_sem);
> - return buffer;
> + up_write(&mm->mmap_sem);
> + return error;
> }
Looks OK to me. Getting that GFP_KERNEL allocation out from inside
mmap_sem can only be good.
next prev parent reply other threads:[~2009-04-24 8:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-24 7:51 [rfc 1/2] x86, bts, mm: buffer allocation Markus Metzger
2009-04-24 8:03 ` Andrew Morton [this message]
2009-05-07 9:26 ` [tip:tracing/core] x86, bts, mm: clean up " tip-bot for Markus Metzger
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=20090424010326.e85ddb93.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=a.p.zijlstra@chello.nl \
--cc=ak@linux.jf.intel.com \
--cc=eranian@googlemail.com \
--cc=hpa@zytor.com \
--cc=juan.villacis@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=markus.t.metzger@gmail.com \
--cc=markus.t.metzger@intel.com \
--cc=mingo@elte.hu \
--cc=oleg@redhat.com \
--cc=roland@redhat.com \
--cc=tglx@linutronix.de \
/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