Is a certain process running your CPU right into the ground? How do you find said process without picking your way through the ps aux results? With this command:
ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'
…at which point you can kill it with sudo kill -9.
Procedure to add a swap file
You need to use dd command to create swapfile. Next you need to use mkswap command to set up a Linux swap area on a device or in a file.
a) Login as the root user
b) Type following command to create 512MB swap file (1024 * 512MB = 524288 block size):
# dd if=/dev/zero of=/swapfile1 bs=1024 count=524288
c) Set up a Linux swap area:
# mkswap /swapfile1
d) Activate /swapfile1 swap space immediately:
# swapon /swapfile1
e) To activate /swapfile1 after Linux system reboot, add entry to /etc/fstab file. Open this file using text editor such as vi:
# vi /etc/fstab
Append following line:
/swapfile1 swap swap defaults 0 0
So next time Linux comes up after reboot, it enables the new swap file for you automatically.
g) How do I verify swap is activated or not?
Simply use free command:
$ free -m
vi first edit source file
then move your cursor to start of selection
ma mark current position with letter a
then move your cursor to end of selection
y'a yank to buffer x from current position to mark a
:e other edit target file
move cursor to where you want the data
p put from buffer x
To copy a block of text between files execute the commands:
| Command |
Explaination |
| 1. |
|
Edit the file containing the text you want to copy. |
| 2. |
|
Go to the top line to be copied. |
| 3. |
ma |
Mark this line as mark “a”. |
| 4. |
|
Go to the bottom line to be copied |
| 5. |
y'a |
Yank (y) the text from the current cursor location to the mark “a” ('a) |
| 6. |
:split second-file |
Open another window containing the second file. (This the file in which the text is to be inserted.) |
| 7. |
|
Go to the line where the insert is to occur. The text will be place after this line. |
| 8. |
p |
Put the text after the cursor. |
strace -q -f -c -p
strace -f verbose=all -e write=all -o /tmp/strace.log -p [pid]
strace -T -t -q -f -e trace=file,open,close,read -o /tmp/prod.strace.log -p <oms or ui pid>
-f traces all child processes as they are created byt he currently traced process as a result of the fork() system call.
-e is a qualifying expression which modifies which events to trace or how to race them
verbose=all dereferences structures for all system calls
write=all performs a full hexadecimal and ASCII dump of all the data written to all file descriptors
-o output file
-p process id to trace
Replace -p [pid] with [command] to trace a specific command.
Kernels 2.6.16 and newer provide a mechanism to have the kernel drop the page cache and/or inode and dentry caches on command, which can help free up a lot of memory. Now you can throw away that script that allocated a ton of memory just to get rid of the cache…
To use /proc/sys/vm/drop_caches, just echo a number to it.
To free pagecache:
# echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
# echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
echo 3 > /proc/sys/vm/drop_caches
As this is a non-destructive operation and dirty objects are not freeable, the user should run “sync” first!
tmpfs is supported by the Linux kernel from version 2.4 and up. tmpfs (previously known as shmfs) distinguishes itself from the Linux ramdisk device by allocating memory dynamically and by allowing less-used pages to be moved onto swap space. RAMFS, in contrast, does not make use of virtual memory (which can be an advantage or disadvantage). In addition, MFS and some older versions of ramfs did not grow and shrink dynamically and instead used a fixed amount of memory at all times.
Usage of tmpfs for example is “mount -t tmpfs -o size=1G,nr_inodes=10k,mode=0700 tmpfs /space” which will allow up to 1 GiB in RAM/swap with 10240 inodes and only accessible by the owner of the directory /space. The filesystem’s maximum size can also be changed on-the-fly, like “mount -o remount,size=2G /space”.
As performance engineer I come across various problems.� Here is one when the server crashed due to lack of free memory. See the error here.
Read more…