Monday, April 30, 2012

How to find the upstream website of a package in Fedora or any other rpm based linux distribution?

What is upstream in opensource?
Package maintainers in linux distributions like Fedora would build and submit rpm packages of any opensource software which they think would be useful to be included in Fedora. The people who originally created the software is called upstream.

How to see upstream website url?
The website url of the upstream software maintainer is included in the rpm spec file. The url can be seen in the output of 'rpm -qi command'. For example, to see the upstream url of vpnc rpm package.

$ rpm -qi vpnc|grep URL
URL         : http://www.unix-ag.uni-kl.de/~massar/vpnc/




Friday, September 10, 2010

Why dmesg is showing write through when the disk connected to Adaptec AAC-RAID is set to write back as per Adaptec Storage Manager?

dmesg command is showing following output.

Vendor: Adaptec Model: Data Rev: V1.0
Type: Direct-Access ANSI SCSI revision: 02
sdb : very big device. try to use READ CAPACITY(16).
SCSI device sdb: 9762222080 512-byte hdwr sectors (4998258 MB)
sdb: Write Protect is off
sdb: Mode Sense: 06 00 10 00
SCSI device sdb: drive cache: write through w/ FUA
sdb : very big device. try to use READ CAPACITY(16).
SCSI device sdb: 9762222080 512-byte hdwr sectors (4998258 MB)
sdb: Write Protect is off
sdb: Mode Sense: 06 00 10 00
SCSI device sdb: drive cache: write through w/ FUA
sdb: sdb1
sd 0:0:1:0: Attached scsi removable disk sdb

This is expected behavior.

What the aacraid driver reports is independent of the firmware settings configured by the storage manager. Instead, the write back configuration the aacraid driver reports is controlled the variable aac_cache (which can be set by a module parameter named cache).

From drivers/scsi/aacraid/aachba.c:

static int aac_cache = 2; /* WCE=0 to avoid performance problems */

...

module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
"\tbit 0 - Disable FUA in WRITE SCSI commands\n"
"\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
"\tbit 2 - Disable only if Battery is protecting Cache");


With the default value of 2, aacraid always reports disks as being in write through mode.

Wednesday, August 4, 2010

Windows telnet client displays garbage characters when connected to Red Hat Enterprise Linux

When user connects to Red Hat Enterprise Linux Server 5 using Windows telnet client, and compiles C programs, junk or garbage characters are displayed.

[test@test ~]$ gcc test.c   
test1.c: In function ΓÇÿmainΓÇÖ:

When one connects via telnet from a Windows system to Red Hat Enterprise Linux 5 system, the telnet client uses the character encoding from Windows. This results in the strange characters. Windows does not use utf-8 character encoding like RHEL.




Using putty on Windows as the telnet client solves the issue. In putty, go to Translation -- > change 'ISO-8859-1:1998 (Latin-1, West Europe)' to UTF-8 and then connect .



Wednesday, July 28, 2010

How to stop the flushing of mmaped pages to disk in RHEL5.2 and later?

If your application is mmapping too much memory, resulting in lots of pdflush write activity and thereby by affecting system performance, vm.flush_mmap_pages kernel parameter could be useful.

/proc/sys/vm/flush_mmap_pages is introduced in RHEL5.2 kernel.

Setting /proc/sys/vm/flush_mmap_pages to 0 will stop the flushing of dirty memory-mapped file pages to disk as long as the memory map is active.

All dirty file pages will be asynchronously flushed to disk only as soon as the memory map is deactivated.





Added a new kernel parameter: /proc/sys/vm/flush_mmap_pages. This parameter specifies whether or not memory-mapped file pages should be flushed to disk by kupdate while the memory map is active. Valid values for this parameter are 1 (enable memory mapping by kupdate) and 0 (disable memory mapping by kupdate). The default value for this parameter is 1.

To configure this parameter, use echo [1 or 0] /proc/sys/vm/flush_mmap_pages. Setting this parameter to 0 does the following:

kupdate will not flush dirty memory-mapped file pages as long as the memory map is active.

All dirty file pages will be asynchronously flushed to disk only as soon as the memory map is deactivated.

If you set /proc/sys/vm/flush_mmap_pages to 0, it is advisable that you use another application to manually sync memory-mapped pages to disk.

Friday, June 11, 2010

byobu - new funky wrapper for screen command

screen command was always been a very helpful tool for system admins.

byobu is a wrapper script over screen.

Best part is that it looks good.

You can also configure status notifications which will be displayed in the bottom screen. This is useful in monitoring the system while working in the terminal.

In Fedora, you can install byobu using following command.
# yum install byobu

Some useful shortcuts from man byobu

F2 - Create a new window

F3 - Move to previous window

F4 - Move to next window

F5 - Reload profile

F6 - Detach from this session

F7 - Enter copy/scrollback mode

F8 - Re-title a window

F9 - Configuration Menu

F12 - Lock this terminal
Run 'byobu' command to start the script.

Thursday, May 27, 2010

How do you find out which cpu a process is running on?

The output of the ps command can be changed to a user defined format by using the -o option.

The following command can be used to display the CPU and the processes assigned.

# ps -eo pid,args,psr

Options:

pid - The process ID of the process.

args - Command with all its arguments as a string.

psr - processor currently assigned to the process.

Go to the man pages for more information on the ps command.

What is the logic behind killing processes during an Out of Memory situation?

As per kernel source code, following is OOM-killer logic,

A function called badness() is defined to calculate points for each processes.

* Points will be added to following processes.

Processes with high memory size.
Niced processes.

* Points will be reduced from following processes.

Processes which were running for long time.
Processes which were started by superusers.
Process with direct hardware access.

The process with the highest number of point, will be killed, unless it is already in the midst of freeing up memory on its own.

Then the system will wait for sometime to see if enough memory is freed. If enough memory is not freed after killing one process, the above steps will continue.

As per select_bad_process function, if a processes is having 0 or less points it could not be killed. The oom kills will be continued until there is no candidate processes left to kill. If the system is not able to find a candidate process to kill, it panics.

static unsigned long badness(struct task_struct *p, unsigned long uptime)
{
unsigned long points, cpu_time, run_time, s;

if (!p->mm)
return 0;

if (p->flags & PF_MEMDIE)
return 0;
/*
* The memory size of the process is the basis for the badness.
*/
points = p->mm->total_vm;

/*
* CPU time is in tens of seconds and run time is in thousands
* of seconds. There is no particular reason for this other than
* that it turned out to work very well in practice.
*/
cpu_time = (p->utime + p->stime) >> (SHIFT_HZ + 3);

if (uptime >= p->start_time.tv_sec)
run_time = (uptime - p->start_time.tv_sec) >> 10;
else
run_time = 0;

s = int_sqrt(cpu_time);
if (s)
points /= s;
s = int_sqrt(int_sqrt(run_time));
if (s)
points /= s;

/*
* Niced processes are most likely less important, so double
* their badness points.
*/
*/
if (task_nice(p) > 0)
points *= 2;

/*
* Superuser processes are usually more important, so we make it
* less likely that we kill those.
*/
if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_ADMIN) ||
p->uid == 0 || p->euid == 0)
points /= 4;

/*
* We don't want to kill a process with direct hardware access.
* Not only could that mess up the hardware, but usually users
* tend to only have this flag set on applications they think
* of as important.
*/
if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_RAWIO))
points /= 4;
#ifdef DEBUG
printk(KERN_DEBUG "OOMkill: task %d (%s) got %d points\n",
p->pid, p->comm, points);
#endif
return points;
}

What is kipmi? Why is it taking too much cpu in my Red Hat Enterprise Linux system?

If your IPMI hardware interface does not support interrupts and is a KCS or SMIC interface, the IPMI driver will start a kernel thread for the interface to help speed things up. This is a low-priority kernel thread that constantly polls the IPMI driver while an IPMI operation is in progress.

kipmi is that low-priority kernel thread. If the system does large number of IPMI operations, there is a possibility of kipmi using too much cpu time.

The kipmi thread is a workaround to fix the hardware disability so there is no real fix. Sometimes firmware updates can fix this though.

As a workaround, you can disable kipmi using following steps. This may decrease the speed of IPMI operations though.
* Edit /etc/modprobe.conf and add following entry.

options ipmi_si force_kipmid=0

* Restart the ipmi using following command.

# service ipmi restart

Wednesday, September 23, 2009

skype and twitux

Tested Skype and Twitux in my Fedora 11 X86_64 system.

Used following repo for skype..

[skype]
name=Skype Repository
baseurl=http://download.skype.com/linux/repos/fedora/updates/i586/
enabled=1
gpgkey=http://www.skype.com/products/skype/linux/rpm-public-key.asc
gpgcheck=0


Twitux is a gnome client for twitter. Simple and nice..
http://sourceforge.net/projects/twitux/
http://twitter.com

Wednesday, July 8, 2009

tape tricks

* display contents of a tape

# tar tvf /dev/tape

* tape rewind

# mt -f /dev/tape rewind

Monday, June 8, 2009

High memory utilization and cache

Many people complains about high memory utilization in the output of free command, which in most situations caused by misreading of free command.

If we are taking following free output for instance,



total used free shared buffers cached
Mem: 8054896 7193712 861184 0 188348 5286732
-/+ buffers/cache: 1718632 6336264
Swap: 2096440 144 2096296



It is seen that most of the memory in the system is used by 'cached' (5286732kb) and buffers (188348kb). The system over time increases the size of the buffers and cache in its RAM. The cache stores various pieces of data from the hard disk such as data from files. When reading from the hard disk, the kernel first looks into cache for that data. This is more efficient, as reading from memory is much faster than reading from the disk. This memory is returned whenever it is required by other programs and should be calculated as being free along with the buffers.

This is an expected behaviour by Linux kernel to speed up the system.

Memory utilization need not be an issue unless there is an Out of Memory or a performance issue.

--

In RHEL5, If cache memory need to be flushed /proc/sys/vm/drop_caches could be used.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


This could cause a hike in I/O in some situations, as kernel will try to write all data to disk.

"sync" command should be run before the above commands.

In RHEL4 /proc/sys/vm/drop_caches is introduced in 2.6.9-67* kernel.

There is also a known bug in which the system hangs when cache is flushed using drop_caches. The bug is only reproduced in large systems with at least 64GB RAM and 8 cpus. The bug is fixed in 2.6.9-78* kernel. Please refer following bugzilla.

https://bugzilla.redhat.com/show_bug.cgi?id=449381

--

Cached memory is good for most of the work loads.

If you want to specifically opt for less cache usage, increasing the value of /proc/sys/vm/swappiness could help.

For Example:

# echo 100 > /proc/sys/vm/swappiness


You can make the values persistent over reboot by adding following to /etc/sysctl.conf.

vm.swappiness=


Please remember that this will increase the usage of swap, which might affect system performance.

--

Following are some other kernel tuning parameters that helps to manage cache.

vm.dirty_expire_centisecs=2000


It determines the amount of time for a page to be considered old enough for flushing to disk via the pdflush daemon. Expressed in 100'ths of a second.

vm.dirty_writeback_centisecs=400


It determines the interval at which the pdflush daemon wakes up to write dirty data to disk.. Expressed in 100'ths of a second.


vm.dirty_background_ratio=5


It determines the percentage of total system memory at which the pdflush background writeback daemon will start writing out dirty data.


vm.dirty_ratio=20


It determines percentage of total system memory at which a process which is generating disk writes will itself start writing out dirty
data.

kernel panic on boot and lvm filters

Problem:

Updated the RHEL5 system to 2.6.18-92.1.13.e15 kernel. When he rebooted the system, system panicked with following errors.


Unable to access resume device (/dev/VolGroup00/LogVol01)
mount: could not find filesystem '/dev/root'
setuproot: moving /dev failed: No such file or directory
switchroot: mount failed: No such file or directory
Kernel panic - not syncing: Attempted to kill init!


Troubleshooting:

I saw / mounted on lvm.

/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)


But in the 'vgdisplay' command output, I was not able to see the logical volume !!!!

Interestingly following entry was in /etc/lvm/lvm.conf.

filter = [ "r/disk/", "r/sd./", "a/./" ]


The filter will exclude all /dev/disk/* and /dev/sd* devices.


Solution:

Edit /etc/lvm/lvm.conf and replace following entry

filter = [ "r/disk/", "r/sd.*/", "a/.*/" ]


with

filter = [ "a/dev/mapper/.*/", "a/dev/sda2$/", "r/.*/" ]


This filter will enable all /dev/mpath/* devices and /dev/sda2 device where the / was mounted.

* Clear /etc/lvm/.cache.

# > /etc/lvm/.cache


* Run vgscan command

# vgscan


* Reinstall the latest kernel rpm.

# rpm -e kernel-2.6.18-128.1.10.el5
# yum install kernel


After following the suggestions, the system booted fine with the new kernel.

Rebuilding the initrd would have also worked.

How can I improve the performance of the syslog daemon in Red Hat Enterprise Linux?

http://kbase.redhat.com/faq/docs/DOC-17098

Tuesday, March 10, 2009

How to enable and disable a cpu on a live Linux system?

For squeezing out a bit of extra battery time, I usually disables one of cpus of my laptop.

This option is only available from RHEL5.

I do have two cores in my system.

# grep processor /proc/cpuinfo
processor : 0
processor : 1

/sys/devices/system/cpu/cpuX/online decides if a cpu is enabled or disabled.

# cat /sys/devices/system/cpu/cpu1/online
1


To disable the cpu1:

# echo 0 > /sys/devices/system/cpu/cpu1/online


Now only one cpu is up.

# grep processor /proc/cpuinfo
processor : 0


To re-enable the cpu:

# echo 1 > /sys/devices/system/cpu/cpu1/online


I will not be able to disable cpu0. Even online file is not availabe.

# ll /sys/devices/system/cpu/cpu0/
total 0
drwxr-xr-x 5 root root 0 2009-03-10 16:50 cache
drwxr-xr-x 3 root root 0 2009-03-10 16:38 cpufreq
drwxr-xr-x 5 root root 0 2009-03-10 16:50 cpuidle
-r-------- 1 root root 4096 2009-03-10 16:50 crash_notes
drwxr-xr-x 2 root root 0 2009-03-10 16:50 topology


Some architectures (i386, X86_64) does have some special dependency on a certain CPU. I have not tested it in any other architectures.

Monday, March 9, 2009

How to create rpm packages with non stripped binaries in Red Hat Enterprise Linux?

Usually binaries are stripped of the debug information for making them compact. Non-stripped binaries are binaries which have debug information built into them. Non stripped binaries are generally build by passing -g option to gcc.

Rpms shipped with Red Hat Enterprise Linux provides stripped binaries. A separate debuginfo package is provided with all debugging information. Debuginfo rpms for Red Hat Enterprise Linux could be found in following url.

http://people.redhat.com/anderson/debuginfo.html

'file' command could tell if a binary is stripped or not.

# file /usr/bin/python
/usr/bin/python: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), stripped

Some times a non stripped binary will be useful for profiling and debugging.

Below steps could be followed to create an rpm package which provides a non stripped binary. Following is an example of building a python rpm package with non stripped binary.

1. Download the source rpm for the package from rhn.redhat.com.

2. Install the source rpm in the system with following command.

# rpm -ivh python-2.3.4-14.2.src.rpm


3. Edit /etc/rpm/macros and add following line.

%debug_package %{nil}


4. Build the rpm using rpmbuild command.

# rpmbuild -bb /usr/src/redhat/SPECS/python.spec


'-bb' option is given so that a binary package is only created. '-ba' option could build binary and source packages

Binary package will be created under /usr/src/redhat/RPMS/x86_64/

5. Now remove the current rpm with stripped binary and install the new binary rpm package win non stripped binary.

# rpm -e python --nodeps

# rpm -ivh /usr/src/redhat/RPMS/x86_64/python-2.3.4-14.2.x86_64.rpm
Preparing... ########################################### [100%]
1:python ########################################### [100%]

# file /usr/bin/python
/usr/bin/python: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), not stripped

6. For listing symbols from the non stripped binary 'nm' command could be used.

# nm /usr/bin/python


I used RHEL in this example because of familiarity. This should work with almost all rpm based operating system flavors.