Thursday, December 11, 2014

When to use GFP_ATOMIC over GFP_KERNEL

Using the GFP_ATOMIC option with kmalloc instructs the memory allocator to never block waiting for a page. So the execution of the instruction will happen instantaneously - either with the allocation of the desired memory or not. Because the kernel does not have a chance to wait and free
up memory or reclaim memory for new allocations, GFP_ATOMIC has a higher chance of failing than GFP_KERNEL.

In order to make sure that the memory can be DMA’d, bitwise or either GFP_KERNEL or GFP_ATOMIC with the GFP_DMA flag as shown below:
1 . . .
2 buf = kmalloc (BUF_LEN, GFP_DMA | GFP_KERNEL) ;
3 i f ( ! buf )
4 e r r o r handling
5 . . .

Wednesday, December 10, 2014

Why is the buddy system needed in Linux

The buddy system is a mechanism for page management in Linux. It is needed to make sure that the free memory does not get fragmented and unusable. An alternative to the buddy system would be to use the memory management unit (MMU) support to rewire or re-arrange blobs of free pages together to construct larger contiguous pages. However, this will not work for DMA systems which bypass the MMU. Also, modifying the virtual address on a continual basis would make the paging process slow.

Debugging on the buddy system can be done by printing the current stats. This is supported under the /proc/buddyinfo file. As described in the guide from centos.org, fragmentation issues can be debugged. A sample output from the same site is as shown below:
cat /proc/buddyinfo

Monday, December 8, 2014

Customizing latex footnotes to alphabets

There is a simple hack to do this:
\renewcommand{\thefootnote}{\arabic{footnote}}Arabic numerals, e.g., 1, 2, 3...
\renewcommand{\thefootnote}{\roman{footnote}}Roman numerals (lowercase), e.g., i, ii,... 
\renewcommand{\thefootnote}{\Roman{footnote}}Roman numerals (uppercase), e.g., I, II, ... 
\renewcommand{\thefootnote}{\alph{footnote}}Alphabetic (lowercase), e.g., a, b... 
\renewcommand{\thefootnote}{\Alph{footnote}}Alphabetic (uppercase), e.g., A, ... 
\renewcommand{\thefootnote}{\fnsymbol{footnote}}A sequence of nine symbols,
Changed mine to alphabets. Looks much neater now.