2

I have to compile a computer generated source with my sources which is too huge and I've no control over it. Since my memory is not much, I've to force make use less memory. Otherwise, it gets killed by OS (precise). What can I do?

2 Answers 2

5

How about adding more swap to your machine as a solution? This will add more virtual memory and may allow you to build your code without the OOM killer killing the compiler. If you don't want to fiddle around with making your swap partition larger your could add a temporary swap file. For example, adding a file based 4GB swap:

dd if=/dev/zero of=swap.img bs=1M count=4096
mkswap swap.img
chmod 0600 swap.img 
sudo chown root:root swap.img
swapon swap.img
6
  • good idea, thx. i didn't think about using a swap space/file. i also didn't know about swap files which may be used this way instead of swap spaces. this should solve the problem if gcc use swap and doesn't need the whole compiling be done in the physical memory. i'm going to test it. i'll inform.
    – hamidi
    Jun 12, 2016 at 5:39
  • which one is faster? swap file or swap space? or maybe there's no preference?
    – hamidi
    Jun 12, 2016 at 5:52
  • yeah, that worked :) now let me know, please, whether the swap file is permanent and if not how can i make a swap file permanent? thx
    – hamidi
    Jun 12, 2016 at 5:56
  • So create your swap file somewhere, e.g. /var/swap.img and add an entry in /etc/fstab to mount it at boot time: e.g. /var/swap.img none swap sw Jun 12, 2016 at 11:17
  • There is no difference in speed , its just disk access , it doesn't go via the filesystem
    – Amias
    Jun 12, 2016 at 13:38
-2

Have you tried using nice? It allows to set a custom priority for your processes. nice ranges from -20 to 19, being 19 the lowest priority and -20 the highest. You could try something like this:

nice -n 19 command_you_want_to_execute

Example:

nice -n 19 firefox

Edit: ellaborating a bit on my response, if your OS kills your process it's because is using resources that are needed for the correct functioning of your system. If you give your process a lower priority, those resources will automatically be allocated to more important system tasks.

3
  • i'll test it and inform, thx. but at the moment this doesn't seem to me to solve the problem... as practically it didn't. the process is executed in another priority class by this way causing the cpu be available less to it and more to other processes. it doesn't affect of memory usage.
    – hamidi
    Jun 12, 2016 at 5:42
  • 1
    Nice is about CPU usage , oom killer is about memory usage, nice will not help here, it will just make it slower.
    – Amias
    Jun 12, 2016 at 13:39
  • 2
    -1 The “niceness” doesn't affect memory consumption, only the allocation of CPU time by the scheduler. Jun 13, 2016 at 15:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .