# Memory excessive?



## doc1623 (May 23, 2013)

xorg seems to be using a lot of memory to me. Also, opera seems to be a problem. I'm just having some slowness/freezing issues and was wondering if anything below popped out to the experts here. Please let me know what you think. So, far I've rebuilt xorg. 

Thanks


This first one is right after reboot (grabbed just the top 12):

```
last pid:  2103;  load averages:  0.53,  0.48,  0.22                                                                                                                                                                                                  up 0+00:02:11  21:22:19
63 processes:  1 running, 62 sleeping
CPU:  0.9% user,  0.0% nice,  0.0% system,  0.0% interrupt, 99.1% idle
Mem: 186M Active, 34M Inact, 348M Wired, 5956K Cache, 128K Buf, 3093M Free
Swap: 4096M Total, 4096M Free

  PID USERNAME    THR PRI NICE   SIZE    RES STATE   C   TIME   WCPU COMMAND
 1996 larry         1  22    0   392M 75076K select  2   0:04  4.49% enlightenment
 1750 root          1  23    0  3222M 34920K select  1   0:04  2.98% Xorg
 2091 root          1  20    0 16564K  2480K CPU3    3   0:00  0.39% top
 2040 larry         2  79    3   464M 60664K select  0   0:01  0.29% python2.7
 2051 larry         1  52    3 33588K  5332K pause   1   0:00  0.20% zsh
 2089 root          1  30    0 26872K  4984K pause   2   0:00  0.20% zsh
 2088 larry         1  31    3 41176K  2272K wait    2   0:00  0.20% su
 1943 haldaemon     2  31    0 97556K  9132K select  1   0:00  0.00% hald
 1758 pgsql         1  52    0 72596K  6780K select  0   0:00  0.00% postgres
 1746 root          1  27    0 76860K  8316K wait    0   0:00  0.00% slim
 1944 root          2  52    0 81904K  6872K select  0   0:00  0.00% hald-runner
 1730 root         18  52    0   117M  8200K waitvt  2   0:00  0.00% console-kit-daemon
```

Another with opera seemingly, eating a lot:

```
1996 larry         1  23    0   392M 85404K select  0   1:10  4.69% enlightenment
 1750 root          1  20    0  3222M 36328K select  2   0:52  1.95% Xorg
 2105 larry         5  23    3  1458M  1225M uwait   1   2:27  1.27% opera
 2040 larry         2  75    3   465M 62356K select  0   0:04  0.00% python2.7
 1338 root          1  20    0 14232K  1284K select  0   0:04  0.00% moused
 1943 haldaemon     2  31    0 97556K  9132K select  1   0:01  0.00% hald
 1758 pgsql         1  20    0 72596K  6780K select  3   0:00  0.00% postgres
 1746 root          1  27    0 76860K  8316K wait    0   0:00  0.00% slim
 1977 root          1  20    0 20872K  2324K select  3   0:00  0.00% hald-addon-storage
 1944 root          2  52    0 81904K  6872K select  0   0:00  0.00% hald-runner
 2034 larry         1  23    3 66840K  6888K select  2   0:00  0.00% enlightenment_fm
 2089 root          1  20    0 35312K  6164K pause   2   0:00  0.00% zsh
```


----------



## SirDice (May 23, 2013)

A modern OS will use all the available memory. Unused memory is useless memory.

As long as there's no (excessive) swapping you should be alright.


----------



## kpa (May 23, 2013)

In your top(1) listing, Xorg has resident set size of roughly 36 megabytes. Think about it for a moment and decide if that's significant or not compared to the amount of total memory  in your system


----------



## wblock@ (May 23, 2013)

The overall size of 3222 M seems large.  But the thing that jumps out at second glance is that X is running as root.  That is bad.


----------



## doc1623 (May 23, 2013)

*sysinfo*

@wblock@ I thought that was a bit much; that's why I rebuilt via portmaster but it didn't change anything. As far as X running as root, well uhm, guess I'm just doing it wrong. I thought everything was run as root until you logged in. In my case through slim. Guess, I'll have to look into that.

Thanks everyone for taking a look.

More info:


```
root@freebsd:/home/larry # sysinfo mem
Generated by SysInfo v1.0.1 by Daniel Gerzo

RAM information

Memory information from dmidecode(8)
Maximum Memory Module Size: 4096 MB
Maximum Total Memory Size: 16384 MB
Maximum Capacity: 8 GB
Number Of Devices: 4

INFO: Run `dmidecode -t memory` to see further information.

System memory summary
Total real memory available:    3803 MB
Logically used memory:          3510 MB
Logically available memory:     293 MB

Swap information
Device          1K-blocks     Used    Avail Capacity
/dev/zvol/zroot/swap   4194304       0B     4.0G     0%
```

A fairly piddly CPU.

```
root@freebsd:/home/larry # sysinfo cpu
Generated by SysInfo v1.0.1 by Daniel Gerzo

CPU information

Machine class:  amd64
CPU Model:      AMD Phenom(tm) 9150e Quad-Core Processor
No. of Cores:   4
Cores per CPU:

CPU usage statistics:
CPU:  0.4% user,  0.8% nice,  1.1% system,  0.2% interrupt, 97.5% idle
```


----------



## kpa (May 23, 2013)

Remember that the RSS field gives the real memory usage of the process, the SIZE is the total amount of memory if all the code and data (including shared libraries) of the process was loaded in memory, many times unused code never gets loaded or gets swapped out pretty quick.

Isn't X setuid(2) root by default?


----------



## wblock@ (May 23, 2013)

I don't use slim or any login manager, so that may be the difference.  Size here is 804   M and Res is 376   M.


----------



## Crivens (May 23, 2013)

Freshly booted 2 GB Laptop here, running Xfce. Xorg currently has these memory requirements:

```
SIZE = 697M  RES = 293M
```
Firefox uses something like 530 / 300 MB.
Annoyingly, I log in using good old xdm and my Xorg also is running as root. So, if this is not what is supposed to happen, what now?


----------



## phoenix (May 25, 2013)

You have 4 GB of free RAM, what are you worried about?


----------



## throAU (May 28, 2013)

kpa said:
			
		

> Remember that the RSS field gives the real memory usage of the process, the SIZE is the total amount of memory if all the code and data (including shared libraries) of the process was loaded in memory, many times unused code never gets loaded or gets swapped out pretty quick.
> 
> Isn't X setuid(2) root by default?



That. In short: you're reading your memory consumption wrong. If you use a login manager it needs to run as root so it can fire off a session running as whatever user. The real current RAM usage of everything on your box (other than cache) is "Active" + "Inactive" which is what... 220 megabytes.


----------



## Beastie (May 28, 2013)

throAU said:
			
		

> The real current RAM usage of everything on your box (other than cache) is "Active" + "Inactive" which is what... 220 megabytes.


Don't forget the "Wired" portion that is made of pages that can't be de/activated (swapped out/in).
So it's more like half a GB.

Still not much though...


Opera is another story. Its memory management has been getting messier with every release since 11.x. I've noticed it doesn't release memory even when you close all tabs and clear history and cache.


----------



## throAU (May 28, 2013)

I thought "wired" included active + inactive + cache + kernel overhead? I.e., it's not 220 + wired, but rather wired includes all of it?


----------



## SirDice (May 28, 2013)

Wired memory is memory that's "tied down" i.e. cannot be swapped out. Hence it cannot include inactive memory.


----------



## phoenix (May 28, 2013)

Instead of trying to add up all the different fields, why not just subtract Free from Total?  IOW, ~4 GB - 3 GB = ~1 GB of RAM in use.  Wow, that's hard.

Or, even simpler, just look at the Free field.  You have 3 GB of RAM that's completely unused (not cached, used for buffers, completely empty)!

Again, where's the problem?


----------



## doc1623 (May 29, 2013)

*Unknown*

Wow, Thanks for all the replies. If nothing else it's great to help understand the memory displayed by `top`.

The problem is that the computer freezes or slows down to nothing. More directly, I have absolutely, no idea what the problem is. I just posted here hoping the experts here would see something. 

It's seems to be something graphical (maybe). It happens when I'm using opera or firefox or virtual-box, basically, my heavier programs.I have rebuilt xorg, to no effect. None of the logs in */var/log* are recent enough to contain pertinent information. Actually, even `top` does not run until the pause is over. If it's not completely locked, or seemingly, I can fix it by closing everything and walking a way for a while, but it never seems to be as quick as it was until I do a reboot. It could easily be something with enlightenment. I am a huge fan but it actually seems buggier since the official release. I have run memtest. All test pass. 

The top I posted was just a shot in the dark. Unfortunately, I really don't know where to look to even start to narrow it down. 

Thanks again for all the replies.


----------



## wblock@ (May 29, 2013)

Please post your xorg.conf.  We may end up starting a new thread.


----------



## Beastie (May 29, 2013)

Have you checked both /var/log/Xorg.0.log and /var/log/Xorg.0.log.old?
If you say the logs are not recent enough, maybe it's because Xorg doesn't have enough time to write the errors that end up locking the machine.

Add the following line to /etc/X11/xorg.conf:

```
Section "ServerLayout"
        [...]
        Option "Log" "sync"
        [...]
EndSection
```


Try to exclude one application or another as the culprit by simply testing the system without it. For example, try to replace Enlightenment with some lightweight WM, say Fluxbox.

Or if you notice Opera is starting to use too much memory, save the session and close it. Sometimes Flash or a JavaScript code on some page can lock up Opera.


----------



## r619 (Aug 21, 2013)

I have the same problem on my slow old laptop with 512 MB of memory. `top -n | grep Xorg`:

```
705 r619        1  20    0   888M 83788K select  35:58  0.00% Xorg
```

I don't use any desktop manager. (LXDM is good enough, but it's not ported/patched yet.) I compiled x11-servers/xorg-server without GLX and HAL; and with SUID bit set. /etc/X11/Xorg.conf:

```
Section "ServerLayout"
	Identifier     "bsdcr"
	Screen      0  "Screen0" 0 0
	InputDevice    "Mouse0" "CorePointer"
	InputDevice    "Keyboard0" "CoreKeyboard"
	InputDevice    "Mouse1" "USBMouse"
	Option         "AutoAddDevices" "Off"
EndSection

Section "Files"
	ModulePath   "/usr/local/lib/xorg/modules"
	FontPath     "/usr/local/lib/X11/fonts/misc/"
	FontPath     "/usr/local/lib/X11/fonts/TTF/"
	FontPath     "/usr/local/lib/X11/fonts/OTF"
	FontPath     "/usr/local/lib/X11/fonts/Type1/"
	FontPath     "/usr/local/lib/X11/fonts/100dpi/"
	FontPath     "/usr/local/lib/X11/fonts/75dpi/"
	FontPath     "/usr/local/lib/X11/fonts/Droid/"
EndSection

Section "Module"
#	Load  "extmod"
#	Load  "record"
#	Load  "dbe"
#	Load  "dri"
#	Load  "dri2"
#	Load  "glx"
	Load  "freetype"
#	Load  "fontcache"
EndSection

Section "InputDevice"
	Identifier  "Keyboard0"
	Driver      "kbd"
EndSection

Section "InputDevice"
	Identifier  "Mouse0"
	Driver      "mouse"
	Option	    "Protocol" "auto"
	Option	    "Device" "/dev/psm0"
	Option	    "ZAxisMapping" "4 5 6 7"
EndSection

Section "InputDevice"
	Identifier  "Mouse1"
	Driver      "mouse"
	Option      "Protocol" "auto"
	Option      "Device" "/dev/sysmouse"
	Option      "ZAxisMapping" "4 5 6 7"
EndSection

Section "Monitor"
	Identifier   "Monitor0"
        Option       "DPMS"
        Modeline "1024x768_60.00"  64.11  1024 1080 1184 1344  768 769 772 795  -HSync +Vsync
	HorizSync    55-75
EndSection

Section "Device"
        ### Available Driver options are:-
        ### Values: <i>: integer, <f>: float, <bool>: "True"/"False",
        ### <string>: "String", <freq>: "<f> Hz/kHz/MHz"
        ### [arg]: arg optional
        #Option     "ShadowFB"           	# [<bool>]
        #Option     "DefaultRefresh"     	# [<bool>]
        #Option     "ModeSetClearScreen" 	# [<bool>]
	Identifier  "Card0"
	Driver      "vesa"
	BusID       "PCI:1:0:0"
EndSection

Section "Screen"
	Identifier "Screen0"
	Device     "Card0"
	Monitor    "Monitor0"
	SubSection "Display"
		Viewport   0 0
		Depth     24
		Modes     "1024x768"
	EndSubSection
EndSection
```


----------



## kpa (Aug 21, 2013)

> ```
> 705 r619        1  20    0   888M 83788K select  35:58  0.00% Xorg
> ```



You have roughly 83 megabytes of memory taken by the Xorg process if you look at the RES column, that's the real memory usage of the process at any given. Is that too much in your opinion?


----------

