2

Admittedly, this is a bit of a weird question....

TL;DR: I'm trying to work on a program, but whenever I link it, it uses ridiculous amounts of RAM. As a result, pretty much everything but the linker gets shoved to the swap space, which makes my system 99% unresponsive for the next 10 minutes. (Though, once I start to use the different applications again, performance starts to return to normal.)

The thing is, I really don't care how long the linking takes as long as the rest of the computer doesn't lock up. This brings me to my question: is there a way to, when the linker starts up, tell the kernel to prefer swapping of it to anything else? e.g. that, if I run low on RAM, the linker will be swapped before anything else.

I'm aware that this would cause some major slowdown, but I also don't want to have to restart my computer every time I link it because it becomes a giant ice box. :O

1

1 Answer 1

2
+50

If I'm understanding your question properly, you wish to reduce the priority of your linker (ld based on the tags you used) in order that your system remains responsive while the linker is running. For all intents and purposes, this question is a duplicate of Change niceness (priority) of a running process but it can't be closed as a duplicate with an open bounty on it.

You can start a process with a very low priority by prepending nice -n 19 to your command or change it while it's in process with renice

This approach will instruct the system to be more willing to release system resources for other tasks and improve the responsiveness of your system the default niceness value is 10. You can experiment with different values from 11 to 19 which will incrementally improve responsiveness of your system, with 19 resulting in the most improvement (and the longest linking time)

Excerpt from the nice man page:

NOTES

       SUSv2 and POSIX.1 specify that nice() should return the new nice value.
       However, the Linux system call and the nice() library function provided
       in older versions of (g)libc (earlier than glibc  2.2.4)  return  0  on
       success.  The new nice value can be found using getpriority(2).

       Since  glibc  2.2.4,  nice()  is implemented as a library function that
       calls getpriority(2) to obtain the new nice value to be returned to the
       caller.   With  this implementation, a successful call can legitimately
       return -1.  To reliably detect an error, set  errno  to  0  before  the
       call, and check its value when nice() returns -1.

Sources:

Change niceness (priority) of a running process

http://manpages.ubuntu.com/manpages/xenial/man2/nice.2.html

You may also find this information interesting.

2
  • Thanks! It works perfectly! (I'll give you the bounty in 22 hours...) May 10, 2017 at 21:42
  • I'm glad we got it sorted! I'm always eager to help!
    – Elder Geek
    May 10, 2017 at 21:45

You must log in to answer this question.

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