We maybe need to use "unified cgroup hierarchy" as explained at Unified and Legacy Control Group Hierarchies.
To enable this feature, add
systemd.unified_cgroup_hierarchy=1
to GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub,
run update-grub, and reboot Linux.
systemd.unified_cgroup_hierarchy is explained insystemd unified cgroup hierarchy.
Then added the following lines at [Service] section of your systemd unit file,
and run systemctl daemon-reload:
Delegate=memory
MemoryHigh=8G (if you choose 8 gigabytes as the limit)
Explanation of "MemoryHigh" is given at
systemd.resource-control.