LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 11-16-2012, 02:33 AM   #1
pstein
LQ Newbie
 
Registered: Jan 2009
Posts: 11

Rep: Reputation: 0
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
 
Old 11-16-2012, 03:55 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,487

Rep: Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077
Yes - read this.
 
Old 11-16-2012, 10:24 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,607

Rep: Reputation: 673Reputation: 673Reputation: 673Reputation: 673Reputation: 673Reputation: 673
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.
 
1 members found this post helpful.
Old 11-16-2012, 05:17 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,487

Rep: Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077Reputation: 1077
Indeed - I was remiss in not comprehending the question clearly.
 
Old 11-17-2012, 12:01 AM   #5
pstein
LQ Newbie
 
Registered: Jan 2009
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rknichols View Post
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?
 
Old 11-17-2012, 09:00 AM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,607

Rep: Reputation: 673Reputation: 673Reputation: 673Reputation: 673Reputation: 673Reputation: 673
Quote:
Originally Posted by pstein View Post
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 .
 
Old 11-17-2012, 10:21 AM   #7
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,139

Rep: Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127
Quote:
Originally Posted by pstein View Post
So maxmimum tmpfs size is NOT limited to the physical memory size?
Correct.

Quote:
Originally Posted by rknichols View Post
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 View Post
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.

Last edited by johnsfine; 11-17-2012 at 10:28 AM.
 
Old 11-18-2012, 02:17 AM   #8
pstein
LQ Newbie
 
Registered: Jan 2009
Posts: 11

Original Poster
Rep: Reputation: 0
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
 
Old 11-18-2012, 07:51 AM   #9
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,139

Rep: Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127Reputation: 1127
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).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why swap space did not function when physical memory ( RAM ) is full ? subankar Linux - Server 7 10-11-2012 01:02 PM
how to call socket prog code written in user space from kernel space???HELP kurt2 Programming 2 07-15-2009 10:56 PM
Swap space did not function when physical memory ( RAM ) is full rabbit00 Linux - Newbie 19 07-06-2009 10:18 PM
how much swap space is needed; how to increase swap space? johnpaulodonnell Linux - Newbie 5 03-23-2007 04:20 AM


All times are GMT -5. The time now is 03:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration