6

I have just set Ubuntu 12.04 64bit with Cinnamon desktop and 3.5.0-030500 kernel on my new laptop with IvyBridge i7.

I decided to test its performance by running a single threaded CPU-hungry program that I often use for camera calibration. Unfortunately, it ended up running much slower than I have ever expected. After some investigation it turned out that the program priority is automatically changed from normal to low which makes the program even slower.

I have also noticed that all user programs such as Skype and Firefox are set to low priority. I tried manually resetting the priority to normal or even very high using the renice command, which works temporary until the kernel scheduler (I guess) resets the priority to low.

Is this a normal behaviour and how can I overcome the slow execution problem?

P.S. I also tried with the 3.2 kernel, but the problem is still present.

2
  • What is the priority value of your process?Type ps -le OR ps -l PID and check under NI column.
    – ignite
    Sep 13, 2012 at 2:27
  • Well, the process starts with Nice value of 0, but then it is changed to 4. I tried setting the nice value manually to -11 or even -20, but after 20-30 seconds it gets changed to 4 again. I know that the kernel scheduler can change the priority of the process, but only with 5 levels; not from -20 to 4.
    – Svepe
    Sep 13, 2012 at 9:42

2 Answers 2

0

You can set the default nice value of a particular user or group in the /etc/security/limits.conf file.

/etc/security/limits.conf

It uses this syntax: [username] [hard|soft] priority [nice value]

For you try to put your user in this file and set to the priority you wish.

1
  • 2
    I added this to the limits.conf file: svepe - priority 0 , but the process priority that I start still gets changed to 4 after it runs for a minute.
    – Svepe
    Oct 8, 2012 at 20:15
0

Here is a way to increase priority permanently for the Firefox in the Ubuntu. You can use it for the Skype or other processes as well.

Step 1: Use the following C code ( source: http://and.sourceforge.net/highpriostart.c)

If you name the file increase_ff_priority.c then

compile and install as follows:

# gcc increase_ff_priority.c -o increase_ff_priority
# sudo cp increase_ff_priority /usr/local/bin
# sudo chmod +s /usr/local/bin/increase_ff_priority

#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>


/*********************************************************************

   High priority task starter.

   USE AT OWN RISK! THIS PROGRAM COMES WITHOUT *ANY*
   WARRANTY WHATSOEVER!

   This program executes a program (as defined in PROGRAM)
   at a given (usually higher than normal) priority (as
   defined in PRIORITY). Edit PROGRAM and PRIORITY to meet
   your needs. Sensible programs may be: cdrecord, MP3 or
   DVD players, etc. Sensible priorities range from -1 to -5.

   The program itself is *not* started SUID root but as the
   user invoking the task starter. Root privilegues are used
   *only* to set the desired priority (aka. nice level).

    Compile and install as follows:
   # gcc increase_ff_priority.c -o increase_ff_priority
   # sudo cp increase_ff_priority /usr/local/bin
   # sudo chmod +s /usr/local/bin/increase_ff_priority

   2002, Patrick Schemitz <[email protected]>
   This program is released under the GNU Public License (GPL).

*********************************************************************/


/* The program to start with higher priority, with full path. */
#define PROGRAM "/usr/bin/firefox"


/* The desired priority, ranging from 19 (very low) to -20 (too
   high). Sensible values from 0 (normal) to maybe -5 (pretty
   high).

   WARNING:

   DO NOT SET THIS TO -20, OR YOU WILL SEVERELY AND PERMANENTLY
   DAMAGE YOUR SYSTEM! Setting the priority too high causes your
   program to interfere with very important system tasks (like
   the swapper or the RAID daemons). Messing with the RAID
   daemons is a *VERY* bad idea!
*/
#define PRIORITY -20


/* You can increase this if your program can sensibly handle a
   very large number of parameters (like tar, ls, etc); normally
   the default (1024) should be plenty.
*/
#define MAX_ARGS 1024


int main (int argc, char **argv)
{
    int i;
    pid_t pid;
    char* args [MAX_ARGS+1] = { PROGRAM, NULL };
    /* first thing to do: drop privilegues */
    seteuid(getuid());
    /* copy over arguments */
    for (i=1; i<argc && i<MAX_ARGS; i++)
    args[i] = argv[i];
    args[i] = NULL;
    /* fork process for the program to be started */
    pid = fork();
    if (pid == 0) {
    /* new process starts actual program */
    execvp(PROGRAM,args);
    } else {
    /* original process regains privilegues */
    seteuid(0);
    /* set desired priority */
    setpriority(PRIO_PROCESS,pid,PRIORITY);
    }
    return 0;
}

Step 2: Create the following file named increase_ff_priority.desktop and copy to ~/.config/autostart (use sudo cp)

[Desktop Entry]
Type=Application
Exec="/usr/local/bin/increase_ff_priority"
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_IN]=increase_ff_priority
Name=increase_ff_priority
Comment[en_IN]=AnyComment
Comment=AnyComment

Step 3: Restart

Step 4: Use Top command or System Monitor to check the priorities.

You must log in to answer this question.

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