LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What if tmpfs space is full? Written to swap space? (http://www.linuxquestions.org/questions/linux-newbie-8/what-if-tmpfs-space-is-full-written-to-swap-space-4175437392/)

pstein 11-16-2012 01:33 AM

What if tmpfs space is full? Written to swap space?
 
Assume I defined a tmpfs filesystem and mounted on /tmp.

What happens if this tmpfs space is "full" written by files?

Are the additional files (or the oldest ones) automatically written to swap file on hard disc?

Peter

syg00 11-16-2012 02:55 AM

Yes - read this.

rknichols 11-16-2012 09:24 AM

Sorry , but the answer is, "No," at least not automatically. A tmpfs has a specified maximum size, which defaults to half of physical memory. When a tmpfs is full, it is full, just like any other file system. Other demands on physical memory may cause part of a tmpfs to be paged out to swap space, but the tmpfs can never grow beyond its specified maximum size. To make it larger, you would have to explicitly set a new maximum size.

syg00 11-16-2012 04:17 PM

Indeed - I was remiss in not comprehending the question clearly.

pstein 11-16-2012 11:01 PM

Quote:

Originally Posted by rknichols (Post 4830812)
Sorry , but the answer is, "No," at least not automatically. A tmpfs has a specified maximum size, which defaults to half of physical memory. When a tmpfs is full, it is full, just like any other file system. Other demands on physical memory may cause part of a tmpfs to be paged out to swap space, but the tmpfs can never grow beyond its specified maximum size. To make it larger, you would have to explicitly set a new maximum size.

ok, thank you.

But that means if e.g. my memory is 4 GB I can specify tmpfs maximum size of 200 GB anyway?
So maxmimum tmpfs size is NOT limited to the physical memory size?
According to the tmpfs doc link in the post of syg00 tmpfs will swap out tmpfs file stuff if necessary.

Correct?

rknichols 11-17-2012 08:00 AM

Quote:

Originally Posted by pstein (Post 4831159)
But that means if e.g. my memory is 4 GB I can specify tmpfs maximum size of 200 GB anyway?
So maxmimum tmpfs size is NOT limited to the physical memory size?
According to the tmpfs doc link in the post of syg00 tmpfs will swap out tmpfs file stuff if necessary.
Correct?

Indeed, you can set the size of a tmpfs as large as you want, even larger than the size of physical memory plus swap. You can also set the size to zero, which is interpreted as "unlimited". As for the result of actually trying to use that much space -- well, you are hereby invited to try that on your own system. I don't care to do it on mine.

Yes, memory pages used by a tmpfs can be pushed out to swap just like other non-kernel pages. All the details are in that tmpfs doc link, and that text might be available on your own system in /usr/share/doc/kernel-doc-*/Documentation/filesystems/tmpfs.txt .

johnsfine 11-17-2012 09:21 AM

Quote:

Originally Posted by pstein (Post 4831159)
So maxmimum tmpfs size is NOT limited to the physical memory size?

Correct.

Quote:

Originally Posted by rknichols (Post 4831336)
Indeed, you can set the size of a tmpfs as large as you want, even larger than the size of physical memory plus swap.

It can make a lot of sense in plausible situations to make the tmpfs far larger than physical ram. But it is hard to come up with a situation in which it makes sense for the tmpfs to be larger than ram plus swap. (I know you were just saying it is possible, not that it makes sense. I just wanted to distinguish larger than ram from larger than ram+swap).

In many work flows (including some of mine; I don't know about the OP) a very large number of files are created, written once, read once, and then deleted. Even if there are so many such files that they don't all fit in ram, that sequence remains more efficient on a tmpfs than in a regular disk file system, subject to the extra rule that tends to apply in such work flows, that if the system crashes in the middle, you start the whole work over from creating the files, you don't try to continue with files from before the crash. Without that rule, a tmpfs is not a good choice.

Linux system crashes are rare. A big cost of redoing work in the unlikely event of a crash is usually cheaper than the tiny cost of doing the same work a little slower every time the system doesn't crash.

For files deleted "soon" after they are created, a tmfs has performance advantages over a regular file system, even if the tmpfs is forced to use some swap space vs. caching letting the regular file system use some ram, such that the ratio of ram use to disk use is the same for the two alternatives. What "soon" needs to mean to make this true depends on so many aspects of your situation, you'll need to evaluate or test that for yourself. There is no simple rule.

Quote:

Originally Posted by pstein (Post 4831159)
if e.g. my memory is 4 GB I can specify tmpfs maximum size of 200 GB anyway?

When planning such a configuration, you don't first decide on the amount of swap space and then decide on the tmpfs size taking into account the practical limits of ram+swap. Instead you first decide on the size of tmpfs you will want and take that (and other swap requirements) into account when deciding on the amount of swap space you need.

pstein 11-18-2012 01:17 AM

Thank you for answers.

One last question about the space allocation:

Lets say I define a tmpfs space with maximum size=50 GB
Then I (re)boot to become tmpfs effective.

Is then tmpfs initially allocated with 20GB or does tmpfs initially has a space of 0 Bytes?
In latter case new space is allocated step-by-step on demand (e.g. when I new file is copied to tmpfs).

So when is tmpfs space allocated?

Peter

johnsfine 11-18-2012 06:51 AM

You don't need to reboot to change the size of a tmpfs or to create a new one.

I'm not sure what control overhead memory is allocated based on the specified max size, probably very little.

The actual file space in a tmpfs is only allocated while used (on demand as files are stored in the tmpfs).


All times are GMT -5. The time now is 02:05 AM.