Centos not using available memory - postgresql

I have Centos installed on a server with 64gb memory and it seems as if the memory usage is being suppressed.
I came to this conclusion by running an insert statement where I insert 10million rows into a Postgres table in both a Timescaledb and a standard Postgres instance hosted on Docker.
I monitored the insert process in three different ways:
Docker stats timescaledb:
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
timescaledb 73.14% 10.42 MiB / 62.75 GiB 0.02% 8.46 kB / 8.39 kB 0 B / 15.1 GB 12
free -i gives the following:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
16298 avahi 20 0 16.2g 762356 759908 R 41.5 1.2 0:22.72 postgres
16127 avahi 20 0 16.2g 693080 691968 S 4.3 1.1 0:01.29 postgres
16129 avahi 20 0 16.2g 17748 16712 S 2.3 0.0 0:00.87 postgres
1578 root 30 10 1232780 86976 11568 S 0.7 0.1 0:46.34 osqueryd
17014 root 20 0 162264 2480 1596 R 0.7 0.0 0:00.03 top
928 root 20 0 90608 3212 2352 S 0.3 0.0 0:03.47 rngd
16128 avahi 20 0 16.2g 132064 131016 S 0.3 0.2 0:00.18 postgres
free -h gives the following
total used free shared buff/cache available
Mem: 62G 1.0G 58G 1.1G 3.1G 56G
Swap: 62G 0B 62G
I know that Timescaledb is an extension of Postgres which comes with its own memory configurations, but the Docker container of Timescaledb configures these automatically for you (for instance effective cache size is set at 48gb as opposed to the default 4gb that Postgres ships with). I also ran a similar process with Apache spark with 16gb assigned to the worker and it ran into an oom error. Additionally, I did a similar test on a different smaller VM and the memory usage increased as expected. All of this leads me to believe that it's a Centos config setting that I am missing somewhere, and nothing to do with Timescale/Postgres?
I have added the following parameters to vm.overcommit_memory = 2 and vm.overcommit_ratio = 95 in /etc/sysctl.conf and ran sysctl -p to implement the settings, but this didn't make a difference.
kernel.shmall = 8224280
kernel.shmmax = 33686650880
kernel.shmmni = 4096
vm.overcommit_memory = 2
vm.overcommit_ratio = 95
Below is the output from cat /proc/meminfo
MemTotal: 65794240 kB
MemFree: 61098656 kB
MemAvailable: 59252660 kB
Buffers: 2120 kB
Cached: 3467144 kB
SwapCached: 0 kB
Active: 2817620 kB
Inactive: 884816 kB
Active(anon): 1109220 kB
Inactive(anon): 234708 kB
Active(file): 1708400 kB
Inactive(file): 650108 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 65535996 kB
SwapFree: 65535996 kB
Dirty: 88 kB
Writeback: 0 kB
AnonPages: 233188 kB
Mapped: 1175120 kB
Shmem: 1110756 kB
Slab: 204044 kB
SReclaimable: 142700 kB
SUnreclaim: 61344 kB
KernelStack: 7232 kB
PageTables: 14672 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 128040524 kB
Committed_AS: 18709300 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 408824 kB
VmallocChunk: 34325399548 kB
Percpu: 9216 kB
HardwareCorrupted: 0 kB
AnonHugePages: 96256 kB
CmaTotal: 0 kB
CmaFree: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 133604 kB
DirectMap2M: 66965504 kB
Is there maybe something I can try to increase my memory usage? Is there maybe a config setting that I am missing somehere?
Thanks in advance for any help

PostgreSQL also uses "unused" memory, because it uses buffered I/O. So this "unused memory" is used by the kernel to cache files – in the case of a database server, these will be database files. That way, I/O requests by PostgreSQL can be served from the kernel cache rather than causing disk I/O requests.

Related

Flutter: What are the factors of app size? (FAQ)

I'm working on my flutter app, and the most recent size report I got is: 219 MB,
by running this command:
flutter build apk --analyze-size --target-platform=android-arm64
clearly, 219 MB size is TOO BIG for me, although I did checked out some tutorials online to reduce the app size, but none of seem effective, so I decided to REALLY dive into this topic, and here are my questions:
Does adding more packages to my app really increase my app size?
If the packages are the same, but I import them to more files, does that effect my app size?
If I increase my widgets and screens, does that increase the app size?
If numbers of widgets are the same, but I sperate (extract widget) them into different files, will the app size increase?
Does the app size that the command returns (above) really reflect my app size in the real world when I publish it?
What are the factors of app size (numbers of widgets, files, or packages)
And here is the analysis:
✓ Built build/app/outputs/flutter-apk/app-release.apk (219.5MB).
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
app-release.apk (total compressed) 219 MB
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
res/
interpolator 1 KB
drawable-hdpi-v4 21 KB
drawable-xxhdpi-v4 33 KB
drawable 16 KB
drawable-xhdpi-v4 25 KB
drawable-mdpi-v4 16 KB
drawable-xxxhdpi-v4 26 KB
color-v23 2 KB
color 3 KB
anim 8 KB
layout 21 KB
drawable-anydpi-v21 2 KB
drawable-ldrtl-xxxhdpi-v17 2 KB
layout-v21 2 KB
drawable-v21 2 KB
drawable-ldrtl-xhdpi-v17 1 KB
drawable-ldrtl-xxhdpi-v17 1 KB
layout-watch-v20 1020 B
mipmap-xxxhdpi-v4 1 KB
raw 1 MB
META-INF/
CERT.SF 34 KB
kotlin-stdlib.kotlin_module 1 KB
CERT.RSA 1016 B
MANIFEST.MF 31 KB
lib/
x86 45 MB
armeabi-v7a 58 MB
arm64-v8a 59 MB
Dart AOT symbols accounted decompressed size 8 MB
package:flutter 3 MB
package:cheese 605 KB
dart:core 389 KB
package:rive 320 KB
dart:io 278 KB
dart:typed_data 265 KB
dart:ui 247 KB
dart:collection 189 KB
dart:async 177 KB
package:flutter_svg 143 KB
package:just_audio/
just_audio.dart 77 KB
dart:convert 76 KB
package:sqflite_common 70 KB
package:vector_math 66 KB
package:petitparser 65 KB
package:photo_view 59 KB
package:source_span 58 KB
package:xml 52 KB
package:cloud_firestore_platform_interface 51 KB
package:rxdart 46 KB
x86_64 52 MB
kotlin/
reflect 2 KB
collections 1 KB
kotlin.kotlin_builtins 4 KB
assets/
flutter_assets 237 KB
IAgoraMediaEngine.h 7 KB
AgoraBase.h 8 KB
IAgoraRtcEngine.h 85 KB
IAgoraRtcChannel.h 16 KB
google/
protobuf 21 KB
resources.arsc 405 KB
okhttp3/
internal 33 KB
AndroidManifest.xml 4 KB
classes2.dex 747 KB
classes.dex 3 MB
I have tons of widgets but I have no idea how to reduce any of them, so PLEASE HELP!!!

Reduce flutter apk size

Can anyone tell me how do I reduce this apk size?
Some major contributors are classes.dex(3MB), Dart AOT symbols(6MB) and audience_network.dex(1MB).
The same applicative using native android can be built in just 4-5MB
Here are the results of --analyze-size.
C:\Users\arunc\AndroidStudioProjects\bonaza>flutter build apk --target-platform android-arm64 --release --analyze-size
Running "flutter pub get" in miband5... 1,807ms
Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety\
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: C:\src\flutter\flutter.pub-cache\hosted\pub.dartlang.org\permission_handler-5.0.1+1\android\src\main\java\com\baseflow\permissionhandler\PermissionHandlerPlugin.java u
ses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 124.9s
√ Built build\app\outputs\flutter-apk\app-release.apk (12.5MB).
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
app-release.apk (total compressed) 13 MB
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
res/
drawable-anydpi-v21 8 KB
interpolator 1 KB
drawable-xxhdpi-v4 56 KB
drawable-hdpi-v4 33 KB
drawable 21 KB
drawable-anydpi-v24 2 KB
drawable-mdpi-v4 24 KB
color-v23 2 KB
drawable-xhdpi-v4 40 KB
drawable-ldpi-v4 6 KB
color 5 KB
mipmap-hdpi-v4 19 KB
layout 28 KB
anim 8 KB
drawable-xxxhdpi-v4 48 KB
mipmap-xxxhdpi-v4 88 KB
mipmap-xhdpi-v4 29 KB
mipmap-xxhdpi-v4 55 KB
drawable-ldrtl-xxxhdpi-v17 2 KB
mipmap-mdpi-v4 10 KB
drawable-v21 2 KB
drawable-ldrtl-xhdpi-v17 1 KB
drawable-ldrtl-xxhdpi-v17 1 KB
layout-watch-v20 1022 B
layout-v21 2 KB
META-INF/
CERT.SF 36 KB
kotlin-stdlib.kotlin_module 1 KB
MANIFEST.MF 32 KB
CERT.RSA 1 KB
assets/
flutter_assets 69 KB
audience_network.dex 1 MB
kotlin/
kotlin.kotlin_builtins 4 KB
reflect 2 KB
collections 1 KB
AndroidManifest.xml 6 KB
classes.dex 3 MB
resources.arsc 664 KB
lib/
arm64-v8a 6 MB
Dart AOT symbols accounted decompressed size 6 MB
package:flutter 3 MB
dart:core 405 KB
dart:typed_data 273 KB
dart:io 253 KB
dart:ui 215 KB
dart:async 173 KB
dart:collection 165 KB
package:miband5 152 KB
package:parse_server_sdk 122 KB
package:flutter_gen 122 KB
package:flutter_localizations 106 KB
package:flutter_cache_manager 102 KB
dart:convert 83 KB
package:sqflite_common 73 KB
package:source_span 63 KB
package:win32 53 KB
package:intl 50 KB
dart:isolate 39 KB
package:vector_math 34 KB
package:google_mobile_ads 29 KB
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
A summary of your APK analysis can be found at: C:\Users\arunc.flutter-devtools\apk-code-size-analysis_09.json
run flutter clean
run flutter pub get
run flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi
after running third commmand you'll get seprate apk's for android-arm , android-arm64 , android-x64 which reduces the apk's size.

How to set /dev/root filesystem size to the partition size

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 4.3G 1.9G 2.2G 47% /
devtmpfs 980M 0 980M 0% /dev
tmpfs 981M 0 981M 0% /dev/shm
tmpfs 981M 33M 948M 4% /run
tmpfs 981M 0 981M 0% /sys/fs/cgroup
tmpfs 981M 0 981M 0% /tmp
tmpfs 981M 16K 981M 1% /var/volatile
# fdisk -l
Disk /dev/mmcblk1: 7.3 GiB, 7818182656 bytes, 15269888 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier:
Device Start End Sectors Size Type
/dev/mmcblk1p1 16384 24575 8192 4M unknown
/dev/mmcblk1p2 24576 32767 8192 4M unknown
/dev/mmcblk1p3 32768 69859 37092 18.1M unknown
/dev/mmcblk1p4 81920 15269854 15187935 7.2G unknown
As far as I know, the /dev/root filesystem size is the size of the content that is being copied to the /dev/root.
My goal is to have /dev/root size the same as /dev/mmcblk1p4 which is 7.2G.
How can I instruct Yocto give the /dev/root filesystem the size of the partition it is mounted to?
I can see two possible solutions to your issue.
The first one is by telling Yocto to generate an image with a sepcific IMAGE_ROOTFS_SIZE value. As stated in the Yocto Mega-Manual. The size is specified in KBytes. Modify your machine.conf or local.conf to add this parameter.
In your case, the value seems to be:
15269854 - 81920 = 15187934 sectors
sectors are 512 Bytes on your system (see verification below)
15187935 * 512 = 7776222208 Bytes
7776222208 / 1024 = 7593967 KBytes
To verify the sector size of 512B:
7593967 / (1024 * 1024) = 7.242 GB
With 512 Bytes blocksize, the partition size is 7.2GB, as stated by fdisk
I think it is a good idea to reduce it a little bit, a value like 7230000 Kilobytes (~7.23 GB) can be a good candidate.
The other method is to use resize2fs program if your partition type is ext2/3/4. This program can be executed on mounted or unmounted devices. If you are using a SDcard, the simplest method will be to insert it into your computer, to unmount it, and run resize2fs /dev/<mysdcarddevice>. You can also execute it directly from your embedded board. In this case you will need to add the package e2fsprogs-resize2fs on the board with IMAGE_INSTALL += "e2fsprogs-resize2fs", then run resize2fs /dev/mmcblk1p4.
As PierreOlivier proposed I used resize2fs program.
Because I am using Yocto to build the custom image I use pkg_postinst_ontarget which runs only once at the first boot on the target machine.
In one of my recipe I put
pkg_postinst_ontarget_${PN}() {
#!/bin/bash
resize2fs /dev/mmcblk1p4
}
This resizes the selected partition on the first boot.
Thank you PierreOlivier

What do these Windbg error messages mean?

I'm trying to do a !heap -s in Windbg to get heap information. When I attempt it I get the following output:
Heap Flags Reserv Commit Virt Free List UCR Virt Lock Fast
(k) (k) (k) (k) length blocks cont. heap
-----------------------------------------------------------------------------
00000000005d0000 08000002 512 28 512 10 3 1 0 0
Error: Heap 0000000000000000 has an invalid signature eeffeeff
Front-end heap type info is not available
Front-end heap type info is not available
Virtual block: 0000000000000000 - 0000000000000000 (size 0000000000000000)
HEAP 0000000000000000 (Seg 0000000000000000) At 0000000000000000 Error: Unable to read virtual block
0000000000000000 00000000 0 0 0 0 0 0 1 0
-----------------------------------------------------------------------------
I can't find any reference as to what the unusual error/not available lines mean.
Can someone please give me a summary as to why I'm not getting an expected list of heaps?
The only thing I execute prior to !heap -s is !wow64exts.sw because the process dumps are from a 32 bit process but created by a 64 bit Task Manager.
After testing with the 32 and 64 bit Task Managers it appears that process dumps of 32 bit processes created by the 64 bit Task Manager can only be debugged successfully in some areas using !wow64exts.sw in Windbg to use 32 bit debugging.
That extension allows call stacks to be reviewed correctly, but !heap -s does not appear to work correctly under it. Instead you end up with the errors in the question.
For example, the output from a process dump of the 32 bit process using the 32 bit Task Manager:
0:000> !heap -s
NtGlobalFlag enables following debugging aids for new heaps:
stack back traces
LFH Key : 0x06b058a2
Termination on corruption : DISABLED
Heap Flags Reserv Commit Virt Free List UCR Virt Lock Fast
(k) (k) (k) (k) length blocks cont. heap
-----------------------------------------------------------------------------
031b0000 08000002 1024 236 1024 2 13 1 0 0 LFH
001d0000 08001002 1088 188 1088 18 9 2 0 0 LFH
01e30000 08001002 1088 160 1088 4 3 2 0 0 LFH
03930000 08001002 256 4 256 2 1 1 0 0
038a0000 08001002 64 16 64 13 1 1 0 0
-----------------------------------------------------------------------------
The output from a process dump of the 32 bit process using the 64 bit Task Manager without !wow64exts.sw:
0:000> !heap -s
NtGlobalFlag enables following debugging aids for new heaps:
stack back traces
LFH Key : 0x000000b406b058a2
Termination on corruption : ENABLED
Heap Flags Reserv Commit Virt Free List UCR Virt Lock Fast
(k) (k) (k) (k) length blocks cont. heap
-------------------------------------------------------------------------------------
0000000001f70000 08000002 512 28 512 10 3 1 0 0
0000000000020000 08008000 64 4 64 1 1 1 0 0
-------------------------------------------------------------------------------------
The output from a process dump of the 32 bit process using the 64 bit Task Manager with !wow64exts.sw:
0:000> !wow64exts.sw
Switched to 32bit mode
0:000:x86> !heap -s
NtGlobalFlag enables following debugging aids for new heaps:
stack back traces
LFH Key : 0x000000b406b058a2
Termination on corruption : ENABLED
Heap Flags Reserv Commit Virt Free List UCR Virt Lock Fast
(k) (k) (k) (k) length blocks cont. heap
-----------------------------------------------------------------------------
0000000001f70000 08000002 512 28 512 10 3 1 0 0
Error: Heap 0000000000000000 has an invalid signature eeffeeff
Front-end heap type info is not available
Front-end heap type info is not available
Virtual block: 0000000000000000 - 0000000000000000 (size 0000000000000000)
HEAP 0000000000000000 (Seg 0000000000000000) At 0000000000000000 Error: Unable to read virtual block
0000000000000000 00000000 0 0 0 0 0 0 1 0
-----------------------------------------------------------------------------
Those were all taken from the same process.

Comprehensive methods of viewing memory usage on Solaris [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
On Linux, the "top" command shows a detailed but high level overview of your memory usage, showing:
Total Memory, Used Memory, Free Memory, Buffer Usage, Cache Usage, Swap size and Swap Usage.
My question is, what commands are available to show these memory usage figures in a clear and simple way? Bonus points if they're present in the "Core" install of Solaris. 'sar' doesn't count :)
Here are the basics. I'm not sure that any of these count as "clear and simple" though.
ps(1)
For process-level view:
$ ps -opid,vsz,rss,osz,args
PID VSZ RSS SZ COMMAND
1831 1776 1008 222 ps -opid,vsz,rss,osz,args
1782 3464 2504 433 -bash
$
vsz/VSZ: total virtual process size (kb)
rss/RSS: resident set size (kb, may be inaccurate(!), see man)
osz/SZ: total size in memory (pages)
To compute byte size from pages:
$ sz_pages=$(ps -o osz -p $pid | grep -v SZ )
$ sz_bytes=$(( $sz_pages * $(pagesize) ))
$ sz_mbytes=$(( $sz_bytes / ( 1024 * 1024 ) ))
$ echo "$pid OSZ=$sz_mbytes MB"
vmstat(1M)
$ vmstat 5 5
kthr memory page disk faults cpu
r b w swap free re mf pi po fr de sr rm s3 -- -- in sy cs us sy id
0 0 0 535832 219880 1 2 0 0 0 0 0 -0 0 0 0 402 19 97 0 1 99
0 0 0 514376 203648 1 4 0 0 0 0 0 0 0 0 0 402 19 96 0 1 99
^C
prstat(1M)
PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP
1852 martin 4840K 3600K cpu0 59 0 0:00:00 0.3% prstat/1
1780 martin 9384K 2920K sleep 59 0 0:00:00 0.0% sshd/1
...
swap(1)
"Long listing" and "summary" modes:
$ swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 256,1 16 1048560 1048560
$ swap -s
total: 42352k bytes allocated + 20192k reserved = 62544k used, 607672k available
$
top(1)
An older version (3.51) is available on the Solaris companion CD from Sun, with the disclaimer that this is "Community (not Sun) supported".
More recent binary packages available from sunfreeware.com or blastwave.org.
load averages: 0.02, 0.00, 0.00; up 2+12:31:38 08:53:58
31 processes: 30 sleeping, 1 on cpu
CPU states: 98.0% idle, 0.0% user, 2.0% kernel, 0.0% iowait, 0.0% swap
Memory: 1024M phys mem, 197M free mem, 512M total swap, 512M free swap
PID USERNAME LWP PRI NICE SIZE RES STATE TIME CPU COMMAND
1898 martin 1 54 0 3336K 1808K cpu 0:00 0.96% top
7 root 11 59 0 10M 7912K sleep 0:09 0.02% svc.startd
sar(1M)
And just what's wrong with sar? :)
# echo ::memstat | mdb -k
Page Summary Pages MB %Tot
------------ ---------------- ---------------- ----
Kernel 7308 57 23%
Anon 9055 70 29%
Exec and libs 1968 15 6%
Page cache 2224 17 7%
Free (cachelist) 6470 50 20%
Free (freelist) 4641 36 15%
Total 31666 247
Physical 31256 244
"top" is usually available on Solaris.
If not then revert to "vmstat" which is available on most UNIX system.
It should look something like this (from an AIX box)
vmstat
System configuration: lcpu=4 mem=12288MB ent=2.00
kthr memory page faults cpu
----- ----------- ------------------------ ------------ -----------------------
r b avm fre re pi po fr sr cy in sy cs us sy id wa pc ec
2 1 1614644 585722 0 0 1 22 104 0 808 29047 2767 12 8 77 3 0.45 22.3
the colums "avm" and "fre" tell you the total memory and free memery.
a "man vmstat" should get you the gory details.
Top can be compiled from sources or downloaded from sunfreeware.com. As previously posted, vmstat is available (I believe it's in the core install?).
The command free is nice. Takes a short while to understand the "+/- buffers/cache", but the idea is that cache and buffers doesn't really count when evaluating "free", as it can be dumped right away. Therefore, to see how much free (and used) memory you have, you need to remove the cache/buffer usage - which is conveniently done for you.