Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Linux Filecache (/proc/sys/vm/buffermem and bdflush)

60 views
Skip to first unread message

Florian Wolff

unread,
Dec 1, 1999, 3:00:00 AM12/1/99
to
Hej all,

I'm running a Linux 2.2.13 System on a P-II 400 with 512 MB Memory and
using glibc 2.1.6 (redhat 6.0).

Linux uses a dynamic file cache. This is generally a good thing,
speeding up access to recent loaded files. But consider the following
code:

#include <stdio.h>
#define BSIZE 256

int main()
{
FILE * fs;
unsigned char buf[BSIZE];

fs = fopen("testfile","w");

while(1)
{
fwrite(buf,BSIZE,1,fs);
// fflush(fs);
}
}

When this program is run, it writes data from a buffer to harddisk. The
problem is, that while running, the Linux buffer memory (BUFF gauge in
xosview) grows more and more - consuming nearly the whole physical
memory. Using fflush(fs) to flush the file does not help, neither
switching to write() instead of fwrite(). The buffer keeps growing.
Unfortunately this could leed into a nasty situation, where a device
driver (an ATM NIC) could not allocate sufficient memory in an interupt
handling routine (using GPF_ATOMIC which is IMHO not able to free
buffer-mem) and then fails.

As far as I understand, the file buffer could be controlled via the
/proc/sys/vm Interface. With decreasing nfract, nref_dirt and age_buffer
in bdflush, the kernel should write out data more often. Setting a
smaller max_percent in buffermem should also reduce the file buffer. But
this is not working. The buffer still grows up to the phy. mem. limit.
Even with calling sync the buffer is not flushed. I have to call a small
utility which allocates as much memory as possible in user space and
then free it to obtain really free memory.

Is the file buffer management broken in recent kernels? Or is there some
other point to tweak?

(please post and reply a followup)
Florian.


Florian Wolff

unread,
Dec 1, 1999, 3:00:00 AM12/1/99
to

Florian Wolff wrote:

> Is the file buffer management broken in recent kernels? Or is there some
> other point to tweak?

I found the answer in the Linux Kernel Mailing list: The Linux File Cache
System is not designed to handle such streaming applications as in my demo
code. If you want to know more, follow the thread on
http://uwsg.ucs.indiana.edu/hypermail/linux/kernel/9908.2/1347.html
for more details.

Florian.


Peter Pointner

unread,
Dec 1, 1999, 3:00:00 AM12/1/99
to
Florian Wolff <floria...@bbcom-hh.de> wrote:
> Hej all,

[snip]

> As far as I understand, the file buffer could be controlled via the
> /proc/sys/vm Interface. With decreasing nfract, nref_dirt and age_buffer
> in bdflush, the kernel should write out data more often. Setting a
> smaller max_percent in buffermem should also reduce the file buffer. But
> this is not working. The buffer still grows up to the phy. mem. limit.
> Even with calling sync the buffer is not flushed. I have to call a small
> utility which allocates as much memory as possible in user space and
> then free it to obtain really free memory.

> Is the file buffer management broken in recent kernels? Or is there some
> other point to tweak?

> (please post and reply a followup)
> Florian.

If I understand your problem correctly you should be able to solve your
problem by increasing the values in /proc/sys/vm/freepages. Read the
docs in /usr/src/linux/Documentation/proc.txt.

Peter

Florian Wolff

unread,
Dec 2, 1999, 3:00:00 AM12/2/99
to Peter Pointner
Peter Pointner wrote:

> If I understand your problem correctly you should be able to solve your
> problem by increasing the values in /proc/sys/vm/freepages.

Thank you for your answer, this is what I'm doing right now.
But as a matter of fact, the current Linux System is not suited for streaming
file applications.

Florian.


0 new messages