Friday, May 18, 2007

quirk of static linking

A question related to linking today.
Why is it advised to put the library options at the end of command line for compilation?

Hint: If we have a static library, say libfoo.a which we want to link to our program hello.c

cc hello.c -lfoo
rather than
cc -lfoo hello.c

-l option tells the compiler to link to library [lib]foo. Note that "lib" from libfoo is dropped and only "foo" part is given with -l.

How Nerdy are you?

Took this Nerd test and was worried I was going to score a "less nerdy" type. But the result were pleasantly surprising. It said " All hail the monstrous nerd. You are by far the SUPREME NERD GOD!!!"
Perhaps, my score was helped by a few dirty clothes in my room, and Solaris.
For now, I am in heaven!


I am nerdier than 95% of all people. Are you a nerd? Click here to find out!

Thursday, May 17, 2007

RAID Primer

Found a brief and good online paper on different types of RAID ( Redundant Array of Independent Discs ). It explains RAID concepts with a brief explanation of each type along with their pros and cons.
The paper can be read here.

Tuesday, May 15, 2007

Top 10 funniest gadgets

While surfing the net today, I stumbled upon this list of top 10 funniest gadgets.
My favorite are DVD rewinder and USB powered butt cooler. What are yours?

Microsoft threatens Linux with patents

According to a news article, Microsoft has alleged that Linux and other Open Source software violate its patents. This includes 42 by Linux kernel alone and many by OpenOffice, totalling 235 patents in all.

Looks like an open source arm-twisting effort by MS directly related to their deal with Novell last year.

More at :
CNN
CRN

Wednesday, January 3, 2007

Memory Overcommit and the OOM Killer

Linux has a feature called memory overcommit. Put simply, it means kernel allocates memory even if it doesn't have enough. This happens when a new process is created using fork(). This effectively copies the parent's address space, and so requires twice the parent process' memory once the new process (child) is created. The memory overcommit feature means that fork() always returns a success. Even if there is not enough memory to create a new child process!
The idea behind a memory overcommit feature of Linux is that the child process rarely uses all the memory allocated to it. fork() is followed by exec() which overlays the child address space with some exectutable. Once the exec() is done, the child process exits and the parent process (which goes into wait() after creation of child) resumes.
Failing to allocate enough memory when it is needed by the child results in another process being invoked. This process is called Out Of Memory (OOM) killer. The job of this process is to select a process to kill so that the memory requirements after fork() can be satisfied. Not a very desirable feature, but it is necessary to keep memory overcommit feature of Linux. This made OOM killer infamous. How to select a process to kill is tricky. It might happen that some important processes (e.g. a database) gets killed by OOM killer. Analogies like this show how serious the situation is when killer is invoked.
It seems that during 2.4, OOM killer's favourite process to kill was the Netscape browser. The browser would crash all of a sudden and you'd have no idea why.
The memory overcommit along with OOM is not an example of a good design feature, but has even made its way into AIX. With 2.6 the memory overcommit feature can be suppressed using some variables, but by default the feature is present.
Fortunately, it doesn't exist in Solaris. Solaris never used memory overcommit. First it was vfork() instead of fork() to prevent the failure of process creation. In Solaris 10, posix_spawn() is used instead of vfork() since vfork() is not MT-safe.

Sunday, December 24, 2006

Search from Firefox address bar

I've been using Google toolbar for Firefox for a long time. There is a Firefox feature which can make the use of the toolbar reduntant by doing Google search from Firefox address bar. For a single word search, Firefox takes us to the homepage of the first search result found. It is like the "I'm feeling lucky" feature of Google search. Just like the infamous "failure" or "miserable failure" and "I'm feeling lucky" combination does. But if we enter more than one word string in the Firefox address bar, it is like normal Google search, and makes installing Google toolbar unnecessary.
A cool feature of Firefox which many are not aware of.

Friday, December 22, 2006

The toilet

1- Say, there is a common toilet with many doors.
2- A person can enter from only one of these doors at any time i.e. the door to enter is fixed for him.
3- A door can be used for entry into the toilet by many persons i.e. it is a common entrance for some persons.
4- Only one person can use the toilet at a time.
5- There is a toilet supervisor whose job is to see that persons behave properly.
6- The supervisor gives each of the persons who use that toilet a number so he can recognize them when they come to use the toilet.
7-The higher the number the higher the chance of the person getting to use the toilet.
8- If a person is using the toilet and another person comes up whose number is bigger, the supervisor kicks the first person out and lets the second person to use the toilet. The kicked one get to use the toilet once the bigger number person is finished. The same fate awaits the second person if another person with even bigger number comes. In this case however, the first kicked person has to wait even longer. If the small number person is one unlucky guy he will find all persons coming with numbers bigger than his and he never gets to use the toilet or may have to wait for too long.
9- Seeing the plight of persons with small numbers the supervisor decides to help them out. He now puts a lock on each door. A person with small number now has option to lock as many doors from inside as he wants.
10- A door is open unless someone is using the toilet and has locked it from inside.
11- Any person can enter if his door is not locked and no higher number person is using the toilet. If a smaller number person is using the toilet when higher number comes and the door is not locked, the supervisor kicks the smaller person out and the higher number person uses it. The smaller person can reenter once the higher number person is done.
Now the supervisor is happy. The person who got small numbers can happily use the toilet if they lock the doors. But the person using the toilet often don't lock all the doors, so they still get kicked out by higher number person whose door they didn't lock.
This also cause another problem. Now sometimes the higher number person can't use the toilet because his door is locked by smaller number person who got kicked up by another person with a number somewhat in the middle of the other two. The highest number person should be using the toilet but the door is locked so he can't. Instead the middle person is using it. The supervisor didn't like it but he can't do anything with present rules so he does something else to help out the highest number person in such cases.
12- Now when a smaller number person goes in the toilet and locks a door, and a higher number person comes to that door, the supervisor exchanges the numbers of the two persons for the time while the small number person is using the toilet.
13- Once the person using the toilet is done, the two get their numbers back. The smaller person opens the door and comes out. And the higher number person enters the toilet.
14- If a person with a number somewhere in the middle comes before the (original) small number person finishes, he sees that a bigger number person is using the toilet since smaller and higher guys have exchanged their numbers. After the guys is done, the real higher number guy gets his number back and enters the toilet. So the middle guy has to wait for both the other two persons and gets a chance to use the toilet after them.

Now substitute the toilet with processor, supervisor with scheduler, persons with processes, and numbers with priorities. 1- to 8- describe the priority based scheduling with preemption. 8- is known as process starving. 9, 10, and 11- constitute what is known as priority inversion.
12, 13, and 14- are examples of priority inheritance.

The analogy isn't perfect though, and there might be some loopholes.

Thursday, December 21, 2006

Outstanding OpenSolaris questions by James McGovern

James left a comment to one of my earlier posts and suggested I answer some of the outstanding questions he posted on his blog sometimes back. Though I am not an authority on this, I will try to answer some of them as per my understanding. I was thinking of replying in comments section but it became too long, so here is a reply to James comment.

Hi James,
Unfortunately I have little information related to SPARC chips. It's an open architecture and anyone can see the specification and is free to implement.
I don't think Sun produces SPARC chips for appliances as they are a server-focussed company.
Maybe Fujitsu does it. I have heard of SPARC chips in some cameras, but you'd have to google search to find out more.
Regarding OpenSolaris, I believe OpenSolaris.org community is much more capable to answer those queries. e.g. I searched Xen community list there and it seems they have some working Xen code for OpenSolaris. Of course, Xen itself is not yet complete, so Xen for OpenSolaris would take time. Looking at the activity there, it seems Xen is the future of OpenSolaris virtualization.
Headless/Diskless clients under Solaris have been supported for quite sometime.
About legal implications of running OpenSolaris, I know none that exist. You are free to distribute your product with an OpenSolaris distribution as long as the existing files you have used from the community and modified are open sourced under CDDL. If you've added any new files, you are free to choose whatever license you want for your files if that license permits it. CDDL is less viral in this regard.
That's my understanding. I'd suggest to throw these questions to OpenSolaris list. They'd sure give you detailed and authentic reply.

Wednesday, December 20, 2006

Virtualization is where the action is !

Virtualization is the buzzword in the world of Operating Systems these days. Recently KVM - Kernel based Virtual Machine capability was introduced into Linux. When completed, it would make it possible to run Windows ( maybe other OS too) as a guest OS on top of Linux in the newer Intel and AMD processors that have support for virtualization.
KVM is virtualization specific to Linux. Other virtualization technologies also exist some of which like VMware are very advanced and allow many more OS's as hosts and guests.
Another virtualization technology under development is Xen which will be a real competitor of VMware as it will have support for many OS's just like VMware and can be used with older processors as well. Xen is an open source project unlike VMware which is proprietary.
Then there's hardware virtualization which allows one set of hardware to run many OS's. UltraSparc T1 aka Niagara is supposed to get Logical Domain ( LDom ) support in the near future which will allow one Niagara processor to run many different versions of Solaris OS simulaneously.
IBM and Sun have had hardware virtualization in their big iron for a long time but now even smaller machines can have it. Solaris for example allows a form of virtualization with Zones where a machine with Solaris 10 or some OpenSolaris distro can run dozens of virtualized instances of the the OS. Each Zone is a secure virtual OS instance on which applications can run which can be compromised without compromising other zones in the same system.
With all these different virtualization techniques in Unix, Linux, Mac OS X and even in Windows, user today is the king! What was unthinkable a few years back is now possible thanks to all the advances in technology, be it open or proprietary.

Steps to install PyTorch on VMware workstation (Ubuntu guest)

  The following is the list of steps to install pytorch 2.0 in VMware workstation (Ubuntu guest): $ mkdir ~/pytorch $ mkdir ~/pytorch/as...