Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've downloaded a lot of torrent files and while I'm seeding them, I've noticed that very often when I start the browser it's slow and the hard disk activity indicator is on. Usually when I start a program it gets cached in RAM and starting it again is very quick, and I have 3 GB of RAM so usually it stays cached nearly forever. But when my torrent client is seeding it seems that after an hour programs that I ran are no longer cached in RAM.

I was thinking maybe it's because of the disk reads which the torrent client performs are cached and fill up RAM eventually. But I don't think they need to be, as they are read only once and are unlikely to be read again soon.

So my questions are - is this the way I think, and if so is it possible in principle to prevent the disk reads from being cached? I can try to edit the source code of the program.

share|improve this question
    
How much swap use do you see? –  arrange Nov 22 '11 at 9:37

2 Answers 2

up vote 3 down vote accepted

It will depend exactly which torrent program you're using. Some of them might behave in different ways.

But yes, it is possible to bypass system cache since this is a common problem.

If you're comfortable editing source (perhaps this should be on another StackExchange..) find where the torrent program opens the file from disk. Most likely an open() call. If it is fdopen() then it's using stdlib and I'm not sure stdlib supports direct i/o.

This system call takes up to three arguments, the first one is the filename, the second are flags, the third is an optional file create mask. The flags will probably be something like O_RDWR at the moment. The flag for "don't use system cache" is O_DIRECT, and you combine flags by separating them with |.

So the result of the flags argument in this case would be O_RDWR | O_DIRECT. Just add the new flag on.

For more information, see

man 2 open
share|improve this answer
    
Great, thanks for the info. I'm using deluge because it is closest to uTorrent. It's written in python but it uses libtorrent (rasterbar) I think, which is in C++. –  sashoalm Nov 22 '11 at 14:01
    
Ok, the specifics may vary if it's C++ (may be using boost or something for example), but the general idea will be the same, you're looking for direct i/o flags to set. –  Caesium Nov 22 '11 at 14:06
    
I managed to add O_DIRECT and rebuild and install libtorrent-rasterbar eventually, but torrents started having errors "Invalid Status", because ::open() would return EINVAL, so I abandoned the idea. –  sashoalm Nov 27 '11 at 11:24
    
Ah, no filesystem support: from man open : Some file systems may notimplement the flag and open() will fail with EINVAL if it is used. –  Caesium Nov 27 '11 at 12:36
    
My home partition is ext4. I think that the error happens only on some files, most were fine, so maybe it was because of a combination of flags that don't go well with each other. –  sashoalm Nov 27 '11 at 19:22

Don't close the browser :)

The I/O cache (used just for reading, not writing to a file), however excessive, will not cause the pages that the program is using to be swapped out.

share|improve this answer
    
Yes, but my problem is that the files on disk of various programs need to be re-read when I start them instead of being already cached in RAM. Without the torrent client, after a while my laptop would become as fast as if it had SSD because every program I start is already cached in RAM. –  sashoalm Nov 27 '11 at 11:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.