LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-06-2015, 04:39 AM   #1
Rafael25
Member
 
Registered: Jul 2012
Posts: 55

Rep: Reputation: Disabled
Cgroups not working


Hi,

I want to restrict cpu usage of my process so i have planned to use
Cgroups.

I have followed the following Set of commands:

Code:
sudo cgcreate -g cpu:/cpulimited 

sudo cgcreate -g cpu:/lesscpulimited

sudo cgset -r cpu.shares=512 cpulimited
This is the output of cgsnapshot -s command:
Code:
# Configuration file generated by cgsnapshot
mount {
        cpuset = /cgroup/cpuset;
        cpu = /cgroup/cpu;
        cpuacct = /cgroup/cpuacct;
        memory = /cgroup/memory;
        devices = /cgroup/devices;
        freezer = /cgroup/freezer;
        net_cls = /cgroup/net_cls;
        blkio = /cgroup/blkio;
}

group lesscpulimited {
        cpu {
                cpu.rt_period_us="1000000";
                cpu.rt_runtime_us="0";
                cpu.cfs_period_us="100000";
                cpu.cfs_quota_us="-1";
                cpu.shares="1024";
        }
}

group cpulimited {
        cpu {
                cpu.rt_period_us="1000000";
                cpu.rt_runtime_us="0";
                cpu.cfs_period_us="100000";
                cpu.cfs_quota_us="-1";
                cpu.shares="512";
        }
}
This command i am trying to execute:

Code:
sudo cgexec -g cpu:lesscpulimited dd if=/dev/zero of=/dev/null bs=1024k &

sudo cgexec -g cpu:cpulimited dd if=/dev/zero of=/dev/null bs=1024k &
But still i cant restrict the CPU usage:

Here is the output of mu top:
Code:

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 1727 root      20   0  9376 1660  524 R 100.0  0.1   8:47.74 dd
 1730 root      20   0  9376 1660  524 R 100.0  0.1   8:07.66 dd
    1 root      20   0 19232 1500 1220 S  0.0  0.1   0:00.63 init
I have restarted the service also.

What i am missing?

Last edited by Rafael25; 02-06-2015 at 04:59 AM.
 
Old 02-06-2015, 07:27 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
I don't think you are missing anything. If the CPU has idle time then the system will give it to whatever process can use it...

Cgroups only change the allocations when the system is saturated, AND you add some other work to it. The cgroups will then be used to balance which process gets the CPU based on the shares allocated.

If you have two CPUs, then both processes will get 100% of a processor. If you then add another such process, you should then see the shares start balancing the use of the CPU based on the shares.
 
Old 02-09-2015, 01:21 AM   #3
Rafael25
Member
 
Registered: Jul 2012
Posts: 55

Original Poster
Rep: Reputation: Disabled
Hi,

Thanks for the reply.
It works now.

I want to restrict System users resources.
How should i do that?
 
Old 02-09-2015, 04:30 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
You already are.
 
  


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
Cgroups, restricting memory e64462 Linux - Software 1 01-11-2013 02:20 AM
LXer: CGroups on CentOS 6 LXer Syndicated Linux News 0 03-03-2012 07:00 PM
Cgroups and Systemd omriar Linux - Server 0 10-06-2011 11:15 AM
cgroups - blkio sethusubbiah Linux - Software 0 07-23-2011 10:45 AM
cgroups spokz Linux - Virtualization and Cloud 3 06-08-2011 05:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:07 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