Re: [PATCH 2/2] fs: proc/stat: use usual seq_file ops rather than single_open

From: David Rientjes
Date: Thu Jun 12 2014 - 02:52:39 EST


On Thu, 12 Jun 2014, Ian Kent wrote:

> > > diff --git a/fs/seq_file.c b/fs/seq_file.c
> > > index 1d641bb108d2..fca78a04c0d1 100644
> > > --- a/fs/seq_file.c
> > > +++ b/fs/seq_file.c
> > > @@ -8,8 +8,10 @@
> > > #include <linux/fs.h>
> > > #include <linux/export.h>
> > > #include <linux/seq_file.h>
> > > +#include <linux/vmalloc.h>
> > > #include <linux/slab.h>
> > > #include <linux/cred.h>
> > > +#include <linux/mm.h>
> > >
> > > #include <asm/uaccess.h>
> > > #include <asm/page.h>
> > > @@ -82,6 +84,31 @@ int seq_open(struct file *file, const struct seq_operations *op)
> > > }
> > > EXPORT_SYMBOL(seq_open);
> > >
> > > +static void seq_alloc(struct seq_file *m)
> > > +{
> > > + m->size = PAGE_SIZE;
> > > + m->buf = kmalloc(m->size, GFP_KERNEL | __GFP_NOWARN);
> > > + if (!m->buf)
> > > + m->buf = vmalloc(m->size);
> > > +}
> > > +
> >
> > If m->size is unconditionally PAGE_SIZE, then how is vmalloc() going to
> > allocate this if kmalloc() fails?
>
> This is just the initial allocation.
> If it runs out of room the allocation size doubles.
>
> I think 2*PAGE_SIZE is probably better here since that's closer to what
> the original heuristic allocation requested and is likely to avoid
> reallocations in most cases.
>
> The issue of kmalloc() failing for larger allocations on low speced
> hardware with fragmented memory might succeed when vmalloc() is used
> since it doesn't require contiguous memory chunks. But I guess the added
> pressure on the page table might still be a problem, nevertheless it's
> probably worth trying before bailing out.
>

I'm not quarreling about using vmalloc() for allocations that are
high-order, I'm referring to the rather obvious fact that m->size is set
to PAGE_SIZE unconditionally above and thus vmalloc() isn't going to help
in the slightest.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/