Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I don't have the space to try this out at the mo, but I'm just idly wondering.. what would happen if I made a 100Gb swap partition, and opened, say, 100Gb of bitmaps or text files? Could Linux handle it? Would it run slow?
The amount of swap memory has nothing to do with the performance of your computer.
What does affect the speed is the speed at which you allocate memory (i.e. read data into virtual memory), and the number of cache misses per second.
When you read data in to your program (or just try to allocate space for it), and there isn't enough free space in RAM, the kernel will write a segment of RAM to swap space, to free up the RAM your process needs. While that's happening, the process requesting the RAM will pause, which may make it appear to be slow.
However, the kernel has a couple of tricks up it's sleeve. Firstly, all processes pause some of the time anyway, since each CPU switches rapidly between different processes; provided you only need a small amount of data to be loaded at a time, this pause can be done while another process is running (you need to have DMA enabled for this to work; that's why DMA seems to make such a big speed difference). Secondly, provided you have a swappiness value of greater than zero, the kernel will also spend some idle time (if it has any) copying data out to swap space before your process requests it, meaning that you are unlikely to get into the situation of having to pause the process unless you are doing nothing but reading in a large amount of data.
When you request a piece of information, you will either have a cache hit (the data is in RAM) or a cache miss (it's only in swap). The kernel will use DMA to transfer memory between cache and RAM, allowing other processes to run while the data is copying, so provided you have something like 99.95% of memory transfers result in cache hits, you should not see any slowdown at all as the CPU would be scheduling other processes to run anyway. This, of course, means that you have to read your data slowly over time, and have DMA enabled.
i.e. this type of thing should work fine: load a high resolution image, process it with some cpu-intensive operation, keeping it in memory/swap for later retrieval, and repeat a few thousand times. Whereas if you loaded all the images up-front and then processed each one back to back, it would be noticeably slower, since each one would have to be read from cache every time anyway.
But, as has been mentioned, RAM is a much more reliable way of improving your memory size without affecting program speed. (By the way, if you have a 32-bit system with less than 4Gb of RAM, there is a campile-time flag you can set in the kernel to use 32-bit addresses instead of 64-bit addresses for physical RAM; if you use this then you may see a slight speed-up. But you have to turn this off to access more than 4Gb of RAM; this is the only case where adding RAM to a Linux system will slow it down.)
Thanks rjlee! That's satisfied an itch. Maybe I'll try it some time, just for the hell of it. You don't think X would complain if I had, say, 10,000 windows open? Maybe I could work with small text files and get it up to 10 billion windows
You don't think X would complain if I had, say, 10,000 windows open?
Well, that's another question. It probably depends on your window manager and how many times it iterates over all open windows. Personally, I would guess that you would probably have slowdowns long before you start using swap space.
But still, feel free to experiment, and find out for certain!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.