Wednesday, April 15, 2015

How Linux Memory is Managed - Part 1

To make virtual memory concept simple, we need to remember few basic ground rules.

1. Linux visualizes its physical resource of memory
2. Process never ever directly address physical memory.
3. Instead Kernel associates each process with unique address space.

Memory Management happens in Linux using Page and Paging.

Kernel allocates unique Virtual Address Space to each Process. This Virtual Address Space is composed of Pages.

Two type of Pages we have
1. Valid  Page : Its associated with Physical Page or Secondary storage like disk.
2. Invalid Page : Its unused, unallocated piece of  Address space.

A program cannot use a page in secondary storage. It can use the page if it is associate with a page in physical memory.

Program -> Tries to access a Page on Secondary Storage -> MMU  generate Page fault->  Kernel does Page-in the desired page from secondary storage to Physical memory.

Imagine a Process tries to access a page on secondary storage. 

Since the page is not present, page fault occurs.

The Kernel intervenes and does Page-in the desired page to Physical memory from Secondary storage.


Interrupts and Interrupt handlers

If you are an embedded engineer, you might be dealing with interrupts in your daily work. Though its simple concept, its thought complex.

To put them in layman words, interrupts allow hardware to communicate with processor which in turn informs the Operating System to perform certain task.

Harware -> Interrupt -> Interrupt controller -> Processor -> Operating System ->  Serve Interrupt. 

Interrupt is physically produced by the hardware and directed into input pins on an Interrupt controller.

Once the interrupt is directed towards Interrupt controller, it informs the Processor.

Processor then notifies the underlying Operating System to handle the interrupt appropriately.

Operating system serves each Interrupt with unique handler and distinguishes each interrupt with its unique id.

Just remember above sequence, and it will help you during technical discussions.

Saturday, April 11, 2015

How to configure vi/vim for coding C - Indentation and file detection

How do we make vi-Vim not to use tab and use 4 spaces instead ?
How to make it  automatically indent code after curly brace blocks like Emacs does?
How to save these settings so that we never have to input them again?

I've seen other questions very often from vi/vim users.
 
Its pretty simple, add below lines to your .vimrc file under your home directory.

 filetype plugin indent on  
 set tabstop=4  
 set shiftwidth=4  
 set expandtab  

More information under :  filetype

Wednesday, April 8, 2015

Missing side bar, Missing Menu bar , Missing icons and Missing "close resize and minimize icons" in Ubuntu 14.04 64bit LTS

This issue was a nightmare. I have tried various solutions to solve this issue but nothing worked. I tried reinstalling unity, resetting unity, reinstalling compiz packages etc and ended up without solving the issue.

Many solutions available in net are for 12.04 , 12.10 etc versions but not for Ubuntu 14.04 64 bit version.

Before trying this solution, make sure you have taken backup of your valuable data. I didn't loose any data but on safe side, its always good to take backup before trying which we are not sure about it.

To solve this issue just change your directory to your home directory.

Press Ctrl+Alt+F1 , enter your username and password.

 cd <home-directory>  
 sudo rm -rf .config  
 sudo rm -rf .compiz/compiz-1  

That's it, reboot the machine and now you should see icons back on the screen :)

Thursday, March 19, 2015

Remove all files in a directory except one or two

In Linux, have you ever wondered what is the command to execute in terminal to delete all files in a directory except one or two ? Its,

 find ! -name 'file.txt' -type f -exec rm -f {} +  
 
This command will remove all files except file.txt.

To remove directory, change type -f to type -d and add -r option to rm as below.

 find ! -name 'file.txt' -type d-exec rm -rf {} +  

Please becareful before executing command. If you accidentally type in an important folder, you may loose all contents.

Always try to understand to learn about each term before executing it :).

How to open chm files in Ubuntu 14.04. Which package to install.

I have been searching for package(s) to install to open chm files. Below command worked like magic.

 sudo apt-get install xchm  

While install press Y. After installation,click on any  *.chm file it will open automatically.

Sunday, March 1, 2015

Building Kernel Source

This article just briefs about downloading and installing Linux Kernel Source.
Of-course, there are many articles available in net. I would like to make this as simple as possible.

Steps to follow

1. Install Git
 sudo apt-get install git  

2. Download Linux Source (in here I am downloading 2.6 version) in to a directory
 $ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git 
 $ git pull 

3.Configure your Kernel by executing
 $make defconfig  
 $make oldconfig  

Some times, we can use "$make  menuconfig" a graphic utility to configure Kernel. You may face fatal error problem while executing this command.

4.Now build your kernel
 $make  

This may take a while. So relax, we have done a lot till now :)

To improve Kernel build time you can use
 $make  -jn

Here, n is the number of jobs to spawn. Usual practice is to spawn one or two jobs per processor. For example, on a 16-core machine, you might do
$ make -j32 > /dev/null

Using utilities such as the excellent distcc or kernel build time. ccache
can also dramatically improve  Kernel build time.

5. Now once the build is done, we need to find for bzImage
 mrtechpathi@mrtechpathi:~/Study/linux-source/linux-2.6$ find . -name bzImage |xargs ls -l  
 lrwxrwxrwx 1 mrtechpathi mrtechpathi   22 Mar 1 23:16 ./arch/x86_64/boot/bzImage -> ../../x86/boot/bzImage  
 -rw-rw-r-- 1 mrtechpathi mrtechpathi 5970016 Mar 1 23:16 ./arch/x86/boot/bzImage  

6.Copy this image to /boot directory as vmlinuz-2.6
 mrtechpathi@mrtechpathi:~/Study/linux-source/linux-2.6$ sudo cp ./arch/x86/boot/bzImage /boot/vmlinuz-2.6  

7.Install modules
$ sudo make modules_install

8.Now update grub using
$ sudo update-grub

Sometimes,  your grub may disappear or may not appear. To solve this check this post "Grub menu is not displayed after installing Linux".