 One of the hardest things to do on Linux is to figure out exactly how much memory a Process or application is taking up while it's running And you wouldn't think that this was actually a hard thing to do because there are a ton of applications out there that tell you Precisely how much memory your system is using at any given point things like bottom and top and be top and be pie top and GNOME system monitor and caddy system monitor you get the idea right there are tons of applications that do Precisely what you would want to do and when you're asking the question how much memory is my browser taking up How much memory is OBS taking up you get the idea right we ask these questions and we want the answers But then you take a look at something like each top and it gives you a bunch of nonsense right or it looks like nonsense so What I want to do today is talk a little bit about this problem because it is kind of a problem but it's also just kind of highlights the confusion of Maintaining a Linux system now first off before we jump in if you leave a thumbs up on this video I'd really appreciate it. It really helped the channel and Thank you very much for doing that it takes like just a second the buttons right down there So I appreciate that I don't know why I went all youtuber there, but whatever so let's talk about this problem Right, so if we take a look at my running of H top This is H top and it is out of the box very confusing Well, at least it looks confusing if you've never seen it before so at the top We have a CPU monitor and it's telling me the usage of all my CPU cores in total everything That's running is running through those CPU cores and it's giving me a percentage of use per core right starting with zero going to 15 So right below that here We have the total memory that I'm using on my system right now I'm using six point six six out of sixty two gigabytes of RAM and that is just the sum of Everything it is running on my machine So if you were to just have this right if you were to just quit this and that'd be the equivalent of running three Dash M like so and it's going to tell you that I'm using 8.166 and Had tells me I have 64 gigabytes of RAM So here is where we start to have some issues because these this is these are two different tools to tell you how much Memory you're using and we're not even getting into the whole processes thing that we'll talk about here in a minute Free tells me I have 64 gigabytes of RAM H top Tells me I have 62 gigabytes of RAM now obviously what H top is doing it is that it's cutting out The swap that I have set aside. I believe that's what it's doing so because if I add 62 and 6 and 2 I get 64.7 and That's basically what Free is Tommy that I have so I'm assuming that that's what it's doing But it's also possible that it's counting it in a different way And obviously it's counting the used in a different way because this free is Tommy I'm using 8166 which is about a gig a little bit under eight gigabytes of RAM if I go back to H top again Each top tells me that I'm using 6.69 gigabytes of RAM. So why is it counting things differently whether It's counting the total amount of RAM that I have differently or it's counting the total amount of RAM that I'm using differently It's counting it differently and that is weird, right? Because you'd think that no matter what application I'm using I should be able to Go into it. So if I go to be top here just like so I should be able to see exactly how much memory I'm using so I'd be top is Tommy. I'm using 7.9 for Mem a gigabytes of memory. So if I run free free again, like so it's time I'm using 8.22 and if I go to H top it'll tell me I'm using six something That's three different applications telling me something completely different when it comes to how much RAM my system is using What the hell is going on? Well, what's going on is that there's not a Single way of counting how much memory your system is using so they're all doing it in a different way. Also, they're combining processes and Doing things in a slightly different way that means that the sum that they get at the end is Going to be different than some other application that counts things in a different way So I think you'll see something a little bit different here when we look at be top because be top does something That is very similar to what windows task manager does or at least it does more recently The windows task manager has the same problem that Linux does where a whole bunch of processes are running for you Like your browser or whatever what windows task manager will do is it will group them together So it looks just like one process be top kind of does the same thing where it Actually groups things that are related to each other by this tree like structure It's not always the best way to group things because like what does pi com have to do with system D? Well, obviously if you know anything about the way, you know, Linux works system D is the Godfather of literally everything that runs on your machine. It starts those things, right? It it Handles all of the initiation of every task on your machine So that's the reason why everything that is running is running underneath that now as you can see everything here is Grouped just like you would kind of expect but if we go back to each top There are no groups here, but you can still see the same kind of thing going on So particularly when it comes to multiple processes So things like OBS are going to have a bunch of different processes running if you're looking at discord discord now Here's the thing about browsers, right? And I know you're saying well Matt Discord's not a browser. Well discord is an electron application which runs on web technology. Basically, it's chromium underneath It, right? So it is a browser. It's just running the web wrapper for discord So if we scroll down here, we'll see that to do is is doing the exactly the same thing And then we have a voli one here the voli two will have a whole bunch of different processes if we scroll down far enough and browsers and electron apps are going to do that But they're not the only applications that split out there running into different processes. So things like System D does this obviously audacity does it Basically everything you're going to see comes and runs with different Processes for different things that it's doing and each one of these is going to use up memory Now the problem with the way we display this particularly in each top is that the memory line here isn't always What's actually going on? So some of these processes aren't actually separate processes And you'll notice that because like for example if we can get to we can actually see this not moving around for a Little bit you can see some of them run the exact same memory percentage So this process and this process here are both running 2.4 percent of memory It seems a little bit coincidental that they're actually using the exact same percentage of memory when they're separate processes, right? And they're always linked. They're always exactly the same yet when you go see like a different Processes down here. Some of these are 2.4. Some of them are a little bit different Why is it listing them as different processes if they're using the same amount of RAM? Well, it's because the processes themselves aren't tied to the RAM But are instead tied to the amount of CPU that they're using so It's very confusing when you're seeing it in this type of layout because it's kind of not only is it moving around all the time But also, you know, was it actually counting so you can see just going from these different applications that it is Hard to actually find out how much memory your system is actually using. How do I find out how much memory? Vivaldi's using or how much memory OBS is using and how can I trust that the application that I'm Using to measure those things is actually telling me the truth and the answer that question is that you don't I Know that that's a really pissed poor answer, but it's just the answer so on Linux when you talk about memory usage per application Figuring out how much memory those things are actually using is hard because like I said every application counts things a little bit differently So when you see Something telling you that it's using X amount of RAM really what it's doing is it's Estimating at any given point and one of the things that we'll have to remember when we're talking about Linux is that everything is Not only constantly moving because things are running and Processes are doing things in the background. So right now OBS is recording now You think that recording the screen and recording my voice and stuff like that is fairly a simple when it comes to just the broader Idea of what it's doing, but underneath There's a whole bunch of technology that's going into that You know, it's probably using a whole bunch of different codecs and video stuff that's going on in the background all of that stuff has to be running in order for the Overlying features to actually work all applications are like that so when You ask Linux to tell you precisely how much memory something is using it Moves around a lot because things are changing but also we have to remember that everything in Linux is a file So if you have a process It's always going to be in a file somewhere and those files are always moving around being rewritten overwritten moved around and all That stuff so if you go into your terminal and we zoom in here just a little bit And we type in PID of and say OBS. It might be studio. I'm not It might be just OBS. We're gonna find out and just must be OBS So just like that. So if we look that we can see that every process has a PID so this Identification number identifies the process of that application and that's how it tracks Not only, you know the process of what it's doing But also when say H top queries the system of over how much memory OBS is using it's what it's querying is the file of that particular process So for example, if we go in back into H top, we'll see that each one of these has a PID, right? And that's a process number. So we can see that my particular system is running a hundred and ninety tasks 1192 threads and each one of these is going to be related to a task or a thread and like I said, every one of these is a file and You think that you just well if it's a file I can just go measure how large that file is and it will tell me how much memory it's using Well, it doesn't really work like that And also as you can see these things move around much too fast for you to actually be able to query that and then be able to rely on those numbers so Telling exactly how much memory something actually is using is a constant moving target and Because it's that way and because applications measure things in different ways and combine processes in different ways and Group PIDs in different ways all this stuff every application tells you does things that's a little bit differently You're always almost always going to get a different number depending on what you're looking at So we could go through and add up the amount of memory that OBS is using we can do that through free We can do that through something like B top so if we go to B top again We can actually go down here and we should be able to go down here and see Exactly how much OBS is using if we scroll down far enough We'll actually see that OBS here has all these processes associated with so we have 18 432 Which is the main PID of OBS but everything below that has its own PID Well, we can see that B top unlike H top does a combined Memory count for us. So it's telling me that it's using 1.5 gigabytes of memory and what that has done is it's added up all of the processes together and then Talented up into this sum and then given it to you right, but we have to ask the question Is that accurate? Well, we don't know and It's a moving target like we said and it relies on all of these different files that are going around and moving around So this is the output that B top actually gives you and in my opinion B top is the best tool you can use to actually get this information because it does Add things up for you. I believe that if you go into H top You can through some finagling actually get each top to show you the exactly the same because it does tell you how much memory those things are using so there is a virtual and reserved memory column here But unless you're a computer nerd You probably don't know what the difference is between virtual and reserved memory or shared memory and what are those things actually mean? well, I'm a computer nerd and I don't even know half the time what those things mean and why those things are important So each top is not a very good tool for figuring out What memory is used where and also? Jizo Pete's OBS using 216% of CPU right now. Goodness gracious Anyways, if we go back and into B top we can actually see some more of this So when you're talking about measuring Your memory usage there are a few things you have to keep in mind the sum of memory that a Application uses is one thing to ask for so if you go into B top and you see this here It's going to give you a sum of that particular process and because we're using the tree Filter here. You can change that by pressing the E key If we go back if we press the E key what it's gonna do is not have the tree so it's not gonna group them together so if you're Looking at this you can actually see how things are added up together and that's a nice way of doing it But that's separate From this part over here, which is telling us how much memory the entire system is using in Totality and like I said and like I showed at the beginning that number there you can't trust it You're never gonna be able to trust it and you're never gonna know which one is telling the absolute truth So right now like I said B top is saying 7.75 gigabytes if we run free dash M again It's telling me I'm using 7.934 gigabytes of memory if we go back into H top It's gonna tell us we're using 6.49 gigabytes of memory So that number there is where our real problem lays like the and it cast doubt of course on The numbers we got from B top and from a top over how much memory the applications are using because that number there that total sum is just a sum of all of the Processes and applications that are running on the system and taking up memory and it's kind of like when you have a bunch of money And now I know that this is not an experience that everybody has but somewhere along the line You've probably held up a stack of $1 bills or $10 bills or something like that and you know a couple hundred bucks And when you go through and you count them and you get one number and then because you don't trust your counting Abilities you go through and count it again You get another number that's a kind of what's going on here and that's weird Right because you would expect to be able to be able to tell exactly how much memory my system is using but you can't because they're all adding things up in a little bit different way and Whether or not that's because they don't know how to count which is probably not the case But mostly it's just they have a different process for actually Counting those Processes and adding them up into how much memory those processes are using so What's a Linux nerd to do when you need to know exactly how much memory your system is using well They answer that question is that you just kind of what I've what I try to do is I look at all three of them If I really need to know and I kind of average them So right now I know that I'm using about eight gigabytes of memory each top for origin is always a little low by like Two gigabytes and again, I'm pretty sure that's because it's subtracting the swap I don't know why it does that because the swap is technically a part of the hard drive not the actual memory So it doesn't really make sense that is it's subtracting the swap Maybe that's not what it's doing It's just counting the overall memory wrong Which is still very weird because it shouldn't be doing that because I have 64 gigabytes of memory We should also note that free seems to count that Exactly right whereas each top and be top. I believe I don't actually know what be top it shows So be top tells me I have 62 gigabytes of memory as well So it too is counting it in a slightly different way the total amount of like we I know that I have 64 gigabytes of RAM in my Machine now we all know that the RAM thing is in hard drive space is also like this where you know you buy a 128 gigabyte hard drive and you're not gonna get 128 gigabytes of storage. You're gonna get 118 or something like that It's a scam of course, and I'm sure there's a technological reason behind it But it feels like a scam and it maybe that's what's happening here is that though because I have 64 gigabytes memory Would I really have a 62 usable gigabytes of memory? Which is you know again a scam But free seems to count it right so the question is why don't they just use free? Well, maybe free is not reliable. Maybe that's not the way that it's supposed to be kind of I don't know That but there has to be a reason right and the though whole thing is like that's what I tend to do is just kind of Average them together and I always kind of discount a little bit H top because it's so low in terms of the actual used Memory be top and free team seem to be a little bit closer together You they're usually within five or six hundred megabytes of each other and that's not a bad difference to have You know I can kind of see where I'm at. I'm assuming I'm probably right in the middle And that's the way that I do it Now in terms of processes I always use be top because it groups things together and adds them together And I don't have to go through and do that and it doesn't move around as much like H top does So when it comes down to it at the end of the day Figuring out how much memory you're actually using can be a task and you're never quite sure what you should believe just know That you probably should have enough memory in your machine to be Generous to applications that you're running So if you think you only need a gigabytes you're probably wrong you probably need 16 if you think you need 16 You're probably wrong you need 32 and that goes that can continue on up the scale See I thought that I needed 32 so I bought 64 and I think that that's just kind of a good rule of thumb because it just kind of While they say that unused RAM is a waste of RAM I'd rather have more RAM and have it just sit there and do nothing Then have not enough RAM and always have to close programs just because I don't have enough That's the way that I've always looked at it So that's a that's a more of a hardware problem obviously, but that's just it all kind of plays into it So that's it for this video. You can see how confusing this can be Especially if you're talking to people who are new Linux users They come from Windows where Windows has one tool to measure this thing and that's the one that you trust every I mean, I'm sure that there are third-party tools to measure processes and system resources on Windows but most people are just going to probably use Windows task manager and That's gonna be one place where they can kind of trust what's going on they don't have multiple different places to look usually and Therefore they don't have different stories being told to them They don't have you know one application saying they're using five gigabytes the other another one saying they're doing six another one They're saying seven usually they just choose the one place to look for and The problem with being a Linux nerd is that we don't we're not satisfied with just one tool We have to have to twelve of them on our It's I'm not lying when I say I have at least seven of these on my machine I'm pretty sure I'm not alone about that I I mean obviously have top because that's built in I have each top I have be top I have free obviously because that's built in I'm pretty sure I have GNOME system manager or Katie's as manager one of the two on the machine so I have five or six of them just on my machine and I think that probably the vast majority of Linux nerds are exactly like me when it comes to that and If you looked at all of them, they're all gonna measure things a little bit differently And that's just gonna add to the confusion. So turns out that the whole video just boiled on to I'm confused Anyways, that's it for this video if you have thoughts on this whole Nonsense if you're smarter than me know what the hell is going on you can leave those in the comment section below I'd love to hear from you you can follow me on masses on our odyssey those links to being the video description if you Haven't already leave a thumbs up on this video It really helped the channel and if you haven't already and you like this kind of stuff hit the subscribe button because this channel is Awesome, and I make Linux content several times a week And I like to rant and rave and talk about applications and links distros and all that stuff So hit the subscribe button You can also head on over to the store where you can find desk mats and hats and hoodies and all sorts of Stuff to help support the channel as well. That's that shop at the links cast at org Thanks to everybody who does support me on patreon on YouTube because you're all absolutely amazing without you The channel just would not be anywhere near where it is right now. So thank you so very very Very very much for your support. I truly truly truly do appreciate it I like to repeat words here I have this tendency when I truly mean something to repeat the word over and over again just to You know hammer home the points anyways, thanks everybody for watching. I'll see you next time