>Linux Secrets!

>1. Linux uses COW scheme with virtual memory management.
2. Threads in Linux can be LinuxThreads, NPTL(Redhat). NPTL is more efficient and from kernel 2.6 onwards it’ll be used. Using env variable LD_ASSUME_KERNEL you can decide which thread library to choose.
3. Linux kernel do not discriminate between threads and processes while making scheduling decision.
4. Memory allocation of a process can be seen with ‘pmap’ command.
5. Linux CPU scheduler is O(1) scheduler i.e. regardless of number of processes, it always take a constant time to select a process.
6. Linux memory management for IA-32 can address only 1GB of physical memory. Beyond this memory has to mapped to the 1GB range hence allocation a page beyond 1GB degrades performance.
7. IA64 can address 64-128GB of memory.
8. Linux allocates most part of the disk’s free space to swap. This improves the performance of VMM.
9. It follows Buddy System for page allocation which try to keep memory address contiguous. Have a loot at /proc/buddyinfo.
10. If no free page is available, kswapd kernel thread reclaims free pages. This thread is used by buddy system and follows LRU. Kernel pages are never swapped out of memory.

>Linux Memory Management Secrets!

>Tips to Improve Dynamic Memory Performance

– Instead of using memset() to initialize malloc()’ed memory, use calloc(). Because when you call memset(), VM system has to map the pages in to memory in order to zero initialize them. It’s very expensive and wasteful if you don’t intend to use the pages right away.
calloc() reserves the needed address space but does not zero initialize them unless memory is used. Hence it postpones the need to load pages in to memory. It also lets the system initialize pages as they’re used, as opposed to all at once.

– Lazy allocation: A global(normal variable or a buffer) can be replaced with a static and a couple of functions to allow its access.

– memcpy() & memmove() needs both blocks to be memory resident. Use them if size of blocks is small(>16KB), you would be using the blocks right away, s/d blocks are not page aligned, blocks overlap.
But if you intend to postpone the use, you would increasing the working set of the application. For small amount of data, use memcpy().

– To check heap dysfunctional behavior: $ MALLOC_CHECK_=1 ./a.out
It’ll give an address related to each violation of dynamic memory routines.

– Electric fence : Works very well with gdb

– Libsafe: for libc routines

Rational Clearcase: Some Useful Commands

Rational Clearcase is perhaps the most popular version management software across various organizations. Here is my humble attempt to capture most useful commands that can save a lot of your time.

a) Creating an element
$cleartool mkelem -eltype{binary, directory etc.} elem_name

b) Creating many elements at once or say you want to convert your non-clearcase element as versioned.
– first copy & paste all such files/dir in a destination directory.
$find -type f/d |xargs cleartool mkelem eltype elem_name

b) Browsing files in your branch
$ct find ./ -branch ‘brtype(_view_name)’ -print

c) Soft Links
$cleartool ln -s target link_name

To update a link, remove it first($ cleartool rmname link_name), create a new link with same/different in a checked-out directory.

d) Merging changes in main branch
You have two options:
1. Use cleartool merge
2. Use diff/patch OR vimdiff

cleartool merge
– Checkout file with your changes.
– $cleartool merge -to file_with_your_changes -version main_branch_version

Amazingly simple and useful.

– Checkout file with your changes.
– $vimdiff file_with_your_changes file_on_main_branch
– You can make out the changes which are marked with different colors.
– Look the file on right side pane, a red color signifies some change in the line
– Merge changes with :,+1 diffget
– Moreover you can use any vi command

%d bloggers like this: