Archive for October 2008

It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections .

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”.


A bitwise AND takes two binary representations of equal length and performs the logical AND operation on each pair of corresponding bits. In each pair, the result is 1 if the first bit is 1 AND the second bit is 1. Otherwise, the result is 0. For example:

AND 0011
= 0001


A bitwise exclusive or takes two bit patterns of equal length and performs the logical XOR operation on each pair of corresponding bits. The result in each position is 1 if the two bits are different, and 0 if they are the same. For example:

XOR 0011
= 0110

In Java, all integer types are signed, and the “<<” and “>>” operators perform arithmetic shifts. Java adds the operator “>>>” to perform logical right shifts, but since the logical and arithmetic left-shift operations are identical, there is no “<<<” operator in Java. These general rules are affected in several ways by the default type promotions; for example, since the eight-bit type byte is promoted to int in shift-expressions,[2] the expression “b >>> 2” effectively performs an arithmetic shift of the byte value b instead of a logical shift. Such effects can be mitigated by judicious use of casts or bitmasks; for example, “(b & 0xFF) >>> 2” effectively results in a logical shift.

<TAG\b[^>]*>(.*?)</TAG> matches the opening and closing pair of a specific HTML tag. Anything between the tags is captured into the first backreference. The question mark in the regex makes the star lazy, to make sure it stops before the first closing tag rather than before the last, like a greedy star would do.