Saturday, April 24, 2010

VIRT = SWAP + RES

While investigating some performance problem, I've faced the need to understand exactly what is the memory consumption of process on linux server.
While looking to be simple, it takes a while to figure out how different statistics are calculated.

The first tool to use, is of course, top command.
One should remember that not all flags are enabled by default. So, for example, to enable SWAP statistics, one should run top, press 'f' in order to mark needed fields, then press 'p' and enter.

For user space process, next formula is useful: VIRT = SWAP + RES, means total amount of memory used by process consists of amount of physical memory + amount of swapped memory.
% MEM shows percentage of RES relatively to Mem - total amount of physical memory, not including swap.

Thrashing and paging could be traced through nFLT and nDRT fields of top.

Full report about memory used by process and by included shared libraries one can get using pmam -x `pidof my_process`

Swap can be disabled by commenting out swap line in /etc/fstab file

Useful links:

Good description of top:
http://www.linuxforums.org/articles/using-top-more-efficiently_89.html

Article about pmap:
http://www.cyberciti.biz/tips/howto-find-memory-used-by-program.html

Wednesday, April 14, 2010

Saturday, March 6, 2010

How to configure BGP IPv6

In this chapter I will describe how to configure BGP router on Ubuntu with IPv6 support.
1. Install last version of quagga routing daemon via Synaptic Package Manager.
2. Enable BGP support in quagga:
gedit /etc/quagga/daemons
change bgpd value to 'yes'
bgpd=yes
3. Configure BGP protocol:
4. Restart quagga daemon:
/etc/init.d/quagga restart

Saturday, January 30, 2010

How to configure IPv6 tunnel

Here I will show several methods to configure IPv6 tunnel on Ubuntu machine.

Miredo

The first and the easiest one is to use miredo tool that uses teredo tunneling protocol (RFC 4380).This method works for NATed machines and doesn't require configuration of routers.
Go to System->Administration->Synaptic Packet Manager, search for miredo and install the product. After installation, service should be started automatically. You can use service commands to start/stop it:
service miredo start
service miredo stop

New interface called teredo was created.

teredo Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet6 addr: fe80::ffff:ffff:ffff/64 Scope:Link
inet6 addr: 2001:0:53aa:64c:8e1:636f:b04b:f84d/32 Scope:Global
UP POINTOPOINT RUNNING NOARP MTU:1280 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:0 (0.0 B) TX bytes:96 (96.0 B)

To check that it works:
ping6 ::1 - ping loopback device
ping6 -I teredo fe80::ffff:ffff:ffff - IPv6 address starting with fe80, it's and address of local link, usually derived from MAC
ping6 2001:0:53aa:64c:8e1:636f:b04b:f84d
ping6 ipv6.google.com

ip -6 route - check routing table

Withdraws : teredo allows to have only /128 connection, means to subnet can be created on client side, but single peers only.

Hurricane Electric
Hurricane Electric is an IPv6 broker, offerring IPv6 subnets and IPv6 BGP service as well. First of all it needs to registrate and create account on their site.
I have Sofaware / Check Point router that connects to the internet via ADSL, means there is automatic NAT on all outbound connections. When creating the tunnel on HE site, you need to provide the dynamic IP that router receives as IPv4 client endpoint. Current router's IPV4 address can be checked by services like myIP. IPv4 server endpoint address and IPv6 addresses will be provided automatically when tunnel is created.
To configure tunnel interface, script provided on HE page can be used. The address of IPv4 end point should be local address of the machine and not the router. I use this script to confgire he-ipv6 interface.

#!/bin/bash

# Server's IPv4 IP
ipv4s=216.66.80.26

# Client IPv4 - local
ipv4c=192.168.7.144

# Server's side of point-to-point /64 allocation
ipv6s=2001:470:1f08:6fd::1/64

# User's side of point-to-point /64 allocation
ipv6c=2001:470:1f08:6fd::2/64

echo "Configuring HE connection"
echo "Tunnel on HE site must be configured with updated router IP"
echo "Router should be configured to forward protocol 41 to local IP"
echo "Server IPv4 IP: $ipv4s"
echo "Client IPv4 IP: $ipv4c"
echo "Server IPv4 IP: $ipv6s"
echo "Client IPv4 IP: $ipv6c"

ip tunnel add he-ipv6 mode sit remote $ipv4s local $ipv4c ttl 255
ip link set he-ipv6 up
ip -6 addr add $ipv6c dev he-ipv6
ip -6 route add ::/0 dev he-ipv6

The last step is to configure protocol 41 forwarding on the router. HE uses 6to4 incapsulation.
In Sofaware / Check Point router WebUI, go to Security->Rules.
Press Add Rule button in order to add new rule. The rule should Allow and Forward protocol 41 destinated to the router IP to the machine where he-ipv6 is configured.

Final check - ping6 ipv6.google.com

Saturday, July 19, 2008

Compiling SWT application into native Windows executable

Investigating cross-platform development options, I found that Java can be a nice option for cross-platform GUI. Especially, I liked the idea of SWT, which is based on native graphic libraries, GTK for Linux and MFC for windows.
And what is indeed cool - SWT application can be compiled into native executable by gcj compiler.
I did it for my Eclipse-written SWT application.

There are few steps to perform it (I did in on Windows in MinGW environment)
1. Install suitable GCJ distribution - I used ThisIsCool distribution built especially for MinGW,
but any other can be used as well
2. Recompile SWT libraries - actually what we need is to receive libswt.a library for static linking. One can use already compiled library, but if doesn't match swt version you use, you can face some troubles with GUI look.
3. Unzip the jar file your Eclipse uses into some directory. All you need here is the java .class files
4. Run the next script, that will build object files from each class file and pack it into libswt.a library

#!/bin/sh
SWT_CLASSES=`find . -name "*.class" -print sed 's/^\.\///'`

for i in $SWT_CLASSES
do
OBJ_FILE=`echo $i sed 's/\//_/g' sed 's/\.class$/\.o/'`
echo Compiling $i to $OBJ_FILE gcj -fjni -g0 -c -o $OBJ_FILE $i
done

gcj -c --resource=org.eclipse.swt.internal.SWTMessages \ -o SWTMessages.o org/eclipse/swt/internal/SWTMessages.properties

echo Creating libswt.a
OBJ_FILES=`ls *.o`
for i in $OBJ_FILES
do ar rvs libswt.a $i
done
ranlib libswt.a
echo Done.
5. Now go to the directory your application java class is placed, copy there libswt.a, swt.jar and swt-win32-xxxx.dll
6. Compile the executable file - assume your class is named Moca_VE.java:
i686-pc-mingw32-gcj -fjni --main=Moca_VE -s --classpath swt.jar -o Moca_VE.exe Moca_VE.java -s -L. -Wl,--no-whole-archive -lswt -mwindows