LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-16-2015, 03:48 AM   #1
knobby67
Member
 
Registered: Mar 2006
Posts: 627

Rep: Reputation: 43
Is there a way to move a process from RAM to swap space in C code


Hi All,
hope someone can advise on this, I need to run 4 processes though only two are in use at any instance, but I need to swap between which are. Right now I pause a process then unpause the one I wish to use next. However I can have memory issues, that is I run out of RAM. So rather than reload each process from disk, which is slow, I thought I'd try to save load time by loading the process into RAM, then moving to swap space when not running. When I need it load from swap space to RAM again. Firstly is this possible? Secondly will it save time. Thanks in advance.
 
Old 02-16-2015, 04:05 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,802

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
If I understand it well it is made automatically by the OS (if required).
 
Old 02-16-2015, 04:23 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Yes, and the kernel is smarter. For example, you have one program that uses some code segments and some data segments. Writing the code segment to swap is pointless as the code already is on disk. So the kernel will simply drop the code segment when more RAM is needed, and load it back later later. Moving the code to swap makes no sense.
 
Old 02-16-2015, 06:28 AM   #4
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
Quote:
Originally Posted by knobby67 View Post
Hi All,
hope someone can advise on this, I need to run 4 processes though only two are in use at any instance, but I need to swap between which are. Right now I pause a process then unpause the one I wish to use next. However I can have memory issues, that is I run out of RAM. So rather than reload each process from disk, which is slow, I thought I'd try to save load time by loading the process into RAM, then moving to swap space when not running. When I need it load from swap space to RAM again. Firstly is this possible? Secondly will it save time. Thanks in advance.
So rather than reload each process from disk, which is slow, you want to put it on disk but it feels better when the region where you put it is called swap?
make it simple ,
dump the data of unused processes to disk and put the process to sleep, if you have luck they are in the disk cache and fast swapping between the processes is not an issue, or it is in /tmp which is mounted to tempfs anyway :-), however, if is on disk it depends if reading form file is not very noticeable faster or slower than from swap.
 
  


Reply



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
is swap space needed when RAM is greater than hard drive space ? ron7000 Linux - General 9 11-13-2014 08:56 PM
Swap Space required for 96GB RAM ravindert Linux - Newbie 12 07-15-2012 05:01 PM
Why size of swap space is 2x of RAM??? Why not 1.5x of RAM or 2.5x of RAM??? Saurav Ghosh Linux - Newbie 7 11-01-2011 03:49 AM
Move Main System from RAM to swap timothyb89 Linux - General 10 08-26-2006 03:49 PM
SWAP space=2*RAM p_test Linux - Enterprise 3 04-27-2006 02:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:49 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
Open Source Consulting | Domain Registration