Why is the memory usage sharply decreased after restarting the service?
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Matthew_Wai@My-PC:~$ free -h
total used free shared buff/cache available
Mem: 5.7Gi 880Mi 2.6Gi 59Mi 2.3Gi 4.5Gi
Swap: 2.0Gi 0B 2.0Gi
Matthew_Wai@My-PC:~$ sudo systemctl stop HDD_temp && sudo systemctl start HDD_temp
[sudo] password for Matthew_Wai:
Verification successful
Matthew_Wai@My-PC:~$ free -h
total used free shared buff/cache available
Mem: 5.7Gi 888Mi 2.4Gi 59Mi 2.4Gi 4.5Gi
Swap: 2.0Gi 0B 2.0Gi
Matthew_Wai@My-PC:~$
The above output shows the following:
(1) "buff/cache" was "2.3Gi" originally.
(2) The service was restarted.
(3) "buff/cache" was "2.4Gi" after the restart.
Restarting the service did not clear the cache.
Last edited by Matthew Wai; 11-23-2023 at 11:25 PM.
are you sure you can manage the memory better than the kernel itself (which was developed to do this). see post #5.
But there is another question here too: are you sure kernel won't free it up by itself if that memory will be needed for something more important?
Actually it is not a simple shell script, it invokes at least 5-6 additional tools, like sudo, date, service, grep, hddtemp.
Quote:
Originally Posted by Matthew Wai
Restarting the service did not clear the cache.
Obviously, it won't do that, just tells the kernel that the memory/cache used by this service is not needed any more.
As you can see you have a lot of memory available, why don't you allow the kernel to use it for something useful (speed up something a bit)?
Both the service and the script were written by me.
Both work fine after the service is restarted.
I am not smart enough to figure out why the service should not be restarted.
Both the service and the script were written by me.
Both work fine after the service is restarted.
I am not smart enough to figure out why the service should not be restarted.
I'm not really convinced that restarting the service will help anything. You need to make at least more measurements and more precise measurements to be sure.
I wonder if your shell script will ever log "Failure".?
The variable "${S}" is empty by default. “Failure” will appear as long as "${S}" remains empty.
I have never seen “Failure” in the “Log” file, as the following command never fails repeatedly. sudo service fancontrol start
Quote:
Originally Posted by MadeInGermany
But I have no explanation why it should consume MBs of memory.
After restarting the service, it uses 496 KB, which is reasonable. See below:
Code:
Matthew_Wai@My-PC:~$ service HDD_temp status|grep "Memory"
Memory: 496.0K
Matthew_Wai@My-PC:~$
One possible explanation is that there is a bug in the kernel or the memory management code.
Obviously, this cannot be ruled out. It's just almost impossible. The Linux kernel is currently used on countless hosts (millions or even billions of devices and VMs) and has been running for decades, not just years. Such an error should have been detected and corrected a long time ago. Otherwise, all of these systems would inevitably be unstable and unreliable
The loop will end even if "${S}" is empty. The reason is shown below:
Code:
for ((N=0;N<20;N++))
The loop will not be an endless loop.
the for loop is not an endless loop, the while loop you wrote is an endless loop, if fancontrol cannot be started this loop will just run forever. If the "service | grep" command always fails, it never sets S to anything.
A waste of 200 MB of memory will not cause an error, instability, or unreliability.
That is wrong. Any [unpredictable] memory leak will lead to crash sooner or later. And actually wasting a single byte (not 200MB) under any circumstances is very dangerous, unacceptable.
That is wrong. Any [unpredictable] memory leak will lead to crash sooner or later. And actually wasting a single byte (not 200MB) under any circumstances is very dangerous, unacceptable.
I did not mean a memory leak. When I wrote "a waste of 200 MB", I meant the memory usage could safely be reduced.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.