if (!m->buf) {
m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
if (!m->buf)
goto Enomem;
}
But I malloc'ked m->buf before when the seq_file m is first opened in zoneinfo_open()
Also, I noticed a very strange behavior with setting the PAGE_SIZE for seq_file. Unless, I read any data into the seq_file the seq_file size always remains PAGE_SIZE, but as soon as I read a big amount of data the seq_file size actually goes upto 16*PAGE_SIZE. I don't know where that came from. I only set it to 2*PAGE_SIZE.
However, it served my purpose (or least it appears to have) because I am basically trying to read a huge portion of the lru active list (for all ZONES) into the seq_file
Is there a better way of doing this?
Thanks
Bithika
On 11/17/06, black hole <neyrith@xxxxxxxxx> wrote:
Hello,On 11/17/06, Bithika Khargharia < bithika@xxxxxxxxx> wrote:Hi,
I am trying to increase the size of the seqfile buffer from PAGE_SIZE to 2*PAGE_SIZE to read the file zoneinfo in /proc. I created the seq_file structure in zoneinfo_open (code snippet attached) and kmalloc'ked the buffer as
activePages->buf = kmalloc(activePages->size = 2*PAGE_SIZE, GFP_KERNEL);
Then file->private_data field points to the created seq_file. Finally seq_open is called with the file.
However, when I print out the size of the seq_file "zoneinfo" it always return 4096 Bytes which is the PAGE_SIZE in my system. It is not set to 2*PAGE_SIZE as desired.
What am I doing wrong?Let's look at the seq_open() implementation at
http://lxr.linux.no/source/fs/seq_file.c#L29
Notice the memset(p, 0, (*p)) at line 39.
This has two consequences. The first one is memory leak.
Your previously allocated buf of 2*PAGE_SIZE size is lost.
The second one is that the buf gets set to PAGE_SIZE size
in the the seq_read() ( http://lxr.linux.no/source/fs/seq_file.c#L65).
The line 89 is executed because the buf member
of the struct seq_file is zero.
My conclusion therefore is that the size of the buf in the seq_file
API implementation is always PAGE_SIZE.
What exacly are you trying to accomplish?
Maybe there's another way.
BlackHole
--
O for a Life of Sensations rather than of Thoughts!-- Keats