Systemd vs commandline: resources allocation difference

Hello Everyone,

I want to create a systemd service for which the resources allocated should be same as when the process is launched from command line.

Here is my systemd service file

[CODE][Unit]
Description=Image Server
After=Volumes-localStorage2.mount autofs.service

[Service]
Type=simple
ExecStartPre=/bin/sleep 60
ExecStart=/root/ccs/ias/jetty/startjetty.sh
ExecStop=/root/ccs/ias/jetty/endjetty.sh
Restart=always

[Install]
WantedBy=default.target[/CODE]

Below is the comparison between the cgroup and status file under /proc/{PROCESS_ID}/
I see the difference in FDSize and VM sizes.

[table=“width: 500, class: grid”]
[tr]
[td]File[/td]
[td]Process started with command line[/td]
[td]Process started using systemd service[/td]
[/tr]
[tr]
[td]cgroup[/td]
[td]11: perf_event:/
10:devices:/[COLOR="#A52A2A"]user.slice[/COLOR]
9:hugetlb:/
8:freezer:/
7:cpu,cpuacct:/
6:memory:/
5:blkio:/
4: pids:[COLOR="#A52A2A"]/user.slice/[/COLOR]user-0.slice/session-111.scope
3:cpuset:/
2:net_cls,net_prio:/
1:name=systemd:/[COLOR="#A52A2A"]user.slice[/COLOR]/user-0.slice/session-111.scope
[/td]
[td]11: perf_event:/
10:devices:/[COLOR="#A52A2A"]system.slice[/COLOR]/ccs-is.service
9:hugetlb:/
8:freezer:/
7:cpu,cpuacct:/
6:memory:/
5:blkio:/
4: pids:/[COLOR="#A52A2A"]system.slice[/COLOR]/ccs-is.service
3:cpuset:/
2:net_cls,net_prio:/
1:name=systemd:/[COLOR="#A52A2A"]system.slice[/COLOR]/ccs-is.service
[/td]
[/tr]
[tr]
[td]status[/td]
[td]Name: java
…
FDSize: [COLOR="#A52A2A"]2048[/COLOR]
Groups: 0
…
VmPeak: 48315864 kB
VmSize: 48080772 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: [COLOR="#A52A2A"]6442880 [/COLOR]kB
VmRSS: [COLOR="#A52A2A"]3996968 [/COLOR]kB
RssAnon: 3977792 kB
RssFile: 19144 kB
RssShmem: 32 kB
VmData: 48014352 kB
VmStk: 132 kB
VmExe: 4 kB
VmLib: 17784 kB
VmPTE: 13028 kB
VmPMD: 108 kB
VmSwap: 0 kB
HugetlbPages: 0 kB
Threads: [COLOR="#A52A2A"]1366[/COLOR]
…
[/td]
[td]Name: java
…
FDSize: [COLOR="#A52A2A"]512[/COLOR]
Groups:
…
VmPeak: 47170508 kB
VmSize: 47119108 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: [COLOR="#A52A2A"]1570056 [/COLOR]kB
VmRSS: [COLOR="#A52A2A"]1560688 [/COLOR]kB
RssAnon: 1542096 kB
RssFile: 18560 kB
RssShmem: 32 kB
VmData: 47057508 kB
VmStk: 132 kB
VmExe: 4 kB
VmLib: 17108 kB
VmPTE: 5584 kB
VmPMD: 84 kB
VmSwap: 0 kB
HugetlbPages: 0 kB
Threads: [COLOR="#A52A2A"]378[/COLOR]
…
[/td]
[/tr]
[/table]

Then I modified the Systemd unit file to change cgroup from system.slice to user.slice (since the process started from command line has cgroup with user.slice)

[CODE][Unit]
Description=Image Server
After=Volumes-localStorage2.mount autofs.service

[Service]
Type=simple
ExecStartPre=/bin/sleep 60
ExecStart=/root/ccs/ias/jetty/startjetty.sh
ExecStop=/root/ccs/ias/jetty/endjetty.sh
Restart=always
[COLOR="#A52A2A"]Slice=user.slice[/COLOR]

[Install]
WantedBy=default.target[/CODE]

[table=“width: 500, class: grid”]
[tr]
[td]File[/td]
[td]Process started with command line[/td]
[td]Process started using systemd service[/td]
[/tr]
[tr]
[td]cgroup[/td]
[td]11: perf_event:/
10:devices:/[COLOR="#A52A2A"]user.slice[/COLOR]
9:hugetlb:/
8:freezer:/
7:cpu,cpuacct:/
6:memory:/
5:blkio:/
4: pids:[COLOR="#A52A2A"]/user.slice/[/COLOR]user-0.slice/session-111.scope
3:cpuset:/
2:net_cls,net_prio:/
1:name=systemd:/[COLOR="#A52A2A"]user.slice[/COLOR]/user-0.slice/session-111.scope
[/td]
[td]11: perf_event:/
10:devices:/[COLOR="#A52A2A"]user.slice[/COLOR]
9:hugetlb:/
8:freezer:/
7:cpu,cpuacct:/
6:memory:/
5:blkio:/
4: pids:/[COLOR="#A52A2A"]user.slice[/COLOR]/ccs-is.service
3:cpuset:/
2:net_cls,net_prio:/
1:name=systemd:/[COLOR="#A52A2A"]user.slice[/COLOR]/ccs-is.service
[/td]
[/tr]
[tr]
[td]status[/td]
[td]Name: java
…
FDSize: [COLOR="#A52A2A"]2048[/COLOR]
Groups: 0
…
VmPeak: 48315864 kB
VmSize: 48080772 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: [COLOR="#A52A2A"]6442880 [/COLOR]kB
VmRSS: [COLOR="#A52A2A"]3996968 [/COLOR]kB
RssAnon: 3977792 kB
RssFile: 19144 kB
RssShmem: 32 kB
VmData: 48014352 kB
VmStk: 132 kB
VmExe: 4 kB
VmLib: 17784 kB
VmPTE: 13028 kB
VmPMD: 108 kB
VmSwap: 0 kB
HugetlbPages: 0 kB
Threads: [COLOR="#A52A2A"]1366[/COLOR]
…
[/td]
[td]Name: java
…
FDSize: [COLOR="#A52A2A"]1024[/COLOR]

	…
	VmPeak:              47180788 kB
	VmSize:                47107864 kB
	VmLck:        0 kB
	VmPin:        0 kB
	VmHWM:            [COLOR="#A52A2A"]3609828 [/COLOR]kB
	VmRSS: [COLOR="#A52A2A"]3609424 [/COLOR]kB
	RssAnon:             3590372 kB
	RssFile:    19020 kB
	RssShmem:              32 kB
	VmData:              47041444 kB
	VmStk:      132 kB
	VmExe:        4 kB
	VmLib:     17784 kB
	VmPTE:     9776 kB
	VmPMD:                    96 kB
	VmSwap:                    0 kB
	HugetlbPages:          0 kB
	Threads:              [COLOR="#A52A2A"]422[/COLOR]
	…
[/td]

[/tr]
[/table]

I also tried by adding the following in systemd service file

LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity

Still it didn’t solve the problem.

Please help!!, Thanks in advance.