Search This Blog

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

2015-01-20

Linux Out Of Memory Management (Killer)

A summary of what an out of memory condition is is as follows:
  • Linux over allocates memory to processes VSZ giving them more than what they need.
  • It overcommits this memory allowing a larger VSZ than total memory availble
  • This generally isnt a problem since linux doesnt generally use up all the allocated memory
  • If processes actually require more memory than is available (due to their over allocation) it will kill "unimportant" processes to free memory and keep the system running

The messages for OOM killer can be found in:
/var/log/messages
Normally with the following keywords:
Out of Memory: Killed process

There are methods to mitigate the actions of OOM killer to prevent it from killing certain processes which can be found: http://unix.stackexchange.com/questions/136291/will-linux-start-killing-my-processes-without-asking-me-if-memory-gets-short/136294#136294 and here http://www.oracle.com/technetwork/articles/servers-storage-dev/oom-killer-1911807.html

The OOM calculator calculates using the following method: http://unix.stackexchange.com/questions/153585/how-oom-killer-decides-which-process-to-kill-first

References:
http://en.wikipedia.org/wiki/Out_of_memory

Memory Management In Linux

Using ps we can find out how much memory is allocated to a process (VSZ) and how much memory a process is actually using (RSS)

ps -e -o pid,vsz,rss,comm= | sort -n -k 2

The above will show you the process id, how much memory is allocated to a process, how much the process is actually using, and a comment of process description. It will then sort by how much memory is allocated to a process for you to see which apps are using up a lot of VSS.

Long running processes are useful to know as well when looking for memory hungry apps that have been running a long time

ps -ef --sort=start_time


References:
http://linuxconfig.org/ps-output-difference-between-vsz-vs-rss-memory-usage
http://serverfault.com/questions/27887/how-to-sort-ps-output-by-process-start-time
http://linuxcommando.blogspot.ca/2008/09/how-to-get-process-start-date-and-time.html

2014-08-25

Splitting and Combining Files

It's a fairly common scenario that you may have files larger than the existing storage medium you have. So you can buy multiple storage items, but you'll need to split the file out into smaller chunks to be able to store it in multiple locations. How do you do this? In linux it's fairly easy using the split utility. You can even recombine and split in windows fairly easily.

The initial split is done using the split command as follows:
split -b 1024m file file.part-
Where -b is the block size you want to split by. In this example 1GB.
file is the original file you want to split
file_ is the prefix you would like to use.

When running the split command the files it will create will be of the format
file.part-aa
file.part-ab
file.part-ac
etc.
As defined by the prefix above.

To recombine these files you can use cat in linux to concatenate the existing files.
cat file-part-* > file

In windows you can use the copy command
copy /b file.part-aa + file.part-ab + file.part-ac + file.part-ad file

I'm unsure of how to specify regex for the copy command in windows but this is a quick and dirty way to get it done and you could always generate a list of files and manually script it together.

You can also pipe the output of gzip into split to compress the archive but you will probably have additional overhead of decompression, and if you don't care so much about space savings split is probably going to be quicker.

An alternate way of doing this would be to use the dd utility:

Example file
tmp
contents:
cat tmp
a
b
c
d

Sizing details (in bytes):
ls -ls tmp
0 -rw-r--r--  1 bnold  domusers  8 Aug 25 15:20 tmp

wc -c tmp
       8 tmp

Split
dd if=tmp of=tmp.part1 bs=1 count=4 
dd if=tmp of=tmp.part2 bs=1 count=4 skip=4

Restore
dd if=tmp.part1 of=tmp_new bs=1 count=4
dd if=tmp.part2 of=tmp_new bs=1 count=4 seek=4

Contents of restored file:
cat tmp_new
a
b
c
d

Size of restored file:
ls -ls tmp_new
0 -rw-r--r--  1 bnold  domusers  8 Aug 25 15:44 tmp_new

wc -c tmp
       8 tmp

Validating integrity:
md5 tmp
MD5 (tmp) = 47ece2e49e5c0333677fc34e044d8257
md5 tmp_new
MD5 (tmp_new) = 47ece2e49e5c0333677fc34e044d8257
Hashes match, we're good.
References:
http://www.linuxquestions.org/linux/answers/applications_gui_multimedia/splitting_and_merging_files_using_dd
http://en.wikipedia.org/wiki/Split_%28Unix%29
http://stackoverflow.com/questions/1120095/split-files-using-tar-gz-zip-or-bzip2
http://linuxpoison.blogspot.ca/2008/09/split-and-merge-large-files.html
http://serverfault.com/questions/86808/break-up-a-dd-image-into-multiple-files

2013-12-10

Change TTYs In Linux To Debug

I have found this useful while doing a kickstart install. Being able to change your terminal when an irrecoverable error shows up is very useful.

The way to get to other terminal types is to use a combination of: Ctrl+Alt+F-key

Here's the functions of some of them:
Ctrl+Alt-F1 - The installation dialog when using text or cmdline 
Ctrl+Alt-F2 - A shell prompt
Ctrl+Alt-F3 - The install log displaying messages from install program
Ctrl+Alt-F4 - The system log displaying messages from kernel, etc.
Ctrl+Alt-F5 - All other messages 
Ctrl+Alt-F7 - The installation dialog when using the graphical installer 

2013-07-10

Testing MTU

MTU (Maximum Transmission Unit) is the maximum effective size of a PDU (Protocol Data Unit) that can be transmitted onwards by a layer.

These configuration maximums may need to differ to accommodate different traffic types. They may need to be increased or decreased depending on whether you have configured VPN and require additional header area to transmit data as your WAN link may be configured for 1500 MTU and your VPN may require an extra 8 bytes of data to package your VPN frames. If this is the case you may need to decrease your MTU to 1492.

An easy way to test to test and validate your MTU sizes is by using a simple ping with the DF (do not fragment bit).

Windows:
The following will send a frame with a size of 1500 bytes (using -l) and will tell windows not to fragment the packet (-f do not fragment)
C:\Users\user>ping $hostname -l 1500 -f

Pinging $hostname [$ip_address] with 1500 bytes of data:
Packet needs to be fragmented but DF set.
Packet needs to be fragmented but DF set.
Packet needs to be fragmented but DF set.

Ping statistics for $ip_address:
    Packets: Sent = 3, Received = 0, Lost = 3 (100% loss),
Control-C
^C

Linux:
This will do the same as the windows command (-M do will tell Linux to not fragment) it only does one attempt to prevent spam (-c 1) and will send with a size of 1500 bytes (-s 1500)
# ping -s 1500 -M do $hostname -c 1
PING $hostname ($ip_address) 1500(1528) bytes of data.
From TPC-F3-05.phaedrus.sandvine.com ($ip_address) icmp_seq=1 Frag needed and DF set (mtu = 1500

--- $hostname ping statistics ---
0 packets transmitted, 0 received, +1 errors

FreeBSD:
FreeBSD ping with no fragment (-D) and a size of 1500 bytes (-s 1500)
sudo ping -D -s 1500 $hostname
PING $hosntmae ($ip_address): 1500 data bytes
ping: sendto: Message too long
ping: sendto: Message too long
ping: sendto: Message too long


Here's some commonly known and referenced MTU sizes
1500 The biggest-sized IP packet that can normally traverse the Internet without getting fragmented. Typical MTU for non-PPPoE, non-VPN connections. 
1492 The maximum MTU recommended for Internet PPPoE implementations. 
1472 The maximum ping data payload before fragmentation errors are received on non-PPPoE, non-VPN connections. 
1460 TCP Data size (MSS) when MTU is 1500 and not using PPPoE. 
 
1464 The maximum ping data payload before fragmentation errors are received when using a PPPoE-connected machine. 
1452 TCP Data size (MSS) when MTU is 1492 and using PPPoE. 
576 Typically recommended as the MTU for dial-up type applications, leaving 536 bytes of TCP data. 
48 The sum of IP, TCP and PPPoE headers. 
40 The sum of IP and TCP headers. 
28 The sum of IP and ICMP headers. 

http://en.wikipedia.org/wiki/Maximum_transmission_unit
http://www.dslreports.com/faq/695

2011-05-01

dd Progress

Quick Tip for checking the progress for dd

When you dd is running, open up a new terminal, and run:

ps -aux

to find the process ID (PID) of your dd command, which should be near the bottom. Then use the command:

kill -USR1

which will send show the progress message in your dd window.