From: Andrew Morton <akpm@linux-foundation.org>
To: xtu4 <xiaobing.tu@intel.com>
Cc: linux-kernel@vger.kernel.org, guifang.tang@intel.com,
linX.z.chen@intel.com, "Arve Hjønnevåg" <arve@android.com>
Subject: Re: Avoid high order memory allocating with kmalloc, when read large seq file
Date: Tue, 29 Jan 2013 16:24:31 -0800 [thread overview]
Message-ID: <20130129162431.58754538.akpm@linux-foundation.org> (raw)
In-Reply-To: <510768B6.3070000@intel.com>
On Tue, 29 Jan 2013 14:14:14 +0800
xtu4 <xiaobing.tu@intel.com> wrote:
> @@ -209,8 +209,17 @@ ssize_t seq_read(struct file *file, char __user
> *buf, size_t size, loff_t *ppos)
> if (m->count < m->size)
> goto Fill;
> m->op->stop(m, p);
> - kfree(m->buf);
> - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
> + if (m->size > 2 * PAGE_SIZE) {
> + vfree(m->buf);
> + } else
> + kfree(m->buf);
> + m->size <<= 1;
> + if (m->size > 2 * PAGE_SIZE) {
> + m->buf = vmalloc(m->size);
> + } else
> + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
> +
> +
> if (!m->buf)
> goto Enomem;
> m->count = 0;
> @@ -325,7 +334,10 @@ EXPORT_SYMBOL(seq_lseek);
The conventional way of doing this is to attempt the kmalloc with
__GFP_NOWARN and if that failed, fall back to vmalloc().
Using vmalloc is generally not a good thing, mainly because of
fragmentation issues, but for short-lived allocations like this, that
shouldn't be too bad.
But really, the binder code is being obnoxious here and it would be
best to fix it up. Please identify with some care which part of the
binder code is causing this problem. binder_stats_show(), from a
guess? It looks like that function's output size is proportional to
the number of processes on binder_procs? If so, there is no upper
bound, is there? Problem!
btw, binder_debug_no_lock should just go away. That list needs
locking.
next prev parent reply other threads:[~2013-01-30 0:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-29 6:14 xtu4
2013-01-29 21:49 ` David Rientjes
2013-01-31 6:19 ` Tu, Xiaobing
2013-01-30 0:24 ` Andrew Morton [this message]
2013-01-31 6:19 ` Tu, Xiaobing
2013-01-31 6:11 ` resend----[PATCH] " xtu4
2013-01-31 21:27 ` Andrew Morton
2013-02-01 3:30 ` xtu4
2013-02-01 3:31 ` xtu4
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=20130129162431.58754538.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=arve@android.com \
--cc=guifang.tang@intel.com \
--cc=linX.z.chen@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=xiaobing.tu@intel.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
Powered by JetHome