Friday, April 21, 2017

Linux: Why deleting files does not free space

You are in the middle of compiling your code and you see errors:
/disk/user1/platform_dev/odfl/driver/openwrt/staging_dir_arm_platform/bin/arm-unknown-linux-uclibcgnueabi-objcopy:/disk/user1/platform_dev/odfl/driver/base/build_platform/kmod/linuxmodule/stI4AuYi: No space left on device
make[5]: *** [/disk/user1/platform_dev/odfl/driver/base/build_platform/kmod/linuxmodule/handlerproxy.o] Error 1
make[5]: *** Waiting for unfinished jobs....

So this is just like old times. You run df -h and check if you are running at disk capacity.
I find that I am at 70% disk usage but still the make process is complaining.

I decide to be conservative and free up more space on the system.
Then I see something interesting. Despite doing the rm -Rf on a couple of big chunks of data,
I do not see the free space on my system going up. 

That gets me thinking why this might be happening. The reason is that the deletes I did were through screen. And, Linux will not free up any descriptors (Inodes) as long as they are being referred through some process.

Sunday, September 18, 2016

Linux: A simple tutorial on running GDB for stack examination

Simple tutorial on examining the stack with GDB on #Linux

Saturday, August 20, 2016

Linux: Sleeping while atomic during kmalloc solved

So you ran into a crash where the kernel complains that you were sleeping while atomic.
You were either able to run objdump or gdb and track down that the crash is caused due
to a kmalloc? How is that possible?
Did you make recent changes which included putting in a kmalloc?

Typical format:
The function is declared in <linux/slab.h>:
void * kmalloc(size_t size, int flags)

This function is often used in a similar fashion:
struct packet_st *ptr;
ptr = kmalloc(sizeof(struct packet_st), GFP_KERNEL);
if (!ptr)
        /* handle error ... */

The problem is that the GFP_KERNEL has to be used in proper context. i.e. you cannot use GFP_KERNEL from IRQ context. This is because GFP_KERNEL tells the kernel that if it was not able to immediately allocate the required page, it is free to sleep. However, as we know, we are not allowed to sleep in "atomic" context. 

Hence, we need to make sure that appropriate context flag is used while requesting memory. If you are in the IRQ context, it is useful to use the GFP_ATOMIC flag instead of GFP_KERNEL. This will solve the problem of the crash.

Friday, July 15, 2016

Linux: How to tar only selected folders and files

Step 1: Select the files and prepare a list.

I do this with a simple function in my .bashrc script:

$> cat >> ~/.bashrc
99 function cscopesetup()
100 {
101     rm cscope.files;
103     echo "Populating filenames...";
104     find $SRC/folder1/ -iname "*.c" -print >> cscope.files #folder1
105     find $SRC/folder9/ -iname "*.h" -print >> cscope.files #folder9
106     echo "Driver done"
107 }


Run this from the bash command:
$> source ~/.bashrc

This will create a file on your home directory with the name cscope.files

If you open this file, you should see the names of all the files you want to tar and backup.

Step 2: Now tar the files
$> tar -cvf myfile.tar -T cscope.files

This will do it.

Wednesday, December 2, 2015

Linux: Compare if two files are the same

Quick script I wrote in my .bashrc to check if two files are the same:

function md5comp()
    a=$(md5sum $1 | awk '{print $1}')
    b=$(md5sum $2 | awk '{print $1}')
    echo "Comparing $1 and $2"
    [ "$a" = "$b" ] && echo  "Equal" || echo "Not Equal"

$ md5comp filea.txt fileb.txt
Comparing filea.txt and fileb.txt

Wednesday, November 18, 2015

Linux: Why to drop caches and how? Host or virtual machine

Excerpt from stackoverflow: "The reason to drop caches like this is for benchmarking disk performance, and is the only reason it exists. When running an I/O-intensive benchmark, you want to be sure that the various settings you try are all actually doing disk I/O, so Linux allows you to drop caches rather than do a full reboot."

How to drop caches on the host?

Monday, September 28, 2015

Google Blogger Header Image Design

Do you like our new header image on the website? If you do, you can make one for your blog too. We used a nice open source software called inkscape.

If you want to learn the ropes with inkscape, there are multiple tutorials on youtube, which are easily obtained on searching. 

I will put a gist of the steps we used to create the image you see below:
Our blog's header image

  1. Create or obtain a logo: Either use a professional service or use your ideas to create a logo for your website. This part is optional. You can create the header image without a logo although it looks better with one.