How to disable desktop environment and then re-enable it?

I want to free CPU and RAM for a while , I’m on KDE will switching to tty and disabling desktop environment help achieve this If I do this :backhand_index_pointing_down: in tty

sudo systemctl stop sddm

and then do this :backhand_index_pointing_down: in tty

sudo systemctl start sddm

will it free my cpu and RAM during that time

That won’t work like this.
Install another distro if you’re low on resources. Like Mabox, which is manjaro without DE.

sudo systemctl disable sddm

will prevent the display manager from starting the next time you boot and you will land you on a TTY

You can still start a graphical session from there, but initially it will save the time and some memory from being used.

sudo systemctl enable sddm
will enable the display manager again

All this will not really free up CPU or RAM.

Not sure what you want to achieve with that, but if you want to stop the graphical environment, you can get that with:

systemctl isolate multi-user

(this is the equivalent of init 3 in the old sysvinit system)

To get back your graphical environment, execute:

systemctl isolate graphical

(this is the equivalent of init 6 in the old system)

Of course you should run these commands in a tty (Usually something like CTRL+ALT+F3 from the graphical environment). Also add sudo if you log in to the tty with a normal user.

2 Likes

Before trying a random (mindless) solution please explain why and what you really want to achieve. :wink:

2 Likes

It will free up some RAM, because logging out of the desktop environment or stopping the graphical session altogether will flush buffers and drop some cache, and a lot of stuff will not be loaded in RAM anymore.

However, there should be no need for this, as the Linux kernel is very good at managing memory — actually, Linux manages memory probably better than any other operating system kernel out there.

What you need to understand is that a lot of the memory in use is simply cache. This means that it’s disposable memory content, only kept in virtual memory for convenience, so as to improve performance — it is faster to load something already in RAM than to load something from the drive.

When more memory is needed, the kernel can do two things, i.e. paging out stuff to the swap device, and releasing some of the memory used as cache.

The bottom line of course, is that we’re dealing with an XY problem. You are asking about a proposed solution to a problem, rather than about the problem itself.

Maybe you should tell us why you want to temporarily free up RAM? If it’s because of potential memory corruption by cosmic radiation or electromagnetic fields, then this approach won’t work. If this is your concern, then you should shut down the computer and let it sit powered down for about 10 to 15 minutes before booting back up.

Again, tell us about the problem, not about what you think the solution would be to some problem that you’re not sharing with us.

5 Likes

Thanks everyone for an incredibly helpful and clear explanation of how CPU and RAM consumption function together.

I was running Conda and it was eating my CPU and RAM , I didn’t know I can give limited thread and downgrade to older version , since all i needed terminal to access conda I thought if I just disable desktop environment and enable it later

it still isnt clear why you thought nuking the DE was the resolution, i’ve no idea what conda does. but if this was on the lines of having maximum available memory to run your stuff, and you think plasma resource usage is too much, try using alternate light weight window-manger. there are plenty available through official repos. Window manager - ArchWiki

in case you need quick memory cache drop after an exhaustive op, you can use;

sudo sh -c "sync && echo 3 > /proc/sys/vm/drop_caches && echo 1 > /proc/sys/vm/compact_memory"
4 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.