seq_file: Allocate memory using vmalloc when kmalloc failed
When dumpstate access /proc/xxx/binder, this binder include lots of info, it will use seq_read in kernel, in this function, it will trigger high order memory alloc, when read binder info or other large file, this will cause memory presure when system don't have contious high order memory, it will lead to high kswap workload to reclaim the page. so change kmalloc to vmalloc, it can avoid contiously high order memory allocating. CRs-fixed: 514982 Change-Id: I463d5f72c24b7bb298e14b0da49c5fc96091ecc1 Patch-mainline: linux-arm-kernel(lkml) @ Thu, 31 Jan 2013 14:11:32 +0800 Link : https://lkml.org/lkml/2013/1/31/20 Signed-off-by: Srinivasarao P <spathi@codeaurora.org>
This commit is contained in:
parent
93b28e41a0
commit
13bad1e17a
|
@ -7,8 +7,10 @@
|
|||
|
||||
#include <linux/fs.h>
|
||||
#include <linux/export.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/seq_file.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/vmalloc.h>
|
||||
|
||||
#include <asm/uaccess.h>
|
||||
#include <asm/page.h>
|
||||
|
@ -131,8 +133,10 @@ static int traverse(struct seq_file *m, loff_t offset)
|
|||
|
||||
Eoverflow:
|
||||
m->op->stop(m, p);
|
||||
kfree(m->buf);
|
||||
m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
|
||||
is_vmalloc_addr(m->buf) ? vfree(m->buf) : kfree(m->buf);
|
||||
m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | __GFP_NOWARN);
|
||||
if (!m->buf)
|
||||
m->buf = vmalloc(m->size);
|
||||
return !m->buf ? -ENOMEM : -EAGAIN;
|
||||
}
|
||||
|
||||
|
@ -227,8 +231,10 @@ 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);
|
||||
is_vmalloc_addr(m->buf) ? vfree(m->buf) : kfree(m->buf);
|
||||
m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | __GFP_NOWARN);
|
||||
if (!m->buf)
|
||||
m->buf = vmalloc(m->size);
|
||||
if (!m->buf)
|
||||
goto Enomem;
|
||||
m->count = 0;
|
||||
|
@ -343,7 +349,7 @@ EXPORT_SYMBOL(seq_lseek);
|
|||
int seq_release(struct inode *inode, struct file *file)
|
||||
{
|
||||
struct seq_file *m = file->private_data;
|
||||
kfree(m->buf);
|
||||
is_vmalloc_addr(m->buf) ? vfree(m->buf) : kfree(m->buf);
|
||||
kfree(m);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue