Re: [PATCH 3/3] seq_file: convert seq buffer to vmalloc

From: NamJae Jeon
Date: Thu Sep 22 2011 - 19:26:36 EST


2011/9/23 Colin Cross <ccross@xxxxxxxxxxx>:
> On Thu, Sep 22, 2011 at 2:07 PM, Joe Perches <joe@xxxxxxxxxxx> wrote:
>> On Thu, 2011-09-22 at 13:57 -0700, Colin Cross wrote:
>>> seq_files are often used for debugging. ÂWhen things are going wrong
>>> due to failed physically contiguous allocations, the exponentially
>>> growing physically contiguous allocations in seq_read can make things
>>> worse. ÂThere is no need for physically contiguous memory, so switch
>>> to virtually contiguous memory instead.
>>
>> vmalloc's are relatively expensive.
>> Perhaps use kmalloc when appropriate instead?
> Talking about allocation efficiency in the context of seq_files is
> silly - for a KMALLOC_MAX_SIZE buffer (8MB), you are already going to
> allocate 11 times, with increasingly large buffers, and are likely to
> fail long before you ever get to KMALLOC_MAX_SIZE.
>
>> []
>>> - Â Â /* don't ask for more than the kmalloc() max size */
>>> - Â Â if (size > KMALLOC_MAX_SIZE)
>>> - Â Â Â Â Â Â size = KMALLOC_MAX_SIZE;
>>> -
>>> - Â Â buf = kmalloc(size, GFP_KERNEL);
>>> + Â Â buf = vmalloc(size);
>>> Â Â Â if (!buf)
>>> Â Â Â Â Â Â Â return -ENOMEM;
>>
>> Â Â Â Âif (size > KMALLOC_MAX_SIZE)
>> Â Â Â Â Â Â Â Âbuf = vmalloc(size, GFP_KERNEL)
>> Â Â Â Âelse
>> Â Â Â Â Â Â Â Âbuf = kmalloc(size, GFP_KERNEL);
> KMALLOC_MAX_SIZE is far too big for this. ÂKMALLOC_MAX_SIZE is the
> maximum allocation that is theoretically possible, but will fail if
> you don't have any completely empty pageblocks. ÂIf I were to put a
> size here, it would probably be order 3, but even that can easily fail
> on a system that has under memory pressure.
-> I agree. I think that vmalloc is better than kmalloc. because you
can face page allocation fail by high order page.
>
>>> + Â Â vfree(m->buf);
>>
>> Â Â Â Âif (m->size > KMALLOC_MAX_SIZE)
>> Â Â Â Â Â Â Â Âvfree(m->buf);
>> Â Â Â Âelse
>> Â Â Â Â Â Â Â Âkfree(m->buf);
>>
>>> Â Â Â m->buf = buf;
>>> Â Â Â m->size = size;
>>>
>>> @@ -106,7 +103,7 @@ static int traverse(struct seq_file *m, loff_t offset)
>>> Â Â Â Â Â Â Â return 0;
>>> Â Â Â }
>>> Â Â Â if (!m->buf) {
>>> - Â Â Â Â Â Â m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
>>> + Â Â Â Â Â Â m->buf = vmalloc(m->size = PAGE_SIZE);
>>
>> embedding the set of m->size like this is ugly.
> I agree, but it was there in the original file. ÂI could clean it up,
> but that should be in a separate patch.
>
>> [do the same as above kmalloc/vmalloc based on size]
>>
>> etc.
>>
>>
> --
> 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/
>
--
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/