<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Kaiwan's Tech Blog</title>
	<atom:link href="http://kaiwantech.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://kaiwantech.wordpress.com</link>
	<description>YALIN! Yet Another LINux blog</description>
	<lastBuildDate>Tue, 01 Nov 2011 02:44:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='kaiwantech.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Kaiwan's Tech Blog</title>
		<link>http://kaiwantech.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://kaiwantech.wordpress.com/osd.xml" title="Kaiwan&#039;s Tech Blog" />
	<atom:link rel='hub' href='http://kaiwantech.wordpress.com/?pushpress=hub'/>
		<item>
		<title>kmalloc and vmalloc : Linux kernel memory allocation API Limits</title>
		<link>http://kaiwantech.wordpress.com/2011/08/17/kmalloc-and-vmalloc-linux-kernel-memory-allocation-api-limits/</link>
		<comments>http://kaiwantech.wordpress.com/2011/08/17/kmalloc-and-vmalloc-linux-kernel-memory-allocation-api-limits/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 09:40:15 +0000</pubDate>
		<dc:creator>Kaiwan</dc:creator>
				<category><![CDATA[Embedded Linux]]></category>
		<category><![CDATA[Linux Kernel]]></category>
		<category><![CDATA[Linux Programming]]></category>
		<category><![CDATA[allocation]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[beagleboard]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[internals]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[kernel module]]></category>
		<category><![CDATA[kmalloc]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[LKM]]></category>
		<category><![CDATA[max]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[OMAP]]></category>
		<category><![CDATA[proc]]></category>
		<category><![CDATA[procfs]]></category>
		<category><![CDATA[size]]></category>
		<category><![CDATA[TI]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vmalloc]]></category>

		<guid isPermaLink="false">http://kaiwantech.wordpress.com/?p=188</guid>
		<description><![CDATA[The Intent To determine how large a memory allocation can be made from within the kernel, via the &#8220;usual suspects&#8221; &#8211; the kmalloc and vmalloc kernel memory allocation APIs, in a single call. Lets answer this question using two approaches: one, reading the source, and two, trying it out empirically on the system. (Kernel source [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=188&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2></h2>
<h2>The Intent</h2>
<p>To determine how large a memory allocation can be made from within the kernel, via the &#8220;usual suspects&#8221; &#8211; the kmalloc and vmalloc kernel memory allocation APIs, <em>in a single call</em>.</p>
<p>Lets answer this question using two approaches: one, reading the source, and two, trying it out empirically on the system.<br />
(Kernel source from kernel ver 3.0.2; tried out on kernel ver 2.6.35 on an x86 PC and 2.6.33.2 on the (ARM) BeagleBoard).</p>
<h2>Quick Summary</h2>
<p>For the impatient:</p>
<p>The upper limit (number of bytes that can be allocated in a single kmalloc request), is a function of:</p>
<ul>
<li>the processor – really, the page size – and</li>
<li>the number of buddy system freelists (MAX_ORDER).</li>
</ul>
<p>On both x86 and ARM, with a standard page size of 4 Kb and MAX_ORDER of 11, the kmalloc upper limit is 4 MB!<br />
The vmalloc upper limit is the amount of physical RAM on the system.</p>
<p>The kernel module (can download the source code, see the link at the end of this article), also serves as a decent example of writing pure kernel code.</p>
<p><span style="font-family:'Times New Roman';font-size:xx-small;"><br />
</span></p>
<h1>I kmalloc Limit Tests</h1>
<p>First, lets check out the limits for <strong>kmalloc </strong>:</p>
<h2>I Via the Source</h2>
<p>From the source: <a href="http://lxr.linux.no/linux+v3.0.2/include/linux/slab.h">http://lxr.linux.no/linux+v3.0.2/include/linux/slab.h</a></p>
<p>&#8230;</p>
<p><code>/*<br />
122 * The largest kmalloc size supported by the slab allocators is<br />
123 * 32 megabyte (2^25) or the maximum allocatable page order if that is<br />
124 * less than 32 MB.<br />
125 *<br />
126 * WARNING: Its not easy to increase this value since the allocators have<br />
127 * to do various tricks to work around compiler limitations in order to<br />
128 * ensure pr</code><span class="Apple-style-span" style="font-family:monospace;">oper constant folding.<br />
</span><span class="Apple-style-span" style="font-family:monospace;">129 */<br />
</span><span class="Apple-style-span" style="font-family:monospace;">130#define KMALLOC_SHIFT_HIGH ((MAX_ORDER + PAGE_SHIFT &#8211; 1) &lt;= 25 ? \<br />
</span><span class="Apple-style-span" style="font-family:monospace;">131                           (MAX_ORDER + PAGE_SHIFT &#8211; 1) : 25)<br />
</span><span class="Apple-style-span" style="font-family:monospace;">132<br />
</span><span class="Apple-style-span" style="font-family:monospace;">133#define KMALLOC_MAX_SIZE (1UL &lt;&lt; KMALLOC_SHIFT_HIGH)</span></p>
<p>With MAX_ORDER = 11 and PAGE_SHIFT = 12 (typical case on x86 or ARM with 4K pages), this works out to:<br />
1UL &lt;&lt; 22 which is (the same as 2^22) = 4194304 = 4096 KB = <strong>4MB</strong>.</p>
<h2></h2>
<h2>II Trying it out</h2>
<p>I wanted to verify this experimentally &#8211; well, at least the kmalloc() limit (the vmalloc() is hard to verify, as it can use the whole of physical RAM!).</p>
<p>Toward this end, I wrote a small kernel module. It basically does the following:</p>
<ul>
<li>Creates and sets up two proc-based &#8220;files&#8221;</li>
<ul>
<li>/proc/driver/kmalloc_test</li>
<li>/proc/driver/vmalloc_test</li>
</ul>
<li>their &#8216;write&#8217; callbacks are invoked when the user writes a value to the files; this, of course, is expected to be the number of bytes to attempt to allocate using that particular API (kmalloc, in this case).<br />
Also, realize that we will just do some  arbitrary writes into the region allocated and then (more or less) immediately free it.</li>
<li>their &#8216;read&#8217; callbacks are invoked when userspace reads the entry; it merely displays the last attempted number of bytes to allocate&#8230;</li>
</ul>
<div>So, once the driver is loaded, one just has to write to the proc file to attempt an allocation. For example:</div>
<div>
<pre># dmesg -c
...
#
# insmod ./kvalloc.ko
#
# ls -l /proc/driver/*test*
-rw-r--r-- 1 root root 0 2011-08-16 17:03 /proc/driver/kmalloc_test
-rw-r--r-- 1 root root 0 2011-08-16 17:03 /proc/driver/vmalloc_test
# echo 200000 &gt; /proc/driver/kmalloc_test
# dmesg
[25125.896862] vmall_init_module:260 : Loaded ok.
[25136.659209] kmalloc_procwrite:199 : Successfully allocated via kmalloc 200000 bytes (195 Kb, 0 MB) now to location 0xd5240000 (will kfree..)
#
# echo 2000008 &gt; /proc/driver/vmalloc_test
# dmesg
[25125.896862] vmall_init_module:260 : Loaded ok.
[25136.659209] kmalloc_procwrite:199 : Successfully allocated via kmalloc 200000 bytes (195 Kb, 0 MB) now to location 0xd5240000 (will kfree..)
[25162.082120] vmalloc_procwrite:129 : Successfully allocated via vmalloc 2000008 bytes (1953 Kb, 1 MB) now to location 0xe0ac5000 (will vfree..)
#</pre>
</div>
<p>As can be seen, the driver was loaded, the proc files were created, and two successful allocations were performed.<br />
Of course, one can&#8217;t be expected to keep doing this manually till we hit a limit&#8230;so, we&#8217;ll use a simple shell script to help automate this task.<br />
The script will basically loop, allocating a given amount of RAM (x bytes), adding a  step factor to it (x+step) and doing it again, in a loop&#8230;</p>
<p>We pass &#8216;k&#8217; or &#8216;v&#8217; to the script as a parameter, telling it whether to test the kmalloc or vmalloc API limit. We can also pass optional parameters, starting size and &#8216;step factor&#8217;.</p>
<pre><strong># ./test_kvalloc.sh</strong>
Usage: test_kvalloc.sh {k|v} [start_numbytes] [step_factor]
 k : test the KMALLOC limit
 v : test the VMALLOC limit
<strong># </strong></pre>
<h3>Testing kmalloc limit</h3>
<p>So, lets do a test run for kmalloc, starting at 300 Kb in steps of 500 Kb.</p>
<p># dmesg -c<br />
&#8230;<br />
<strong># ./test_kvalloc.sh k 307200 512000</strong><br />
KVALLOC_PROCFILE = /proc/driver/kmalloc_test</p>
<p>Running:<br />
KMALLOC TEST<br />
test_kvalloc.sh 307200 512000</p>
<p>Attempting to alloc 307200 bytes (300 KB, 0 MB)<br />
Attempting to alloc 819200 bytes (800 KB, 0 MB)<br />
Attempting to alloc 1331200 bytes (1300 KB, 1 MB)<br />
Attempting to alloc 1843200 bytes (1800 KB, 1 MB)<br />
Attempting to alloc 2355200 bytes (2300 KB, 2 MB)<br />
Attempting to alloc 2867200 bytes (2800 KB, 2 MB)<br />
Attempting to alloc 3379200 bytes (3300 KB, 3 MB)<br />
Attempting to alloc 3891200 bytes (3800 KB, 3 MB)<br />
Attempting to alloc 4403200 bytes (4300 KB, 4 MB)<br />
./test_kvalloc.sh: line 46: echo: write error: Cannot allocate memory<br />
FAILURE! AT 4403200 bytes = 4300 KB = 4 MB. Aborting&#8230;<br />
#</p>
<p><strong><em>Yes, it fails at ~ 4 MB. </em></strong></p>
<p><em></em><br />
# dmesg<br />
[25647.216149] kmalloc_procwrite:199 : Successfully allocated via kmalloc 307200 bytes (300 Kb, 0 MB) now to location 0xc0f80000 (will kfree..)<br />
[25647.223584] kmalloc_procwrite:199 : Successfully allocated via kmalloc 819200 bytes (800 Kb, 0 MB) now to location 0xdce00000 (will kfree..)<br />
[25647.321891] kmalloc_procwrite:199 : Successfully allocated via kmalloc 1331200 bytes (1300 Kb, 1 MB) now to location 0xdcc00000 (will kfree..)<br />
[25647.329913] kmalloc_procwrite:199 : Successfully allocated via kmalloc 1843200 bytes (1800 Kb, 1 MB) now to location 0xdcc00000 (will kfree..)<br />
[25647.336471] kmalloc_procwrite:199 : Successfully allocated via kmalloc 2355200 bytes (2300 Kb, 2 MB) now to location 0xdc000000 (will kfree..)<br />
[25647.397678] kmalloc_procwrite:199 : Successfully allocated via kmalloc 2867200 bytes (2800 Kb, 2 MB) now to location 0xdc000000 (will kfree..)<br />
[25647.398845] kmalloc_procwrite:199 : Successfully allocated via kmalloc 3379200 bytes (3300 Kb, 3 MB) now to location 0xdc000000 (will kfree..)<br />
[25647.400119] kmalloc_procwrite:199 : Successfully allocated via kmalloc 3891200 bytes (3800 Kb, 3 MB) now to location 0xdc000000 (will kfree..)<br />
[25647.401443] &#8212;&#8212;&#8212;&#8212;[ cut here ]&#8212;&#8212;&#8212;&#8212;<br />
[25647.401598] WARNING: at /build/buildd/linux-2.6.35/mm/page_alloc.c:2005 __alloc_pages_slowpath+0x36d/0x4b0()<br />
[25647.401624] Hardware name: VMware Virtual Platform<br />
[25647.401625] Modules linked in: kvalloc nls_iso8859_1 nls_cp437 vfat fat usb_storage cdc_acm vmblock vsock vmhgfs acpiphp binfmt_misc snd_ens1371 gameport snd_ac97_codec ac97_bus snd_pcm snd_seq_midi snd_rawmidi ppdev snd_seq_midi_event snd_seq vmware_balloon snd_timer snd_seq_device psmouse serio_raw parport_pc snd soundcore snd_page_alloc intel_agp lp agpgart vmci i2c_piix4 shpchp parport mptspi mptscsih floppy mptbase scsi_transport_spi vmxnet [last unloaded: kvalloc]<br />
[25647.401674] Pid: 6395, comm: test_kvalloc.sh Not tainted 2.6.35-30-generic #56-Ubuntu<br />
[25647.401676] Call Trace:<br />
[25647.401723] [&lt;c014b602&gt;] warn_slowpath_common+0&#215;72/0xa0<br />
[25647.401729] [&lt;c01e0a5d&gt;] ? __alloc_pages_slowpath+0x36d/0x4b0<br />
[25647.401732] [&lt;c01e0a5d&gt;] ? __alloc_pages_slowpath+0x36d/0x4b0<br />
[25647.401735] [&lt;c014b652&gt;] warn_slowpath_null+0&#215;22/0&#215;30<br />
[25647.401750] [&lt;c01e0a5d&gt;] __alloc_pages_slowpath+0x36d/0x4b0<br />
[25647.401753] [&lt;c01e03c7&gt;] ? get_page_from_freelist+0&#215;247/0&#215;330<br />
[25647.401756] [&lt;c01e0d0f&gt;] __alloc_pages_nodemask+0x16f/0x1c0<br />
[25647.401759] [&lt;c01e0d7c&gt;] __get_free_pages+0x1c/0&#215;30<br />
[25647.401785] [&lt;c020e196&gt;] __kmalloc+0&#215;146/0&#215;170<br />
[25647.401799] [&lt;c0231c6f&gt;] ? mntput_no_expire+0x1f/0xd0<br />
[25647.401803] [&lt;e0a493ca&gt;] kmalloc_procwrite+0x7a/0x1d8 [kvalloc]<br />
[25647.401848] [&lt;c02644d3&gt;] proc_file_write+0&#215;63/0xa0<br />
[25647.401851] [&lt;c0264470&gt;] ? proc_file_write+0&#215;0/0xa0<br />
[25647.401854] [&lt;c025f4f7&gt;] proc_reg_write+0&#215;67/0xa0<br />
[25647.401868] [&lt;c023069d&gt;] ? alloc_fd+0xbd/0xf0<br />
[25647.401872] [&lt;c0219ab2&gt;] vfs_write+0xa2/0&#215;190<br />
[25647.401875] [&lt;c025f490&gt;] ? proc_reg_write+0&#215;0/0xa0<br />
[25647.401878] [&lt;c021a372&gt;] sys_write+0&#215;42/0&#215;70<br />
[25647.401923] [&lt;c05cc284&gt;] syscall_call+0&#215;7/0xb<br />
[25647.401925] &#8212;[ end trace b6b188c8bd2758df ]&#8212;<br />
[25647.401927] kvalloc: kmalloc of 4403200 bytes FAILED!<br />
#</p>
<h3>Testing the same on the BeagleBoard (running 2.6.33.2 Linux on a TI OMAP3 ARM Cortex-A8 processor, 256 MB RAM):</h3>
<p>On the board, after inserting the kernel module, we run the shell script:</p>
<pre>root@beagleboard:/media/mmcblk0p1# ./test_kvalloc.arm.sh k 50000 102400
KVALLOC_PROCFILE = /proc/driver/kmalloc_test

Running:
KMALLOC TEST
test_kvalloc.arm.sh 50000 102400

Attempting to alloc 50000 bytes (48 KB, 0 MB)
kmalloc_procwrite:199 : Successfully allocated via kmalloc 50000 bytes (48 Kb, 0 MB) now to location 0xc2c40000 (will kfr
ee..)
Attempting to alloc 152400 bytes (148 KB, 0 MB)
kmalloc_procwrite:199 : Successfully allocated via kmalloc 152400 bytes (148 Kb, 0 MB) now to location 0xcd400000 (will k
free..)
Attempting to alloc 254800 bytes (248 KB, 0 MB)
kmalloc_procwrite:199 : Successfully allocated via kmalloc 254800 bytes (248 Kb, 0 MB) now to location 0xcd400000 (will k
free..)
Attempting to alloc 357200 bytes (348 KB, 0 MB)
kmalloc_procwrite:199 : Successfully allocated via kmalloc 357200 bytes (348 Kb, 0 MB) now to location 0xcf980000 (will k
free..)
...
...
Attempting to alloc 3838800 bytes (3748 KB, 3 MB)
kmalloc_procwrite:199 : Successfully allocated via kmalloc 3838800 bytes (3748 Kb, 3 MB) now to location 0xcd800000 (will
 kfree..)
Attempting to alloc 3941200 bytes (3848 KB, 3 MB)
kmalloc_procwrite:199 : Successfully allocated via kmalloc 3941200 bytes (3848 Kb, 3 MB) now to location 0xcd800000 (will
 kfree..)
Attempting to alloc 4043600 bytes (3948 KB, 3 MB)
kmalloc_procwrite:199 : Successfully allocated via kmalloc 4043600 bytes (3948 Kb, 3 MB) now to location 0xcd800000 (will
 kfree..)
Attempting to alloc 4146000 bytes (4048 KB, 3 MB)
kmalloc_procwrite:199 : Successfully allocated via kmalloc 4146000 bytes (4048 Kb, 3 MB) now to location 0xcd800000 (will
 kfree..)
Attempting to alloc 4248400 bytes (4148 KB, 4 MB)
kvalloc: kmalloc of 4248400 bytes FAILED!
root@beagleboard:/media/mmcblk0p1#</pre>
<p><em><strong>Clearly, and as expected, the kmalloc() fails at the 4 Mb allocation attempt (just as on the x86)!</strong></em></p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<h1>II vmalloc Limit Tests</h1>
<p>Now, lets check out the limits for <strong>vmalloc</strong> :</p>
<h2>I Via the Source</h2>
<p>A quick perusal of the source (start at mm/vmalloc.c), shows the call graph for vmalloc is (approximately, at least):</p>
<p>vmalloc &#8211;&gt; __vmalloc_node_flags &#8211;&gt; __vmalloc_node &#8211;&gt; __vmalloc_node_range</p>
<p><em>[ a --&gt; b above implies function a() calls function b() ].</em></p>
<p>In the function __vmalloc_node_range()  (code pasted below from the lxr.linux.no website):</p>
<pre>...
void *<a href="http://lxr.linux.no/linux+v3.0.2/+code=__vmalloc_node_range">__vmalloc_node_range</a>(unsigned long <a href="http://lxr.linux.no/linux+v3.0.2/+code=size">size</a>, unsigned long <a href="http://lxr.linux.no/linux+v3.0.2/+code=align">align</a>,
<a id="L1607" name="L1607" href="http://lxr.linux.no/linux+v3.0.2/mm/vmalloc.c#L1607"></a>1607                        unsigned long <a href="http://lxr.linux.no/linux+v3.0.2/+code=start">start</a>, unsigned long <a href="http://lxr.linux.no/linux+v3.0.2/+code=end">end</a>, <a href="http://lxr.linux.no/linux+v3.0.2/+code=gfp_t">gfp_t</a> <a href="http://lxr.linux.no/linux+v3.0.2/+code=gfp_mask">gfp_mask</a>,
<a id="L1608" name="L1608" href="http://lxr.linux.no/linux+v3.0.2/mm/vmalloc.c#L1608"></a>1608                        <a href="http://lxr.linux.no/linux+v3.0.2/+code=pgprot_t">pgprot_t</a> <a href="http://lxr.linux.no/linux+v3.0.2/+code=prot">prot</a>, int <a href="http://lxr.linux.no/linux+v3.0.2/+code=node">node</a>, void *<a href="http://lxr.linux.no/linux+v3.0.2/+code=caller">caller</a>)
<a id="L1609" name="L1609" href="http://lxr.linux.no/linux+v3.0.2/mm/vmalloc.c#L1609"></a>1609{
<a id="L1610" name="L1610" href="http://lxr.linux.no/linux+v3.0.2/mm/vmalloc.c#L1610"></a>1610        struct <a href="http://lxr.linux.no/linux+v3.0.2/+code=vm_struct">vm_struct</a> *<a href="http://lxr.linux.no/linux+v3.0.2/+code=area">area</a>;
<a id="L1611" name="L1611" href="http://lxr.linux.no/linux+v3.0.2/mm/vmalloc.c#L1611"></a>1611        void *<a href="http://lxr.linux.no/linux+v3.0.2/+code=addr">addr</a>;
<a id="L1612" name="L1612" href="http://lxr.linux.no/linux+v3.0.2/mm/vmalloc.c#L1612"></a>1612        unsigned long <a href="http://lxr.linux.no/linux+v3.0.2/+code=real_size">real_size</a> = <a href="http://lxr.linux.no/linux+v3.0.2/+code=size">size</a>;
<a id="L1613" name="L1613" href="http://lxr.linux.no/linux+v3.0.2/mm/vmalloc.c#L1613"></a>1613
<a id="L1614" name="L1614" href="http://lxr.linux.no/linux+v3.0.2/mm/vmalloc.c#L1614"></a>1614        <a href="http://lxr.linux.no/linux+v3.0.2/+code=size">size</a> = <a href="http://lxr.linux.no/linux+v3.0.2/+code=PAGE_ALIGN">PAGE_ALIGN</a>(<a href="http://lxr.linux.no/linux+v3.0.2/+code=size">size</a>);
<a id="L1615" name="L1615" href="http://lxr.linux.no/linux+v3.0.2/mm/vmalloc.c#L1615"></a>1615        if (!<a href="http://lxr.linux.no/linux+v3.0.2/+code=size">size</a> || (<a href="http://lxr.linux.no/linux+v3.0.2/+code=size">size</a> &gt;&gt; <a href="http://lxr.linux.no/linux+v3.0.2/+code=PAGE_SHIFT">PAGE_SHIFT</a>) &gt; <a href="http://lxr.linux.no/linux+v3.0.2/+code=totalram_pages">totalram_pages</a>)
<a id="L1616" name="L1616" href="http://lxr.linux.no/linux+v3.0.2/mm/vmalloc.c#L1616"></a>1616                return <a href="http://lxr.linux.no/linux+v3.0.2/+code=NULL">NULL</a>;
<a id="L1617" name="L1617" href="http://lxr.linux.no/linux+v3.0.2/mm/vmalloc.c#L1617"></a>1617</pre>
<p id="81/e5/99c5fa3941bad9d64f37ff37a463f5f85dec_3/1000">Line 1615 above tells us:</p>
<p id="81/e5/99c5fa3941bad9d64f37ff37a463f5f85dec_3/1000">if the size is zero OR if the size expressed in pages is greater than <em>totalram_pages</em>, then abort; it&#8217;s invalid.<br />
<strong>So there&#8217;s our answer: the vmalloc API limit is the size of physical RAM!</strong></p>
<p id="81/e5/99c5fa3941bad9d64f37ff37a463f5f85dec_3/1000">Of course, budding kernel developers, please (read, <em>for God&#8217;s sake!!!</em>) note:<br />
Do NOT abuse this API by allocating huge amounts of RAM just because you can; you will hurt the kernel&#8217;s performance like heck and no one will use your driver! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  It&#8217;s true&#8230;</p>
<h2>II Trying it out</h2>
<p>Running on Ubuntu 10.04 with a 2.6.35 kernel, on the VMware VM, we have this much RAM:</p>
<pre># grep -i memtotal /proc/meminfo
MemTotal:         508396 kB
#</pre>
<p>i.e. ~  <strong>496 MB</strong> of RAM.</p>
<p>We run the same shell script as above, this time with the &#8216;v&#8217; parameter and a larger initial size (lets try 500 Kb) and &#8216;step factor&#8217; (lets go with 5 Mb &#8211; that means we&#8217;ll attempt to alloc in steps of 5 Mb !):</p>
<p>&#8230;</p>
<p><a href="http://kaiwantech.files.wordpress.com/2011/08/screenshot-vmalloc1-ubuntu-10-10-x86-32-vmware-player.png"><img title="Screenshot-vmalloc1-Ubuntu 10.10 x86-32 - VMware Player" src="http://kaiwantech.files.wordpress.com/2011/08/screenshot-vmalloc1-ubuntu-10-10-x86-32-vmware-player.png?w=1024&#038;h=640" alt="vmalloc limit test 1" width="1024" height="640" /></a></p>
<p>&#8230;</p>
<div class="wp-caption alignnone" style="width: 1034px"><a href="http://kaiwantech.files.wordpress.com/2011/08/screenshot-vmalloc2-ubuntu-10-10-x86-32-vmware-player.png"><img class="size-full wp-image-200" title="Screenshot-vmalloc2-Ubuntu 10.10 x86-32 - VMware Player" src="http://kaiwantech.files.wordpress.com/2011/08/screenshot-vmalloc2-ubuntu-10-10-x86-32-vmware-player.png?w=630" alt="vmalloc limit test 2"   /></a><p class="wp-caption-text">vmalloc limit test 2</p></div>
<p>&#8230;<br />
I find that vmalloc successfully allocates (and of course subsequently deallocates) upto ~ 455 MB at one shot (remember, on this VM system total RAM is 496 MB) before the virtual machine itself seems to hang. In reality, the kernel is doing it&#8217;s very best to allocate RAM as requested. In fact, it does succeed&#8230;until RAM runs out!</p>
<p>The Linux OS design is such that, when RAM is falling short, the kernel will do it&#8217;s damn-dest to reclaim RAM, aggressively swapping as necessary. What if this does not help? What if some malicious or greedy app(s) <em>keep allocating memory</em>!? &#8211; like we do here: we just keep eating RAM with vmalloc()! Well, when the kernel hits a dead-end, i.e., when <em>both</em> RAM and swap space are (almost) exhausted, the kernel takes a decision: it can either die or kill the bad guy; guess which it does <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The OOM (Out Of Memory) Killer runs, killing off the &#8220;bad&#8221; tasks!<br />
That&#8217;s exactly what happens here: we don&#8217;t give the kernel much choice, do we!</p>
<p>Notice how this is a very different case from how the kmalloc() fails : it fails on hitting an artificially set limit, with no fuss or fanfare. The vmalloc(), on the other hand, hogs so much RAM, that it inadvertently causes the OOM Killer to run, killing the memory hoggers as a side effect, rather than failing directly due to the size limit being hit.</p>
<p>The screenshots above show the situation before the OOM-killer hits.</p>
<p>[ These tests have been run on Ubuntu 10.04, running a 2.6.35 kernel on the VMware Workstation VM product ].</p>
<h3>Testing the same on the BeagleBoard (running 2.6.33.2 Linux on a TI OMAP3 ARM Cortex-A8 processor, 256 MB RAM):</h3>
<p>The BeagleBoard I&#8217;m using (rev C3), has 256 MB RAM. On the board, after inserting the kernel module, we run the shell script, this time with the &#8216;v&#8217; parameter and a larger initial size (lets try 500 Kb) and &#8216;step factor&#8217; (lets go with 5 Mb &#8211; that means we&#8217;ll attempt to alloc in steps of 5 Mb !):</p>
<pre>root@beagleboard:/media/mmcblk0p1# ./test_kvalloc.arm.sh
Usage: test_kvalloc.arm.sh {k|v} [start_numbytes] [step_factor]
 k : test the KMALLOC limit
 v : test the VMALLOC limit
<strong>root@beagleboard:/media/mmcblk0p1# ./test_kvalloc.arm.sh v 500000 5242880</strong>
KVALLOC_PROCFILE = /proc/driver/vmalloc_test

Running:
VMALLOC TEST
test_kvalloc.arm.sh 500000 5242880

Attempting to alloc 500000 bytes (488 KB, 0 MB)
vmalloc_procwrite:129 : Successfully allocated via vmalloc 500000 bytes (488 Kb, 0 MB) now to location 0xd0871000 (will v
free..)
Attempting to alloc 5742880 bytes (5608 KB, 5 MB)
vmalloc_procwrite:129 : Successfully allocated via vmalloc 5742880 bytes (5608 Kb, 5 MB) now to location 0xd08ee000 (will
 vfree..)
Attempting to alloc 10985760 bytes (10728 KB, 10 MB)
vmalloc_procwrite:129 : Successfully allocated via vmalloc 10985760 bytes (10728 Kb, 10 MB) now to location 0xd0e6f000 (w
ill vfree..)
Attempting to alloc 16228640 bytes (15848 KB, 15 MB)
vmalloc_procwrite:129 : Successfully allocated via vmalloc 16228640 bytes (15848 Kb, 15 MB) now to location 0xd18f1000 (w
ill vfree..)
...
...
Attempting to alloc 220700960 bytes (215528 KB, 210 MB)
vmalloc_procwrite:129 : Successfully allocated via vmalloc 220700960 bytes (215528 Kb, 210 MB) now to location 0xd088e000
 (will vfree..)
Attempting to alloc 225943840 bytes (220648 KB, 215 MB)
vmalloc_procwrite:129 : Successfully allocated via vmalloc 225943840 bytes (220648 Kb, 215 MB) now to location 0xddb42000
 (will vfree..)
Attempting to alloc 231186720 bytes (225768 KB, 220 MB)
vmalloc_procwrite:129 : Successfully allocated via vmalloc 231186720 bytes (225768 Kb, 220 MB) now to location 0xd0890000
 (will vfree..)
Attempting to alloc 236429600 bytes (230888 KB, 225 MB)
echo invoked oom-killer: gfp_mask=0xd2, order=0, oom_adj=0
[&lt;c002e3a0&gt;] (unwind_backtrace+0x0/0xd4) from [&lt;c007c700&gt;] (T.280+0x3c/0x108)
[&lt;c007c700&gt;] (T.280+0x3c/0x108) from [&lt;c007c804&gt;] (T.277+0x38/0xd8)
[&lt;c007c804&gt;] (T.277+0x38/0xd8) from [&lt;c007c9f8&gt;] (__out_of_memory+0x154/0x178)
[&lt;c007c9f8&gt;] (__out_of_memory+0x154/0x178) from [&lt;c007ca9c&gt;] (out_of_memory+0x80/0xb4)
[&lt;c007ca9c&gt;] (out_of_memory+0x80/0xb4) from [&lt;c007f208&gt;] (__alloc_pages_nodemask+0x418/0x514)
[&lt;c007f208&gt;] (__alloc_pages_nodemask+0x418/0x514) from [&lt;c0095678&gt;] (__vmalloc_area_node+0xbc/0x11c)
[&lt;c0095678&gt;] (__vmalloc_area_node+0xbc/0x11c) from [&lt;c00958b8&gt;] (vmalloc+0x24/0x2c)
[&lt;c00958b8&gt;] (vmalloc+0x24/0x2c) from [&lt;bf000140&gt;] (vmalloc_procwrite+0xf4/0x190 [kvalloc])
[&lt;bf000140&gt;] (vmalloc_procwrite+0xf4/0x190 [kvalloc]) from [&lt;c00dd100&gt;] (proc_file_write+0x3c/0x58)
[&lt;c00dd100&gt;] (proc_file_write+0x3c/0x58) from [&lt;c00d94ec&gt;] (proc_reg_write+0x40/0x54)
[&lt;c00d94ec&gt;] (proc_reg_write+0x40/0x54) from [&lt;c009e490&gt;] (vfs_write+0xac/0x154)
[&lt;c009e490&gt;] (vfs_write+0xac/0x154) from [&lt;c009e5e4&gt;] (sys_write+0x3c/0x68)
[&lt;c009e5e4&gt;] (sys_write+0x3c/0x68) from [&lt;c0028dc0&gt;] (ret_fast_syscall+0x0/0x2c)
Mem-info:
Normal per-cpu:
CPU    0: hi:   90, btch:  15 usd:  97
...
...
0 pages swap cached
Out of memory: kill process 991 (sh) score 65 or a child
Killed process 2533 (test_kvalloc.ar) vsz:2676kB, anon-rss:72kB, file-rss:0kB
echo invoked oom-killer: gfp_mask=0xd2, order=0, oom_adj=0
[&lt;c002e3a0&gt;] (unwind_backtrace+0x0/0xd4) from [&lt;c007c700&gt;] (T.280+0x3c/0x108)
[&lt;c007c700&gt;] (T.280+0x3c/0x108) from [&lt;c007c804&gt;] (T.277+0x38/0xd8)
[&lt;c007c804&gt;] (T.277+0x38/0xd8) from [&lt;c007c9f8&gt;] (__out_of_memory+0x154/0x178)
[&lt;c007c9f8&gt;] (__out_of_memory+0x154/0x178) from [&lt;c007ca9c&gt;] (out_of_memory+0x80/0xb4)
...
...
Out of memory: kill process 991 (sh) score 44 or a child
Killed process 991 (sh) vsz:2852kB, anon-rss:112kB, file-rss:24kB
echo invoked oom-killer: gfp_mask=0xd2, order=0, oom_adj=0
...
...
Out of memory: kill process 986 (syslogd) score 42 or a child
Killed process 986 (syslogd) vsz:2740kB, anon-rss:60kB, file-rss:64kB
...
...</pre>
<p>So, we can see from above, that at the 225 MB allocation attempt it failed; the kernel OOM-killer jumped in and rapidly finished off the shell script, the shell process, syslogd&#8230;<br />
After that, I aborted the script and the login process re-ran (because init would have re-spawned it) and I received the login prompt again.</p>
<p>=============================================================================================================================================</p>
<p>As an aside, this kernel module serves as a decent example of writing some pure kernel code (not driver related): it is concurrent-safe, and implements the useful notion of a global &#8220;context / device&#8221; structure accessed via a single global pointer that is passed around. This helps with code maintenance and debugging as well&#8230;It is also small enough to read quickly and grasp the essentials.</p>
<p><em>Please do comment with your inputs!</em></p>
<p><a title="Download kvalloc source" href="https://docs.google.com/leaf?id=0B50DrIUFF1J2NDBhOWQ4ZjAtYTcyZC00YjEwLTkwMGUtY2E1MTEzMzQ5M2Nj&amp;hl=en_US">Download the source tarball (tar.gz) here</a>.</p>
<br />Filed under: <a href='http://kaiwantech.wordpress.com/category/embedded-linux/'>Embedded Linux</a>, <a href='http://kaiwantech.wordpress.com/category/linux-kernel/'>Linux Kernel</a>, <a href='http://kaiwantech.wordpress.com/category/linux-programming/'>Linux Programming</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kaiwantech.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kaiwantech.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kaiwantech.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kaiwantech.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kaiwantech.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kaiwantech.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kaiwantech.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kaiwantech.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kaiwantech.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kaiwantech.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kaiwantech.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kaiwantech.wordpress.com/188/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kaiwantech.wordpress.com/188/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kaiwantech.wordpress.com/188/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=188&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kaiwantech.wordpress.com/2011/08/17/kmalloc-and-vmalloc-linux-kernel-memory-allocation-api-limits/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5216008e0b231a760d20d22b01c4328?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kaiwan</media:title>
		</media:content>

		<media:content url="http://kaiwantech.files.wordpress.com/2011/08/screenshot-vmalloc1-ubuntu-10-10-x86-32-vmware-player.png" medium="image">
			<media:title type="html">Screenshot-vmalloc1-Ubuntu 10.10 x86-32 - VMware Player</media:title>
		</media:content>

		<media:content url="http://kaiwantech.files.wordpress.com/2011/08/screenshot-vmalloc2-ubuntu-10-10-x86-32-vmware-player.png" medium="image">
			<media:title type="html">Screenshot-vmalloc2-Ubuntu 10.10 x86-32 - VMware Player</media:title>
		</media:content>
	</item>
		<item>
		<title>SIGRTMIN or SIGRTMAX &#8211; who&#8217;s higher up (in signal delivery priority order)?</title>
		<link>http://kaiwantech.wordpress.com/2011/03/22/sigrtmin-or-sigrtmax-whos-higher-up-in-signal-delivery-priority-order/</link>
		<comments>http://kaiwantech.wordpress.com/2011/03/22/sigrtmin-or-sigrtmax-whos-higher-up-in-signal-delivery-priority-order/#comments</comments>
		<pubDate>Tue, 22 Mar 2011 10:47:32 +0000</pubDate>
		<dc:creator>Kaiwan</dc:creator>
				<category><![CDATA[Linux Programming]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[signals]]></category>

		<guid isPermaLink="false">http://kaiwantech.wordpress.com/?p=79</guid>
		<description><![CDATA[Linux supports Realtime (RT) signals (part of the Posix 1003.1b draft standard). The only other GPOS (general pupose OS) that does so is Solaris (TODO- verify. Right? Anyone??). The Linux RT signals can be seen with the usual &#8216;kill&#8217; command. [As can be seen from the command output, am running on an Ubuntu 10.10 Linux [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=79&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Linux supports Realtime (RT) signals (part of the Posix 1003.1b draft standard).<br />
The only other GPOS (general pupose OS) that does so is Solaris (TODO- verify. Right? Anyone??).</p>
<p>The Linux RT signals can be seen with the usual &#8216;kill&#8217; command.</p>
<p><em><span id="more-79"></span>[As can be seen from the command output, am running on an Ubuntu 10.10 Linux box, with libc ver 2.12.1]:</em> <code><strong><br />
<code><br />
$ cat /etc/issue<br />
</code></strong>Ubuntu 10.10 \n \l</code></p>
<p><strong>$ uname -r<br />
</strong>2.6.35-28-generic</p>
<p><strong>$ ls -l /lib/libc.so.6<br />
</strong>lrwxrwxrwx 1 root root 14 2011-02-03 09:49 /lib/libc.so.6 -&gt; libc-2.12.1.so* <strong><br />
$<br />
$ kill -l<br />
</strong>1) SIGHUP     2) SIGINT     3) SIGQUIT     4) SIGILL     5) SIGTRAP 6) SIGABRT     7) SIGBUS     8) SIGFPE     9) SIGKILL    10) SIGUSR1 11) SIGSEGV    12) SIGUSR2    13) SIGPIPE    14) SIGALRM    15) SIGTERM 16) SIGSTKFLT    17) SIGCHLD    18) SIGCONT    19) SIGSTOP    20) SIGTSTP 21) SIGTTIN    22) SIGTTOU    23) SIGURG    24) SIGXCPU    25) SIGXFSZ 26) SIGVTALRM    27) SIGPROF    28) SIGWINCH    29) SIGIO    30) SIGPWR 31) SIGSYS   <span style="color:#0000ff;"> 34) SIGRTMIN    35) SIGRTMIN+1    36) SIGRTMIN+2    37) SIGRTMIN+3</span> <span style="color:#0000ff;">38) SIGRTMIN+4    39) SIGRTMIN+5    40) SIGRTMIN+6    41) SIGRTMIN+7    42) SIGRTMIN+8</span> <span style="color:#0000ff;">43) SIGRTMIN+9    44) SIGRTMIN+10    45) SIGRTMIN+11    46) SIGRTMIN+12    47) SIGRTMIN+13</span> <span style="color:#0000ff;">48) SIGRTMIN+14    49) SIGRTMIN+15    50) SIGRTMAX-14    51) SIGRTMAX-13    52) SIGRTMAX-12</span> <span style="color:#0000ff;">53) SIGRTMAX-11    54) SIGRTMAX-10    55) SIGRTMAX-9    56) SIGRTMAX-8    57) SIGRTMAX-7</span> <span style="color:#0000ff;">58) SIGRTMAX-6    59) SIGRTMAX-5    60) SIGRTMAX-4    61) SIGRTMAX-3    62) SIGRTMAX-2</span> <span style="color:#0000ff;">63) SIGRTMAX-1    64) SIGRTMAX </span> <strong><br />
$</strong></p>
<p>RT signals above are highlighted in <span style="color:#0000ff;">blue colour</span>.</p>
<p>There is (was?) some confusion (different opinions in texts, manuals) as to the prioritisation of queued R signals; is SIGRMIN the lowest priority signal (seems intuitive).</p>
<p>Turns out this is not the case (as I&#8217;ve empirically verified): the top priority RT signal isSIGRTMIN; least (worst) priority RT sig is SIGRTMAX.</p>
<p><em>Source: the<strong> man page on signal(7)</strong>:</em></p>
<pre>...</pre>
<p><strong>Real-time Signals</strong><br />
Linux supports real-time signals as originally defined in the POSIX.1b real-time extensions (and now included in  POSIX.1-2001).<br />
The  range  of supported real-time signals is defined by the macros SIGRTMIN and SIGRTMAX.</p>
<pre>...</pre>
<p>Real-time signals are distinguished by the following:</p>
<p>1.  Multiple  instances  of real-time signals can be queued.  By contrast, if multiple instances of a standard signal are deliv‐<br />
ered while that signal is currently blocked, then only one instance is queued.</p>
<p>2.  If the signal is sent using sigqueue(2), an accompanying value (either an integer or a pointer) can be sent with the signal. If  the receiving process establishes a handler for this signal using the SA_SIGINFO flag to sigaction(2) then it can obtain this data via the si_value field of the siginfo_t structure passed as the second argument to the handler.  Furthermore,  the si_pid and si_uid fields of this structure can be used to obtain the PID and real user ID of the process sending the signal.</p>
<p>3.  Real-time  signals  are  <span style="color:#ff0000;">delivered  in a guaranteed order</span>.  Multiple real-time signals of the same type are delivered in the order they were sent.  If different real-time signals are sent to a process,<span style="color:#ff0000;"><em><strong> they are delivered starting  with  the  lowest-</strong></em></span><span style="color:#ff0000;"><em><strong>numbered signal.  (I.e., low-numbered signals have highest priority.</strong></em></span>) By contrast, if multiple standard signals are pending for a process, the order in which they are delivered is unspecified.</p>
<p>If both standard and real-time signals are pending for a process, POSIX leaves it unspecified which is delivered first.   Linux, like many other implementations, gives priority to standard signals in this case.</p>
<p>&#8230;</p>
<p>So that settles it.</p>
<br />Filed under: <a href='http://kaiwantech.wordpress.com/category/linux-programming/'>Linux Programming</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kaiwantech.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kaiwantech.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kaiwantech.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kaiwantech.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kaiwantech.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kaiwantech.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kaiwantech.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kaiwantech.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kaiwantech.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kaiwantech.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kaiwantech.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kaiwantech.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kaiwantech.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kaiwantech.wordpress.com/79/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=79&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kaiwantech.wordpress.com/2011/03/22/sigrtmin-or-sigrtmax-whos-higher-up-in-signal-delivery-priority-order/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5216008e0b231a760d20d22b01c4328?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kaiwan</media:title>
		</media:content>
	</item>
		<item>
		<title>Android &#8216;A Look Under the Hood&#8217; Presentation at the BAUG</title>
		<link>http://kaiwantech.wordpress.com/2010/05/01/android-a-look-under-the-hood-presentation-at-the-baug/</link>
		<comments>http://kaiwantech.wordpress.com/2010/05/01/android-a-look-under-the-hood-presentation-at-the-baug/#comments</comments>
		<pubDate>Sat, 01 May 2010 08:13:03 +0000</pubDate>
		<dc:creator>Kaiwan</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Embedded Linux]]></category>
		<category><![CDATA[BAUG]]></category>
		<category><![CDATA[meetup]]></category>

		<guid isPermaLink="false">http://kaiwantech.wordpress.com/?p=148</guid>
		<description><![CDATA[Sat 24 April 2010. Attended the third &#8216;meetup&#8217; of the Bangalore Android Users Group (BAUG). I came in late; heard an interesting session by Askhay Dashrath (the lead organizer). Was asked by Bhavya to talk about something on Android, so gave a presentation on &#8216;Android: A Look Under the Hood&#8217;. The coverage included: how Android [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=148&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sat 24 April 2010. Attended the third &#8216;meetup&#8217; of the <a href="http://www.meetup.com/android-baug/boards/view/viewthread?thread=8993742">Bangalore Android Users Group (BAUG)</a>.</p>
<p>I came in late; heard an interesting session by Askhay Dashrath (the lead organizer).</p>
<p>Was asked by Bhavya to talk about something on Android, so gave a presentation on &#8216;Android: A Look Under the Hood&#8217;.<br />
The coverage included:</p>
<ul>
<li>how Android is different from a &#8220;typical&#8221; embedded Linux device / product</li>
<li>Android Architecture</li>
<li>Google&#8217;s Android enhancements to the Linux kernel</li>
<li>brief demo on a device using &#8216;adb shell&#8217;</li>
</ul>
<p>The session was well received, with a good number of questions from participants.</p>
<p>The presentation docs were subsequently uploaded and <a href="http://files.meetup.com/1537455/BAUG_24Apr2010.zip">are available here</a>.</p>
<p>An enjoyable and enlightening time for me as well!</p>
<br />Filed under: <a href='http://kaiwantech.wordpress.com/category/android/'>Android</a>, <a href='http://kaiwantech.wordpress.com/category/embedded-linux/'>Embedded Linux</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kaiwantech.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kaiwantech.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kaiwantech.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kaiwantech.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kaiwantech.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kaiwantech.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kaiwantech.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kaiwantech.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kaiwantech.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kaiwantech.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kaiwantech.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kaiwantech.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kaiwantech.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kaiwantech.wordpress.com/148/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=148&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kaiwantech.wordpress.com/2010/05/01/android-a-look-under-the-hood-presentation-at-the-baug/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5216008e0b231a760d20d22b01c4328?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kaiwan</media:title>
		</media:content>
	</item>
		<item>
		<title>Inside the MSDOS / FAT Linux VFS Implementation</title>
		<link>http://kaiwantech.wordpress.com/2009/08/17/inside-the-msdos-fat-linux-vfs-implementation/</link>
		<comments>http://kaiwantech.wordpress.com/2009/08/17/inside-the-msdos-fat-linux-vfs-implementation/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 12:51:28 +0000</pubDate>
		<dc:creator>Kaiwan</dc:creator>
				<category><![CDATA[Linux Kernel]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fat]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[inode]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[msdos]]></category>
		<category><![CDATA[superblock]]></category>
		<category><![CDATA[vfat]]></category>
		<category><![CDATA[vfs]]></category>

		<guid isPermaLink="false">http://kaiwantech.wordpress.com/?p=102</guid>
		<description><![CDATA[A (small) part of the Linux VFS module of the Designer Graphix Linux Internals training programme. Referenced kernel ver: 2.6.30 Once extracted, see the fs/fat folder. _Tip:_ For ease of code browsing, do &#8216;make tags&#8217; (or &#8216;ctags -R&#8217;) in the root folder of the kernel soure tree. cd fs/fat Note: Here the focus is on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=102&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 2cm } 		P { margin-bottom: 0.21cm } 		H2 { margin-bottom: 0.21cm } 		A:link { so-language: zxx } --></p>
<h2>A (small) part of the <em>Linux VFS</em> module of the <a href="http://www.designergraphix.com/">Designer Graphix</a> Linux Internals training programme.</h2>
<p>Referenced kernel ver: 2.6.30</p>
<p>Once extracted, see the</p>
<pre> fs/fat</pre>
<p>folder.</p>
<p><em>_Tip:_</em><br />
For ease of code browsing, do &#8216;make tags&#8217; (or &#8216;ctags -R&#8217;) in the root folder of the kernel soure tree.</p>
<pre style="margin-bottom:.5cm;">cd fs/fat</pre>
<p><span style="text-decoration:underline;">Note:</span> Here the focus is on part of the MSDOS &#8211; Linux VFS kernel implementation, mainly the disk-related part, i.e., the superblock and inode objects. We don&#8217;t attempt to cover the Dcache/dentry, page cache (address operations) and just touch upon the process&lt;&#8211;&gt;filesystem relationship stuff (at least for now).</p>
<p><em>_Tip:_</em><br />
To gain some insight into the physical structure / arch of the MSDOS (and [v]fat) filesystem, <a href="http://en.wikipedia.org/wiki/File_Allocation_Table#Design">see this page</a>.<br />
The <em>&lt;linux/msdos_fs.h&gt;</em> header mirrors much of this.</p>
<p>For example, the FAT16 boot record (boot sector) structure is nicely <a href="http://home.teleport.com/~brainy/fat16.htm">seen here</a>; it&#8217;s Linux layout is here:<br />
<em>include/linux/msdos_fs.h:struct fat_boot_sector</em><br />
(can browse it via the superb <a href="http://lxr.linux.no/#linux+v2.6.30.5/include/linux/msdos_fs.h#L104">LXR tool here</a>).</p>
<p><strong>Superblock Setup</strong></p>
<p>In <em>namei_msdos.c</em>:</p>
<p><code><br />
...<br />
static struct file_system_type msdos_fs_type = {<br />
.owner          = THIS_MODULE,<br />
.name           = "msdos",<br />
.get_sb         = msdos_get_sb,<br />
.kill_sb        = kill_block_super,<br />
.fs_flags       = FS_REQUIRES_DEV,<br />
};</code></p>
<p>static int __init init_msdos_fs(void)<br />
{<br />
return register_filesystem(&amp;msdos_fs_type);<br />
}<br />
&#8230;</p>
<p><span id="more-102"></span>So, the routine invoked upon mounting is <em>msdos_get_sb </em>:</p>
<p style="margin-bottom:0;">Following the call chain in <span style="color:#0000ff;"><em>msdos_get_sb</em></span><em> </em>(see the flow diagram), control hits VFS <span style="color:#008000;"><em>fill_super</em></span> routine, which implicitly invokes the <span style="color:#0000ff;"><em>msdos_fill_super</em></span> routine (function pointer passed via a parameter). This is the MSDOS-filesystem-specific routine to initialize the superblock.</p>
<p style="margin-bottom:0;">&nbsp;</p>
<p><a href="http://kaiwantech.files.wordpress.com/2009/08/vfs_msdos_31.png"><img class="alignnone size-full wp-image-128" title="vfs msdos " src="http://kaiwantech.files.wordpress.com/2009/08/vfs_msdos_31.png?w=630" alt="vfs msdos "   /></a></p>
<p style="margin-bottom:0;">&nbsp;</p>
<p style="margin-bottom:0;">This invokes the <span style="color:#0000ff;"><em>fat_fill_super</em></span> routine which actually allocates memory for and initializes the MSDOS superblock structure – <span style="color:#800000;">struct msdos_sb_info</span> ; this is the data structure that MSDOS FS uses to map it&#8217;s filesystem superblock into the kernel&#8217;s VFS <span style="color:#800000;">struct super_block </span>structure. This routine reads from disk the MSDOS superblock, parses mount options, makes validity checks on the filesystem superblock, and finally intializes the structure.</p>
<p><code>...<br />
sb-&gt;s_magic = MSDOS_SUPER_MAGIC;<br />
sb-&gt;s_op = &amp;fat_sops;<br />
sb-&gt;s_export_op = &amp;fat_export_ops;<br />
<span style="color:#993300;">sbi</span>-&gt;dir_ops = fs_dir_inode_ops;<br />
<em> &lt;&lt; sbi is the </em><span style="color:#800000;"><em>msdos_sb_info </em></span><span style="color:#000000;"><em>structure &gt;&gt;</em></span><br />
...<br />
bh = <span style="color:#008000;">sb_bread</span>(sb, 0);           <em>&lt;&lt; Block read off disk, sector 0 - boot sector &gt;&gt;</em><br />
if (bh == NULL) {<br />
printk(KERN_ERR "FAT: unable to read boot sector\n");<br />
goto out_fail;<br />
}</code></p>
<p>b = (struct fat_boot_sector *) bh-&gt;b_data;<br />
&#8230;</p>
<p>sbi-&gt;cluster_size = sb-&gt;s_blocksize * sbi-&gt;sec_per_clus;       <em>&lt;&lt; Init msdos superblock &gt;&gt;</em><br />
sbi-&gt;cluster_bits = ffs(sbi-&gt;cluster_size) &#8211; 1;<br />
sbi-&gt;fats = b-&gt;fats;<br />
sbi-&gt;fat_bits = 0;              /* Don&#8217;t know yet */<br />
sbi-&gt;fat_start = le16_to_cpu(b-&gt;reserved);<br />
sbi-&gt;fat_length = le16_to_cpu(b-&gt;fat_length);<br />
sbi-&gt;root_cluster = 0;<br />
sbi-&gt;free_clusters = -1;        /* Don&#8217;t know yet */<br />
sbi-&gt;free_clus_valid = 0;<br />
sbi-&gt;prev_free = FAT_START_ENT;</p>
<p>if (!sbi-&gt;fat_length &amp;&amp; b-&gt;fat32_length) {<br />
struct fat_boot_fsinfo *fsinfo;<br />
struct buffer_head *fsinfo_bh;</p>
<p>/* Must be FAT32 */<br />
sbi-&gt;fat_bits = 32;<br />
sbi-&gt;fat_length = le32_to_cpu(b-&gt;fat32_length);<br />
sbi-&gt;root_cluster = le32_to_cpu(b-&gt;root_cluster);<br />
&#8230;</p>
<p style="margin-bottom:0;">&nbsp;</p>
<p style="margin-bottom:0;">It then sets up the root inode as well (including getting the superblock&#8217;s <em>s_root</em> field to point to the root inode.</p>
<p><code>...<br />
root_inode = <span style="color:#008000;">new_inode</span>(sb);<br />
if (!root_inode)<br />
goto out_fail;<br />
root_inode-&gt;i_ino = MSDOS_ROOT_INO;<br />
root_inode-&gt;i_version = 1;<br />
error = fat_read_root(root_inode);<br />
if (error &lt; 0)<br />
goto out_fail;<br />
error = -ENOMEM;<br />
insert_inode_hash(root_inode);<br />
sb-&gt;s_root = <span style="color:#008000;">d_alloc_root</span>(root_inode);<br />
...</code></p>
<h2><span style="font-size:small;"><strong>Inodes Setup</strong></span></h2>
<p style="margin-bottom:0;">The inode represents any kind of file object. However, the VFS distinguishes between inode operations to be enacted on a directory object versus those to be enacted on a regular file (I/O) object.</p>
<p style="margin-bottom:0;">So we have two &#8216;inode_operations&#8217; structures that the filesystem implements – one for directory operations – creation, deletion, lookup, rename, etc – anything that operates directly on a “directory” (think “.” file) object, and one &#8216;inode_operations&#8217; structure for actual file IO.</p>
<p style="margin-bottom:0;">&nbsp;</p>
<p style="margin-bottom:0;"><strong>Inode Create and Init<br />
</strong></p>
<p style="margin-bottom:0;">&nbsp;</p>
<p style="margin-bottom:0;">Whenever a new file is created, the filesystem has to allocate an inode. The &#8216;alloc_inode&#8217; method of the superblock&#8217;s super_operations does this.<br />
For MSDOS, we have (infs/fat/inode.c):</p>
<p><code><br />
static const struct super_operations fat_sops = {<br />
.<span style="color:#ff0000;">alloc_inode</span> = fat_alloc_inode,<br />
.destroy_inode  = fat_destroy_inode,<br />
.write_inode    = fat_write_inode,<br />
.delete_inode   = fat_delete_inode,<br />
.put_super      = fat_put_super,<br />
.write_super    = fat_write_super,<br />
.statfs         = fat_statfs,<br />
.clear_inode    = fat_clear_inode,<br />
.remount_fs     = fat_remount,<br />
.show_options   = fat_show_options,<br />
};</code></p>
<pre style="margin-bottom:0;">...</pre>
<p>The <em>fs/inode.c:new_inode()</em> routine is invoked to obtain a new inode.<br />
It in turn, invokes the <em>alloc_inode()</em> routine.<br />
<code><br />
static struct inode *alloc_inode(struct super_block *sb)<br />
{<br />
struct inode *inode;</code></p>
<p>if (sb-&gt;s_op-&gt;alloc_inode)<br />
inode = sb-&gt;s_op-&gt;alloc_inode(sb);<br />
else<br />
inode = kmem_cache_alloc(inode_cachep, GFP_KERNEL);</p>
<p>if (inode)<br />
return inode_init_always(sb, inode);<br />
return NULL;<br />
}<br />
So, we can see that <em>alloc_inode</em> invokes the filesystem-specific method from the filesystem&#8217;s superblock operations.<br />
This is the &#8216;<em>fat_alloc_inode</em>&#8216; method (see the fat_sops structure above):</p>
<p>In <em>fs/fat/inode.c</em> :<br />
<code>...<br />
static struct kmem_cache *fat_inode_cachep;</code></p>
<p>static struct inode *fat_alloc_inode(struct super_block *sb)<br />
{<br />
struct msdos_inode_info *ei;<br />
ei = kmem_cache_alloc(fat_inode_cachep, GFP_NOFS);<br />
if (!ei)<br />
return NULL;<br />
return &amp;ei-&gt;vfs_inode;<br />
}<br />
&#8230;<br />
<span style="font-style:normal;">Notice how a<em> custom slab cache</em> (to hold MSDOS inode objects) is used to rapidly perform the allocation (&amp; subsequent free back into the cache).</span></p>
<p><strong><br />
The MSDOS/FAT Directory Inode Operations</strong></p>
<p style="margin-bottom:0;">Initialize an inode:<br />
The &#8216;create&#8217; method of the file_operations structure, therefore, is setup to point to a method to do this for the particular filesystem implementation.</p>
<p style="margin-bottom:0;">So, we see in <em>fs/fat/namei_msdos.c </em><span style="font-style:normal;">:</span></p>
<pre><span style="font-style:normal;">static const struct </span><span style="color:#800000;"><span style="font-style:normal;">inode_operations msdos_dir_inode_operations </span></span><span style="font-style:normal;">= {</span>
        <span style="font-style:normal;">.</span><span style="color:#ff0000;"><span style="font-style:normal;">create         = msdos_create</span></span><span style="font-style:normal;">,</span>
        <span style="font-style:normal;">.lookup         = msdos_lookup,</span>
        <span style="font-style:normal;">.unlink         = msdos_unlink,</span>
        <span style="font-style:normal;">.mkdir          = msdos_mkdir,</span>
        <span style="font-style:normal;">.rmdir          = msdos_rmdir,</span>
        <span style="font-style:normal;">.rename         = msdos_rename,</span>
        <span style="font-style:normal;">.setattr        = fat_setattr,</span>
        <span style="font-style:normal;">.getattr        = fat_getattr,</span>
<span style="font-style:normal;">};</span>

<span style="font-style:normal;">static int msdos_fill_super(struct super_block *sb, void *data, int silent)</span>
<span style="font-style:normal;">{</span>
        <span style="font-style:normal;">int res;</span><span style="font-style:normal;"> </span>
        <span style="font-style:normal;">res = fat_fill_super(sb, data, silent, </span><span style="color:#800000;"><span style="font-style:normal;">&amp;msdos_dir_inode_operations</span></span><span style="font-style:normal;">, 0);</span>
<span style="font-style:normal;">...</span></pre>
<p style="margin-bottom:0;"><em>fs/fat/inode.c:</em></p>
<p style="margin-bottom:0;">&#8230;</p>
<p><code><br />
/*<br />
* Read the super block of an MS-DOS FS.<br />
*/<br />
int fat_fill_super(struct super_block *sb, void *data, int silent,<br />
const struct inode_operations *<span style="color:#800000;">fs_dir_inode_ops</span>, int isvfat)<br />
{<br />
...<br />
<span style="color:#ff0000;">sbi-&gt;dir_ops </span>= fs_dir_inode_ops;<br />
...</code></p>
<p style="margin-bottom:0;">&nbsp;</p>
<p style="margin-bottom:0;">If a userspace process attempts to create a new file on an MSDOS filesystem, the kernel VFS ultimately switches the request to the fs_dir_inode_ops function, in this case, the create method which is <em>msdos_create</em>.</p>
<p style="margin-bottom:0;">&nbsp;</p>
<p style="margin-bottom:0;"><strong>The MSDOS/FAT File Inode Operations</strong></p>
<p style="margin-bottom:0;">In <em>fs/fat/inode.</em>c :</p>
<p style="margin-bottom:0;">The <em>fat_fill_inode</em><span style="font-style:normal;"> routine [1] is the one responsible for initializing the inode, for both a directory object  as well as a non-directory object.</span></p>
<p><code>...<br />
/* doesn't deal with root inode */<br />
static int fat_fill_inode(struct inode *inode, struct <span style="color:#993300;">msdos_dir_entry</span> *de)<br />
{<br />
struct msdos_sb_info *sbi = MSDOS_SB(inode-&gt;i_sb);<br />
...<br />
if ((de-&gt;attr &amp; <span style="color:#ff0000;">ATTR_DIR</span>) &amp;&amp; !IS_FREE(de-&gt;name)) {<br />
inode-&gt;i_generation &amp;= ~1;<br />
inode-&gt;i_mode = <span style="color:#993300;">fat_make_mode</span>(sbi, de-&gt;attr, S_IRWXUGO);<br />
<span style="color:#ff0000;">inode-&gt;i_op = sbi-&gt;dir_ops;<br />
</span><span style="color:#ff0000;"><em> </em></span><span style="color:#000000;"><em>&lt;&lt; sbi-&gt;dir_ops is the same structure we saw above, viz,<br />
the msdos_dir_inode_operations structure. &gt;&gt;</em></span><br />
<span style="color:#ff0000;"> inode-&gt;i_fop = &amp;fat_dir_operations;<br />
</span><br />
...<br />
} else { /* not a directory */<br />
inode-&gt;i_generation |= 1;<br />
inode-&gt;i_mode = fat_make_mode(sbi, de-&gt;attr,<br />
((sbi-&gt;options.showexec &amp;&amp; !is_exec(de-&gt;name + 8))<br />
? S_IRUGO|S_IWUGO : S_IRWXUGO));<br />
MSDOS_I(inode)-&gt;i_start = le16_to_cpu(de-&gt;start);<br />
if (sbi-&gt;fat_bits == 32)<br />
MSDOS_I(inode)-&gt;i_start |= (le16_to_cpu(de-&gt;starthi) &lt;&lt; 16);</code></p>
<p>MSDOS_I(inode)-&gt;i_logstart = MSDOS_I(inode)-&gt;i_start;<br />
inode-&gt;i_size = le32_to_cpu(de-&gt;size);<br />
<span style="color:#ff0000;"> inode-&gt;i_op = &amp;fat_file_inode_operations;</span><br />
<span style="color:#ff0000;"> inode-&gt;i_fop = &amp;fat_file_operations;</span><br />
inode-&gt;i_mapping-&gt;a_ops = &amp;fat_aops;<br />
&#8230;</p>
<p style="margin-bottom:0;">It first switches on whether the &#8216;file object&#8217; to be created is a directory or not.<br />
Furthermore, as we can see above, the inode has two operation pointers:</p>
<p style="margin-bottom:0;">i_op: for the inode methods operating <span style="color:#ff0000;">on the inode object itself</span>, and</p>
<p style="margin-bottom:0;">i_fop: for the methods that operate <span style="color:#ff0000;">on the open file object </span>that the inode represents.</p>
<p style="margin-bottom:0;">In <em>fs/fat/file.c </em>:</p>
<p><code><span style="font-style:normal;">...</span><br />
const struct inode_operations <span style="font-style:normal;">fat_file_inode_operations</span> = {<br />
.truncate       = fat_truncate,<br />
.setattr        = fat_setattr,<br />
.getattr        = fat_getattr,<br />
};</code></p>
<p style="margin-bottom:0;">In <em>fs/fat/file.c </em><span style="font-style:normal;">:</span></p>
<p><code><span style="font-style:normal;">...</span><br />
const struct <span style="color:#ff0000;">file_operations fat_file_operations </span>= {<br />
.llseek         = generic_file_llseek,<br />
.read           = do_sync_read,<br />
.write          = do_sync_write,<br />
.aio_read       = generic_file_aio_read,<br />
.aio_write      = generic_file_aio_write,<br />
.mmap           = generic_file_mmap,<br />
.release        = fat_file_release,<br />
.ioctl          = fat_generic_ioctl,<br />
.fsync          = file_fsync,<br />
.splice_read    = generic_file_splice_read,<br />
}; </code></p>
<p>&#8230;</p>
<p style="margin-bottom:0;">These will be invoked via the usual VFS route (filp-&gt;f_op-&gt;<em>foo</em><span style="font-style:normal;">), where </span><em>foo</em><span style="font-style:normal;"> is the method – system call &#8211; invoked from the userspace process (or thread).</span></p>
<p style="margin-bottom:0;"><span style="font-style:normal;">In fact, we can see from the above implementation, that the MSDOS filesystem (and indeed all the FAT variants – MSDOS (FAT12), FAT16, FAT32 (VFAT)), </span><span style="color:#ff0000;"><span style="font-style:normal;">invoke the generic VFS methods </span></span><span style="font-style:normal;">for read, write, lseek, mmap and aio_[read|write].<br />
Which, of course, is in a large sense, the whole point: once the underlying filesystem &#8220;driver&#8221; (such as MSDOS or FAT) maps it&#8217;s physical structure to the kernel VFS expectations &#8211; to it&#8217;s (VFS&#8217;s) data structures, the kernel goes ahead and treats it as a (virtual) filesystem; I/O proceeds using the mechanisms built-in.<br />
</span></p>
<p style="margin-bottom:0;"><span style="font-style:normal;"><br />
</span></p>
<table border="1" cellspacing="0" cellpadding="4" width="100%">
<col width="85"></col>
<col width="85"></col>
<col width="85"></col>
<tbody>
<tr valign="top">
<td width="33%">
<pre style="text-align:center;"><span style="font-family:DejaVu Sans Mono,monospace;"><span style="font-size:x-small;"><em>VFS component</em></span></span></pre>
</td>
<td width="33%">
<pre style="text-align:center;"><span style="font-family:DejaVu Sans Mono,monospace;"><span style="font-size:x-small;"><em>Corr. MSDOS/FAT component</em></span></span></pre>
</td>
<td width="33%">
<pre style="text-align:center;"><span style="font-family:DejaVu Sans Mono,monospace;"><span style="font-size:x-small;"><em>Macro to access it</em></span></span></pre>
</td>
</tr>
<tr valign="top">
<td width="33%">
<pre><span style="font-family:DejaVu Sans Mono,monospace;"><span style="font-size:x-small;">struct super_block</span></span></pre>
</td>
<td width="33%">
<pre><span style="font-family:DejaVu Sans Mono,monospace;"><span style="font-size:x-small;">struct msdos_sb_info</span></span></pre>
</td>
<td width="33%">
<pre><span style="font-family:DejaVu Sans Mono,monospace;"><span style="font-size:x-small;">MSDOS_SB</span></span></pre>
</td>
</tr>
<tr valign="top">
<td width="33%">
<pre><span style="font-family:DejaVu Sans Mono,monospace;"><span style="font-size:x-small;">struct inode</span></span></pre>
</td>
<td width="33%">
<pre><span style="font-family:DejaVu Sans Mono,monospace;"><span style="font-size:x-small;">struct msdos_inode_info</span></span></pre>
</td>
<td width="33%">
<pre><span style="font-family:DejaVu Sans Mono,monospace;"><span style="font-size:x-small;">MSDOS_I</span></span></pre>
</td>
</tr>
</tbody>
</table>
<p><strong>[1] When does the <em>fat_fill_inode </em>routine get invoked?</strong></p>
<p>The <em>fat_build_inode</em><span style="font-style:normal;"> function invokes it. So what invokes </span><em>fat_build_inode</em><span style="font-style:normal;"> ?</span></p>
<p><span style="font-style:normal;">cscope can provide us with an answer (output below, on the 2.6.30 kernel):</span></p>
<p><span style="font-size:x-small;"><span style="font-style:normal;">Functions calling this function: fat_build_inode </span></span></p>
<p><span style="font-style:normal;"> </span></p>
<pre style="margin-bottom:.5cm;">  <em>File          Function       Line</em>
<span style="font-style:normal;">0 inode.c       fat_get_parent 752 inode = fat_build_inode(sb, de, i_pos);</span>
<span style="font-style:normal;">1 namei_msdos.c msdos_lookup   220 inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);</span>
<span style="font-style:normal;">2 namei_msdos.c msdos_create   306 inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);</span>
<span style="font-style:normal;">3 namei_msdos.c msdos_mkdir    394 inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);</span>
<span style="font-style:normal;">4 namei_vfat.c  vfat_lookup    732 inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);</span>
<span style="font-style:normal;">5 namei_vfat.c  vfat_create    788 inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);</span>
<span style="font-style:normal;">6 namei_vfat.c  vfat_mkdir     882 inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);</span></pre>
<p style="margin-bottom:0;">&nbsp;</p>
<p style="margin-bottom:0;border:medium medium 1px none none solid 0 0 #000000;padding:0 0 .07cm;">&nbsp;</p>
<p style="margin-bottom:0;">&nbsp;</p>
<p><em>(c) 2009 Kaiwan N Billimoria, Designer Graphix.<br />
</em></p>
<br />Posted in Linux Kernel, Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kaiwantech.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kaiwantech.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kaiwantech.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kaiwantech.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kaiwantech.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kaiwantech.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kaiwantech.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kaiwantech.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kaiwantech.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kaiwantech.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kaiwantech.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kaiwantech.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kaiwantech.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kaiwantech.wordpress.com/102/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=102&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kaiwantech.wordpress.com/2009/08/17/inside-the-msdos-fat-linux-vfs-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5216008e0b231a760d20d22b01c4328?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kaiwan</media:title>
		</media:content>

		<media:content url="http://kaiwantech.files.wordpress.com/2009/08/vfs_msdos_31.png" medium="image">
			<media:title type="html">vfs msdos </media:title>
		</media:content>
	</item>
		<item>
		<title>Android&#8217;s already looking successful; but &#8230;</title>
		<link>http://kaiwantech.wordpress.com/2009/05/28/androids-already-looking-successful-but/</link>
		<comments>http://kaiwantech.wordpress.com/2009/05/28/androids-already-looking-successful-but/#comments</comments>
		<pubDate>Thu, 28 May 2009 12:03:17 +0000</pubDate>
		<dc:creator>Kaiwan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[strategy]]></category>

		<guid isPermaLink="false">http://kaiwantech.wordpress.com/?p=98</guid>
		<description><![CDATA[Android&#8217;s steaming ahead. Yup. Pretty much a given.. Google says we&#8217;ll easily have around 18 Android &#8216;phones by year end. So? Please read this excellent NY Times article first (opens in a new window), and then continue here, if it so pleases you&#8230; Well, I don&#8217;t know about you but am a bit taken aback [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=98&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Android&#8217;s steaming ahead.</p>
<p>Yup. Pretty much a given..</p>
<p>Google says we&#8217;ll easily have around 18 Android &#8216;phones by year end.<br />
So?</p>
<p>Please read <a href="http://bits.blogs.nytimes.com/2009/05/27/google-expect-18-android-phones-by-years-end/" target="_blank">this excellent NY Times article</a> first (opens in a new window), and then continue here, if it so pleases you&#8230;</p>
<p>Well, I don&#8217;t know about you but am a bit taken aback by (Google&#8217;s) Andy Rubin&#8217;s statement regarding the three options that handset OEMs and wireless carriers have.</p>
<p>In effect, the first options says (and I&#8217;d love someone to correct me if i&#8217;m reading it wrong here)- take it completely free but don&#8217;t touch (preload) our (Google) apps; the second &#8220;small strings&#8221; option says- sign a distribution agreement with us and all&#8217;s cool. Hmm, can we see this agreement? Third option &#8220;no-censorship&#8221; aka “The Google Experience” phones- so, looks like there <em>is</em> after all, a Google Phone <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  . Right? I mean, Google logo on the device and all.</p>
<p>Initially my impression was that Google is indeed trying to &#8220;distance&#8221; itself from the platform. &#8220;Hey, it&#8217;s open- we built it, now do what you like okay&#8221;. Now that, apparently, looks to be not-so-true.</p>
<p>Still, this is not necessarily &#8220;a bad thing&#8221;. Okay Google is (starting to) leveraging it&#8217;s considerable strength with Android. It&#8217;s still an open platform. Yes. But&#8230; one just wonders..</p>
<p>Well, we&#8217;ll wait and see&#8230;<br />
hope to keep you posted!</p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kaiwantech.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kaiwantech.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kaiwantech.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kaiwantech.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kaiwantech.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kaiwantech.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kaiwantech.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kaiwantech.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kaiwantech.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kaiwantech.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kaiwantech.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kaiwantech.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kaiwantech.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kaiwantech.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=98&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kaiwantech.wordpress.com/2009/05/28/androids-already-looking-successful-but/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5216008e0b231a760d20d22b01c4328?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kaiwan</media:title>
		</media:content>
	</item>
		<item>
		<title>Motorola and Android Newly Weds</title>
		<link>http://kaiwantech.wordpress.com/2009/05/27/motorola-and-android-newly-wed/</link>
		<comments>http://kaiwantech.wordpress.com/2009/05/27/motorola-and-android-newly-wed/#comments</comments>
		<pubDate>Wed, 27 May 2009 02:59:42 +0000</pubDate>
		<dc:creator>Kaiwan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kaiwantech.wordpress.com/?p=94</guid>
		<description><![CDATA[Well, it was bound to happen, everyone knows that. Now it&#8217;s &#8220;official&#8221;. Motorola is newly wed to the Android platform. They&#8217;ve put up a nice aggregate (tutorials, etc) site. So far, I have not (personally) seen/used a really great Android phone (or device). In the hardware sense of course (the software platform simply rocks!). I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=94&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Well, it was bound to happen, everyone knows that.</p>
<p>Now it&#8217;s &#8220;official&#8221;.</p>
<p>Motorola is newly wed to the Android platform.</p>
<p>They&#8217;ve put up a nice aggregate (tutorials, etc) <a href="http://tinyurl.com/qo8ykl">site</a>.</p>
<p>So far, I have not (personally) seen/used a really great Android phone (or device). In the hardware sense of course (the software platform simply rocks!). I mean, the camera on the G1 (I use the ADP1, completely equivalent) is terrible when I compare it with a Nokia N-series phone, for example&#8230;</p>
<p>I think this limitation will now be addressed: Samsung already has an Android smartphone out, now Motorola looks set to release one this year; interestingly, Motorola definitely seems to be looking to leverage the vast open-source community already around the Android platform via their developer site. Good going! -much much nicer than what they did at first with their (early) Motorola-Linux platform(s).</p>
<p>We wish them luck. The more the merrier. The better it gets- for Android, the OEMs, and of course, us.</p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kaiwantech.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kaiwantech.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kaiwantech.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kaiwantech.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kaiwantech.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kaiwantech.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kaiwantech.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kaiwantech.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kaiwantech.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kaiwantech.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kaiwantech.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kaiwantech.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kaiwantech.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kaiwantech.wordpress.com/94/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=94&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kaiwantech.wordpress.com/2009/05/27/motorola-and-android-newly-wed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5216008e0b231a760d20d22b01c4328?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kaiwan</media:title>
		</media:content>
	</item>
		<item>
		<title>My Android Presentations&#8230;</title>
		<link>http://kaiwantech.wordpress.com/2009/05/27/my-android-presentations/</link>
		<comments>http://kaiwantech.wordpress.com/2009/05/27/my-android-presentations/#comments</comments>
		<pubDate>Wed, 27 May 2009 02:51:37 +0000</pubDate>
		<dc:creator>Kaiwan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[android presentation kaiwan designergraphix]]></category>

		<guid isPermaLink="false">http://kaiwantech.wordpress.com/?p=92</guid>
		<description><![CDATA[I&#8217;ve had the privilege of presenting my &#8220;Android &#8211; Get With It!&#8221; talk twice in the last week; once at ARM Embedded Systems and once at CISCO, Bangalore. Was appreciated in general&#8230; Some details. Posted in Uncategorized<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=92&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had the privilege of presenting my &#8220;Android &#8211; Get With It!&#8221; talk twice in the last week; once at ARM Embedded Systems and once at CISCO, Bangalore.</p>
<p>Was appreciated in general&#8230;<br />
<a href="http://www.designergraphix.com/android-platform/"> Some details</a>.</p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kaiwantech.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kaiwantech.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kaiwantech.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kaiwantech.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kaiwantech.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kaiwantech.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kaiwantech.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kaiwantech.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kaiwantech.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kaiwantech.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kaiwantech.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kaiwantech.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kaiwantech.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kaiwantech.wordpress.com/92/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=92&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kaiwantech.wordpress.com/2009/05/27/my-android-presentations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5216008e0b231a760d20d22b01c4328?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kaiwan</media:title>
		</media:content>
	</item>
		<item>
		<title>Most Useful Android Apps</title>
		<link>http://kaiwantech.wordpress.com/2009/05/04/most-useful-android-apps/</link>
		<comments>http://kaiwantech.wordpress.com/2009/05/04/most-useful-android-apps/#comments</comments>
		<pubDate>Mon, 04 May 2009 11:50:19 +0000</pubDate>
		<dc:creator>Kaiwan</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[apps]]></category>
		<category><![CDATA[best]]></category>

		<guid isPermaLink="false">http://kaiwantech.wordpress.com/?p=89</guid>
		<description><![CDATA[Very useful app- ASTRO File Manager &#8211; as one can backup all existing installed apps onto the SD card and (re)install them from there.. Also realize that apps that sync data online are the way to go.. So, among my Best Android Apps are: Built-in: Contacts (w/ gmail), gmail, (google) calendar, Sync: 3Banana, twitdroid. LBS: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=89&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Very useful app- ASTRO File Manager &#8211; as one can backup all existing installed apps onto the SD card and (re)install them from there..<br />
Also realize that apps that sync data online are the way to go..</p>
<p><em>So, among my Best Android Apps are:</em><br />
Built-in: Contacts (w/ gmail), gmail, (google) calendar,<br />
Sync: 3Banana, twitdroid.<br />
LBS: GPS Status, MyTracks, Compass, SnapPhoto,<br />
Misc: ASTRO, Useful Switchers, ToggleBlu</p>
<p>More to follow&#8230;</p>
<p>Ok, an update (6 Oct &#8217;09):</p>
<p>Widgets:</p>
<p>Internal Memory Widget : useful to see how much space remains on internal flash (as all apps get installed there).</p>
<p>MoonPhase : as it says, and really done nicely.</p>
<p><span id="more-89"></span>Retro Clock &amp; Date : &#8230;neat.</p>
<p>PowerManager : wow. Just what the doc ordered; really helps when your batt is low&#8230; of course you can create/edit power profiles. A must!</p>
<p>LastPass : the final word on &#8220;not having to remember those damned username/password pairs ever again&#8221;! Love it! Make sure you use it in Firefox/IE as well&#8230;</p>
<p>MyBackup : looks good, have yet to test restore&#8230;</p>
<p>Proxoid: I use this to tether my phone to the PC so I can browse via the phone&#8217;s GPRS conection&#8230;<br />
works well on Linux!</p>
<p>ContactSender : Very unfortunately, Android (&amp; it seems Linux-based phones in general) can&#8217;t seem to understand the Vcard protocol for sharing contacts (hope I&#8217;m wrong here, pl tell me if so!). So this guy at least lets you conveniently send an SMS to someone w/ the contact info you pick.</p>
<p>Quick Uninstall</p>
<p>SkyMap : wow. Trust google.</p>
<p>Wapedia : really fast wikipedia browser, good no-nonsense UI too.</p>
<p>ToddlerLock : awesome for small kids who can&#8217;t keep their paws off!</p>
<p>ShopSavvy :</p>
<p>Wikitude : both Wows! A little over the top but hey it&#8217;s the future dude!</p>
<p>Know of other awesome apps? Pl comment now!</p>
<br />Posted in Android  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kaiwantech.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kaiwantech.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kaiwantech.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kaiwantech.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kaiwantech.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kaiwantech.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kaiwantech.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kaiwantech.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kaiwantech.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kaiwantech.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kaiwantech.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kaiwantech.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kaiwantech.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kaiwantech.wordpress.com/89/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=89&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kaiwantech.wordpress.com/2009/05/04/most-useful-android-apps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5216008e0b231a760d20d22b01c4328?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kaiwan</media:title>
		</media:content>
	</item>
		<item>
		<title>LINUX CHEATSHEET &#8211; vmstat, ps, top</title>
		<link>http://kaiwantech.wordpress.com/2009/04/29/linux-cheatsheet-vmstat-ps-top/</link>
		<comments>http://kaiwantech.wordpress.com/2009/04/29/linux-cheatsheet-vmstat-ps-top/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 01:48:59 +0000</pubDate>
		<dc:creator>Kaiwan</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[SysAd]]></category>
		<category><![CDATA[cheatsheet]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[proc]]></category>
		<category><![CDATA[ps]]></category>
		<category><![CDATA[top]]></category>
		<category><![CDATA[vmstat]]></category>

		<guid isPermaLink="false">http://kaiwantech.wordpress.com/?p=80</guid>
		<description><![CDATA[LINUX Quick Reference Cheat Sheet vmstat, ps, top v 0.1 : Last Updated: March 2009 : &#60;kaiwan at designergraphix dot com&#62; (c) kaiwan billimoria. Much of the information below gleaned from various Linux man pages. &#160; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- vmstat vmstat fields quick reference The -a switch displays active/inactive memory, given a 2.5.41 kernel or better. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=80&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><!-- 	 	 --></p>
<h1 style="text-align:center;"><strong>LINUX Quick Reference Cheat Sheet</strong></h1>
<h2 style="text-align:center;"><strong>vmstat, ps, top</strong></h2>
<p><strong><br />
</strong><strong>v 0.1 </strong>: Last Updated: March 2009<strong> : &lt;</strong>kaiwan at designergraphix dot com<strong>&gt;<br />
</strong>(c) kaiwan billimoria.</p>
<p style="text-align:left;"><em>Much of the information below gleaned from various Linux man pages.</em></p>
<p style="text-align:left;">&nbsp;</p>
<h2 style="text-align:left;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</h2>
<h2 style="text-align:left;">vmstat</h2>
<p><!-- 	 	 --></p>
<p><strong><em>vmstat </em>fields quick reference</strong></p>
<p>The <strong>-a</strong> switch displays active/inactive memory, given a 2.5.41 kernel or better.<br />
The <strong>-f</strong> switch displays the number of forks since boot. This includes the fork, vfork, and clone system calls, and is equivalent to the total number of tasks created. Each process is represented by one or more tasks, depending on thread usage. This display does not repeat.<br />
The <strong>-m</strong> displays slabinfo.<br />
The <strong>-n</strong> switch causes the header to be displayed only once rather than periodically.<br />
The <strong>-s</strong> switch displays a table of various event counters and memory statistics. This display does not repeat.</p>
<p><em>delay</em> is the delay between updates in seconds. If no delay is specified, only one report is printed with<br />
the average values since boot.<br />
<em>count</em> is the number of updates. If no count is specified and delay is defined, <em>count</em> defaults to infinity.</p>
<p>The <strong>-d</strong> reports disk statistics (2.5.70 or above required)<br />
The <strong>-p</strong> followed by some partition name for detailed statistics (2.5.70 or above required)<br />
The <strong>-S</strong> followed by k or K or m or M switches outputs between 1000, 1024, 1000000, or 1048576 bytes<br />
The <strong>-V</strong> switch results in displaying version information.</p>
<h2>FIELD DESCRIPTION FOR VM MODE</h2>
<h2><strong>Procs</strong></h2>
<pre>r: The number of processes waiting for run time &lt;&lt; ready-to-run &gt;&gt;.
b: The number of processes in uninterruptible sleep &lt;&lt; blocked &gt;&gt;.</pre>
<h3><strong>Memory</strong> &lt;&lt; (default) in kilobytes &gt;&gt;<br />
swpd: the amount of virtual memory used.</h3>
<pre>free: the amount of idle memory.
buff: the amount of memory used as buffers.
cache: the amount of memory used as cache &lt;&lt; page cache, not incl. swap cache&gt;&gt; .
inact: the amount of inactive memory. (-a option)
active: the amount of active memory. (-a option)</pre>
<h3><strong>Swap</strong> &lt;&lt; in kilobytes/second &gt;&gt;</h3>
<pre>si: Amount of memory swapped in from disk (/s).
so: Amount of memory swapped to disk (/s).
<span id="more-80"></span></pre>
<p><!-- 	 	 --></p>
<h3><strong>IO</strong> &lt;&lt; in blocks/second &gt;&gt;</h3>
<pre>bi: Blocks received from a block device (blocks/s).
bo: Blocks sent to a block device (blocks/s).</pre>
<h3><strong>System</strong> &lt;&lt; &#8216;in&#8217; and &#8216;cs&#8217; are per second &gt;&gt;<br />
in: The number of interrupts per second, including the clock.</h3>
<pre>cs: The number of context switches per second.

<strong>CPU</strong> These are percentages of total CPU time.
us: Time spent running non-kernel code. (user time, including nice time)
sy: Time spent running kernel code. (system time)
id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.

<strong>FIELD DESCRIPTION FOR DISK MODE </strong>
   <strong>Reads </strong>
       total: Total reads completed successfully
       merged: grouped reads (resulting in one I/O)
       sectors: Sectors read successfully
       ms: milliseconds spent reading 

   <strong>Writes </strong>
       total: Total writes completed successfully
       merged: grouped writes (resulting in one I/O)
       sectors: Sectors written successfully
       ms: milliseconds spent writing 

   <strong>IO </strong>
       cur: I/O in progress
       s: seconds spent for I/O 

<strong>FIELD DESCRIPTION FOR DISK PARTITION MODE </strong>
       reads: Total number of reads issued to this partition
       read sectors: Total read sectors for partition
       writes : Total number of writes issued to this partition
       requested writes: Total number of write requests made for partition 

<strong>FIELD DESCRIPTION FOR SLAB MODE </strong>
       cache: Cache name
       num: Number of currently active objects
       total: Total number of available objects
       size: Size of each object
       pages: Number of pages with at least one active object
       totpages: Total number of allocated pages
       pslab: Number of pages per slab</pre>
<h2 style="text-align:left;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</h2>
<p><!-- 	 	 --></p>
<h2><!--more--></h2>
<h2>ps</h2>
<p><em><strong>ps</strong></em><strong> fields quick reference</strong></p>
<p>The &#8216;usual&#8217;:</p>
<p>ps -Aef[ww]</p>
<p>ps aux[ww][f]<br />
To print a process tree:</p>
<p>ps -ejH</p>
<p>ps axjf</p>
<p>Signal information:</p>
<p>ps s<br />
To get info about threads:</p>
<p>ps -eLf<br />
ps axH<br />
ps axms</p>
<p>THREAD DISPLAY</p>
<p>H               Show threads as if they were processes</p>
<p>-L              Show threads, possibly with LWP and NLWP columns</p>
<p>-T              Show threads, possibly with SPID column</p>
<p>m               Show threads after processes</p>
<p>-m              Show threads after processes<br />
OTHER INFORMATION</p>
<p>L               List all format specifiers.</p>
<p>-V              Print the procps version.<br />
The output from the ps au option is displayed in the following columns:</p>
<p>USER is the username for the running process.</p>
<p>PID is the process ID.</p>
<p>%CPU is the CPU utilization.</p>
<p>%MEM is the memory utilization.</p>
<p>VSZ is the virtual memory size.</p>
<p>RSS is the resident set sizethe number of kilobytes of program in memory.</p>
<p>TTY specifies which terminal the process was started from.</p>
<p>STAT is the process state.</p>
<p>START is the start time.</p>
<p>TIME is the execution time.</p>
<p>COMMAND is the command name.<br />
PROCESS STATE CODES</p>
<p>Here are the different values that the s, stat and state output</p>
<p>specifiers (header &#8220;STAT&#8221; or &#8220;S&#8221;) will display to describe the state of</p>
<p>a process.</p>
<p>D    Uninterruptible sleep (usually IO)</p>
<p>R    Running or runnable (on run queue)</p>
<p>S    Interruptible sleep (waiting for an event to complete)</p>
<p>T    Stopped, either by a job control signal or because it is being</p>
<p>traced.</p>
<p>W    paging (not valid since the 2.6.xx kernel)</p>
<p>X    dead (should never be seen)</p>
<p>Z    Defunct (&#8220;zombie&#8221;) process, terminated but not reaped by its</p>
<p>parent.<br />
For BSD formats and when the stat keyword is used, additional</p>
<p>characters may be displayed:</p>
<p>&lt;    high-priority (not nice to other users)</p>
<p>N    low-priority (nice to other users)</p>
<p>L    has pages locked into memory (for real-time and custom IO)</p>
<p>s    is a session leader</p>
<p>l    is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)</p>
<p>+    is in the foreground process group</p>
<p>wchan     WCHAN  name of the kernel function in which the process is sleeping, a &#8220;-&#8221; if the process is running, or a &#8220;*&#8221; if the process is multi-threaded and ps is not displaying threads.</p>
<h2 style="text-align:left;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</h2>
<p><strong><em>/proc/meminfo</em> fields quick reference</strong></p>
<p>MemTotal  		Total usable RAM.</p>
<p>MemFree  		The sum of LowFree + HighFree.</p>
<p>Buffers  		Memory in the buffer cache.</p>
<p>Cached  		Memory in the page cache (doesn&#8217;t SwapCache).</p>
<p>SwapCached  		Memory that once was swapped out.</p>
<p>Active  			Memory that has been used more recently and usually is not 			reclaimed unless absolutely necessary.</p>
<p>Inactive  		Memory that has been less recently used.<br />
HighTotal  		The total amount of memory in the high region. Highmem is 			all memory above (approximately) 860 MB of physical RAM.</p>
<p>HighFree  		High region free memory.</p>
<p>LowTotal  		The total amount of non-highmem memory.</p>
<p>LowFree  		The amount of free memory in the low memory region.</p>
<p>SwapTotal  		The total amount of swap memory.</p>
<p>SwapFree  		The total amount of free swap memory.</p>
<p>Dirty  			Memory waiting to get written back to the disk.</p>
<p>Writeback  		Memory that is actively being written back to the disk.</p>
<p>Mapped  		Files that have been mmapped.</p>
<p>Slab  			In-kernel data structures cache.</p>
<p>Committed_AS  	An estimate of how much RAM is needed to make a 99.99%  guarantee that there is never an OOM (out of memory) for this workload. Normally the kernel overcommits memory. So if you do a 1 GB malloc, for example, nothing happens, really. Only when you start using that malloc memory do you get real memory on demand, and just as much as needed. Other cases might include when a file is mmapped that&#8217;s shared only when a write to the file occurs and a private copy of that data is created. Normally it is shared between processes. The Committed_AS is a guesstimate of how much RAM/swap is needed in the worst case.<br />
PageTables  		The amount of memory dedicated to the lowest level of page tables.</p>
<p>VmallocTotal  		The total size of the vmalloc memory area.</p>
<p>VmallocUsed  		The amount of vmalloc area that is used.</p>
<p>VmallocChunk  		The largest contiguous block of vmalloc area that is free.<br />
/proc/&lt;pid&gt;/tasks : threads of process &lt;pid&gt;</p>
<p><em><strong><br />
Hardware information</strong></em></p>
<p>/proc/bus/*/devices</p>
<p>lspci</p>
<p>lsusb</p>
<p>lshw         (Ubuntu specific?)</p>
<p>lshal         (Ubuntu specific?)</p>
<p>lspcmcia</p>
<p>/sys</p>
<h2 style="text-align:left;">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</h2>
<p><!-- 	 	 --></p>
<h2>top</h2>
<p><strong><em>top </em>fields quick reference</strong></p>
<p>A : toggles multiple windows display</p>
<p>Z : colour changes</p>
<p><strong>1. COMMAND-LINE Options </strong></p>
<p>The command-line syntax for top consists of:</p>
<p>-hv | -bcHisS -d delay -n iterations -p pid [,pid...]</p>
<p>The typically mandatory switches (&#8216;-&#8217;) and even whitespace are completely optional.</p>
<p>-b : Batch mode operation</p>
<p>Starts top  in  &#8216;Batch mode&#8217;, which could be useful for sending output from top to other programs or to a file. In this</p>
<p>mode, top will not accept input and runs until the iterations limit you&#8217;ve set with the &#8216;-n&#8217; command-line option or until killed.</p>
<p>-c : Command line/Program name toggle</p>
<p>Starts  top  with the last remembered &#8216;c&#8217; state reversed.  Thus, if top was displaying command lines, now that field will show program names, and visa versa.  See the &#8216;c&#8217; interactive command for additional information.</p>
<p>-d : Delay time interval as:  -d ss.tt (seconds.tenths)</p>
<p>Specifies the delay between screen updates, and overrides the corresponding value in one&#8217;s personal configuration file or the startup default.  Later this can be changed with the &#8216;d&#8217; or &#8216;s&#8217; interactive commands.</p>
<p>Fractional seconds are honored, but a negative number is not allowed.  In all cases, however, such changes are prohibited if top is running in &#8216;Secure mode&#8217;, except for root (unless the &#8216;s&#8217; command-line option was used).  For additional information on &#8216;Secure mode&#8217; see topic 5a. SYSTEM Configuration File.</p>
<p>-h : Help</p>
<p>Show library version and the usage prompt, then quit.</p>
<p>-H : Threads toggle</p>
<p>Starts  top  with  the  last  remembered &#8216;H&#8217; state reversed.  When this toggle is On, all individual threads will be displayed.  Otherwise, top displays a summation of all threads in a process.</p>
<p>-i : Idle Processes toggle</p>
<p>Starts top with the last remembered &#8216;i&#8217; state reversed.  When this toggle is Off, tasks that are idled  or  zombied  will not be displayed.</p>
<p>-n : Number of iterations limit as:  -n number</p>
<p>Specifies the maximum number of iterations, or frames, top should produce before ending.</p>
<p>-u : Monitor by user as:  -u somebody</p>
<p>Monitor only processes with an effective UID or user name matching that given.<br />
-U : Monitor by user as:  -U somebody</p>
<p>Monitor  only processes with a UID or user name matching that given.  This matches real, effective, saved, and filesystem UIDs.</p>
<p>-p : Monitor PIDs as:  -pN1 -pN2 &#8230;  or  -pN1, N2 [,...]</p>
<p>Monitor only processes with specified process IDs.  This option can be given up to 20 times, or you can provide  a  comma delimited list with up to 20 pids.  Co-mingling both approaches is permitted.</p>
<p>This  is  a command-line option only.  And should you wish to return to normal operation, it is not necessary to quit and and restart top  &#8212;  just issue the &#8216;=&#8217; interactive command.</p>
<p>-s : Secure mode operation</p>
<p>Starts top with secure mode forced, even for root.  This mode is far better controlled through the  system  configuration file (see topic 5. FILES).</p>
<p>-S : Cumulative time mode toggle</p>
<p>Starts  top  with  the last remembered &#8216;S&#8217; state reversed.  When &#8216;Cumulative mode&#8217; is On, each process is listed with the cpu time that it and its dead children have used.  See the &#8216;S&#8217; interactive command for additional  information  regarding this mode.<br />
-v : Version</p>
<p>Show library version and the usage prompt, then quit.</p>
<p><strong>2. FIELDS / Columns</strong></p>
<p><strong>2a. DESCRIPTIONS of Fields </strong></p>
<p>Listed below are top&#8217;s available fields.  They are always associated with the letter shown, regardless of the position you may have established for them with the &#8216;o&#8217; (Order fields) interactive command.</p>
<p>Any field is selectable as the sort field, and you control whether they are sorted high-to-low or low-to-high.  For additional information on sort provisions see topic 3c. TASK Area Commands.</p>
<p>a: PID  &#8212;  Process Id</p>
<p>The task&#8217;s unique process ID, which periodically wraps, though never restarting at zero.</p>
<p>b: PPID  &#8212;  Parent Process Pid</p>
<p>The process ID of a task&#8217;s parent.</p>
<p>c: RUSER  &#8212;  Real User Name</p>
<p>The real user name of the task&#8217;s owner.</p>
<p>d: UID  &#8212;  User Id</p>
<p>The effective user ID of the task&#8217;s owner.</p>
<p>e: USER  &#8212;  User Name</p>
<p>The effective user name of the task&#8217;s owner.</p>
<p>f: GROUP  &#8212;  Group Name</p>
<p>The effective group name of the task&#8217;s owner.</p>
<p>g: TTY  &#8212;  Controlling Tty</p>
<p>The  name  of  the  controlling  terminal.   This is usually the device (serial port, pty, etc.) from which the process was started, and which it uses for input or output.  However, a task need not be associated with  a  terminal,  in  which  case you&#8217;ll see &#8216;?&#8217; displayed.</p>
<p>h: PR  &#8212;  Priority</p>
<p>The priority of the task.</p>
<p>i: NI  &#8212;  Nice value</p>
<p>The  nice value of the task.  A negative nice value means higher priority, whereas a positive nice value means lower priority.  Zero in this field simply means priority will not be adjusted in determining a task&#8217;s dispatchability.</p>
<p>j: P  &#8212;  Last used CPU (SMP)</p>
<p>A number representing the last used processor.  In a true SMP environment this will likely change frequently since the kernel  intentionally  uses weak affinity.  Also, the very act of running top may break this weak affinity and cause more processes to change CPUs more often (because of the extra demand for cpu time).</p>
<p>k: %CPU  &#8212;  CPU usage</p>
<p>The task&#8217;s share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.  In a true SMP environment, if &#8216;Irix mode&#8217; is Off, top will operate in &#8216;Solaris mode&#8217; where a task&#8217;s cpu usage will be divided by the total number of CPUs.  You toggle &#8216;Irix/Solaris&#8217; modes with the &#8216;I&#8217; interactive command.</p>
<p>l: TIME  &#8212;  CPU Time</p>
<p>Total CPU time the task has used since it started.  When &#8216;Cumulative mode&#8217; is On, each process is listed with the cpu  time that  it  and  its  dead  children  has used.  You toggle &#8216;Cumulative mode&#8217; with &#8216;S&#8217;, which is a command-line option and an interactive command.  See the &#8216;S&#8217; interactive command for additional information regarding this mode.</p>
<p>m: TIME+  &#8212;  CPU Time, hundredths</p>
<p>The same as &#8216;TIME&#8217;, but reflecting more granularity through hundredths of a second.</p>
<p>n: %MEM  &#8212;  Memory usage (RES)</p>
<p>A task&#8217;s currently used share of available physical memory.</p>
<p>o: VIRT  &#8212;  Virtual Image (kb)</p>
<p>The total amount of virtual memory used by the task.  It includes all code, data and shared libraries plus pages that  have been swapped out.</p>
<p>VIRT = SWAP + RES.</p>
<p>p: SWAP  &#8212;  Swapped size (kb)</p>
<p>The swapped out portion of a task&#8217;s total virtual memory image.</p>
<p>q: RES  &#8212;  Resident size (kb)</p>
<p>The non-swapped physical memory a task has used.</p>
<p>RES = CODE + DATA.</p>
<p>r: CODE  &#8212;  Code size (kb)</p>
<p>The amount of physical memory devoted to executable code, also known as the &#8216;text resident set&#8217; size or TRS.</p>
<p>s: DATA  &#8212;  Data+Stack size (kb)</p>
<p>The amount of physical memory devoted to other than executable code, also known as the &#8216;data resident set&#8217; size or DRS.</p>
<p>t: SHR  &#8212;  Shared Mem size (kb)</p>
<p>The  amount  of  shared  memory used by a task.  It simply reflects memory that could be potentially shared with other processes.</p>
<p>u: nFLT  &#8212;  Page Fault count</p>
<p>The number of major page faults that have occurred for a task.  A page fault occurs when a process attempts to read from or write  to  a  virtual  page that is not currently present in its address space.  A major page fault is when backing storage access (such as a disk) is involved in making that page available.</p>
<p>v: nDRT  &#8212;  Dirty Pages count</p>
<p>The number of pages that have been modified since they were last written to disk.  Dirty pages  must  be  written  to  disk before the corresponding physical memory location can be used for some other virtual page.</p>
<p>w: S  &#8212;  Process Status</p>
<p>The status of the task which can be one of:</p>
<p>&#8216;D&#8217; = uninterruptible sleep</p>
<p>&#8216;R&#8217; = running</p>
<p>&#8216;S&#8217; = sleeping</p>
<p>&#8216;T&#8217; = traced or stopped</p>
<p>&#8216;Z&#8217; = zombie</p>
<p>Tasks shown as running should be more properly thought of as &#8216;ready to run&#8217;  &#8212;  their task_struct is simply represented on the Linux run-queue.  Even without a true SMP machine, you may see numerous tasks in this state depending  on  top&#8217;s  delay interval and nice value.</p>
<p>x: Command  &#8212;  Command line or Program name</p>
<p>Display  the  command line used to start a task or the name of the associated program.  You toggle between command line and name with &#8216;c&#8217;, which is both a command-line option and an interactive command.</p>
<p>When you&#8217;ve chosen to display command lines, processes without a command line (like kernel threads) will be shown with only the program name in parentheses, as in this example:                ( mdrecoveryd )</p>
<p><!-- 	 	 --></p>
<p>Either  form  of  display  is  subject to potential truncation if it&#8217;s too long to fit in this field&#8217;s current width.  That width depends upon other fields selected, their order and the current screen width.</p>
<p>Note: The &#8216;Command&#8217; field/column is unique, in that it is not fixed-width.  When displayed, this column will  be  allocated all  remaining  screen  width  (up to the maximum 512 characters) to provide for the potential growth of program names into command lines.</p>
<p>y: WCHAN  &#8212;  Sleeping in Function</p>
<p>Depending on the availability of the kernel link map (&#8216;System.map&#8217;), this field will show the name or the  address  of  the kernel function in which the task is currently sleeping.  Running tasks will display a dash (&#8216;-&#8217;) in this column.</p>
<p>Note:  By  displaying  this field, top&#8217;s own working set will be increased by over 700Kb.  Your only means of reducing that overhead will be to stop and restart top.</p>
<p>z: Flags  &#8212;  Task Flags</p>
<p>This column represents the task&#8217;s current scheduling flags which are expressed in hexadecimal notation and with zeros  suppressed.   These  flags  are  officially documented in &lt;linux/sched.h&gt;.  Less formal documentation can also be found on the &#8216;Fields select&#8217; and &#8216;Order fields&#8217; screens.</p>
<p><strong>2b. SELECTING and ORDERING Columns </strong></p>
<p>After pressing the interactive commands &#8216;f&#8217; (Fields select) or &#8216;o&#8217; (Order fields) you will be shown a  screen  containing  the current fields string followed by names and descriptions for all fields.</p>
<p>Here is a sample fields string from one of top&#8217;s four windows/field groups and an explanation of the conventions used:</p>
<p>-  Sample fields string:</p>
<p>ANOPQRSTUVXbcdefgjlmyzWHIK</p>
<p>-  The order of displayed fields corresponds to the order of the letters in that string.</p>
<p>-  If  the  letter  is  upper case the corresponding field itself will then be shown as part of the task display (screen width permitting).  This will also be indicated by a leading asterisk (&#8216;*&#8217;), as in this excerpt:</p>
<p>&#8230;</p>
<p>* K: %CPU       = CPU usage</p>
<p>l: TIME       = CPU Time</p>
<p>m: TIME+      = CPU Time, hundredths</p>
<p>* N: %MEM       = Memory usage (RES)</p>
<p>* O: VIRT       = Virtual Image (kb)</p>
<p>&#8230;</p>
<p>Fields select screen  &#8212;  the &#8216;f&#8217; interactive command</p>
<p>You toggle the display of a field by simply pressing the corresponding letter.</p>
<p>Order fields screen  &#8212;  the &#8216;o&#8217; interactive command</p>
<p>You move a field to the left by pressing the corresponding upper case letter and to the right with the lower case letter.</p>
<p><strong>2c. CPU States </strong></p>
<p>The CPU states are shown in the Summary Area. They are always shown as a percentage and are for the time between now and the last refresh.</p>
<p>us  &#8212;  User CPU time</p>
<p>The time the CPU has spent running users&#8217; processes that are not niced.</p>
<p>sy  &#8212;  System CPU time</p>
<p>The time the CPU has spent running the kernel and its processes.</p>
<p>ni  &#8212;  Nice CPU time</p>
<p>The time the CPU has spent running users&#8217; proccess that have been niced.</p>
<p>wa  &#8212;  iowait</p>
<p>Amount of time the CPU has been waiting for I/O to complete.</p>
<p>hi  &#8212;  Hardware IRQ</p>
<p>The amount of time the CPU has been servicing hardware interrupts.</p>
<p>si  &#8212;  Software Interrupts</p>
<p>The amount of time the CPU has been servicing software interrupts.</p>
<p><strong>3. INTERACTIVE Commands </strong></p>
<p>Listed  below is a brief index of commands within categories.  Some commands appear more than once  &#8212;  their meaning or scope may vary depending on the context in which they are issued.</p>
<p>3a. GLOBAL_Commands</p>
<p>&lt;Ret/Sp&gt; ?, =, A, B, d, G, h, I, k, q, r, s, W, Z</p>
<p>3b. SUMMARY_Area_Commands</p>
<p>l, m, t, 1</p>
<p>3c. TASK_Area_Commands</p>
<p>Appearance:  b, x, y, z</p>
<p>Content:     c, f, H, o, S, u</p>
<p>Size:        #, i, n</p>
<p>Sorting:     &lt;, &gt;, F, O, R</p>
<p>3d. COLOR_Mapping</p>
<p>&lt;Ret&gt;, a, B, b, H, M, q, S, T, w, z, 0 &#8211; 7</p>
<p>4b. COMMANDS_for_Windows</p>
<p>-, _, =, +, A, a, G, g, w</p>
<p><strong>3a. GLOBAL Commands </strong></p>
<p>The global interactive commands are always available in both full-screen mode and alternate-display mode.   However,  some  of these interactive commands are not available when running in &#8216;Secure mode&#8217;.</p>
<p>If  you  wish  to know in advance whether or not your top has been secured, simply ask for help and view the system summary on the second line.</p>
<p>&lt;Enter&gt; or &lt;Space&gt; :Refresh_Display</p>
<p>These commands do nothing, they are simply ignored.  However, they will awaken top and following receipt of  any  input the entire display will be repainted.</p>
<p>Use either of these keys if you have a large delay interval and wish to see current status,</p>
<p>&lt;?&gt; or &lt;h&gt; :Help</p>
<p>There  are two help levels available.  The first will provide a reminder of all the basic interactive commands.  If top is secured, that screen will be abbreviated.</p>
<p>Typing &#8216;h&#8217; or &#8216;?&#8217; on that help screen will take you to help for those interactive commands applicable to alternate-display mode.</p>
<p>&lt;=&gt; :Exit_Task_Limits<br />
Removes restrictions on which tasks are shown.  This command will reverse any &#8216;i&#8217; (idle tasks) and &#8216;n&#8217; (max tasks) commands that might be active.  It also provides for an &#8216;exit&#8217; from PID monitoring.  See the &#8216;-p&#8217; command-line option  for a discussion of PID monitoring.<br />
When operating in alternate-display mode this command has a slightly broader meaning.</p>
<p>&lt;A&gt; :Alternate_Display_Mode_toggle<br />
This  command will switch between full-screen mode and alternate-display mode.  See topic<br />
4 ALTERNATE-DISPLAY Mode and the &#8216;G&#8217; interactive command for insight into &#8216;current&#8217; windows and field groups.</p>
<p>&lt;B&gt; :Bold_Disable/Enable_toggle<br />
This command will influence use of the &#8216;bold&#8217; terminfo capability and alters both the summary area and  task  area  for the current&#8217; window.  While it is intended primarily for use with dumb terminals, it can be applied anytime.<br />
Note:  When  this  toggle is On and top is operating in monochrome mode, the entire display will appear as normal text.<br />
Thus, unless the &#8216;x&#8217; and/or &#8216;y&#8217; toggles are using reverse for emphasis, there will be no visual confirmation that  they are even on.</p>
<p>* &lt;d&gt; or &lt;s&gt; :Change_Delay_Time_interval<br />
You will be prompted to enter the delay time, in seconds, between display updates.<br />
Fractional  seconds  are honored, but a negative number is not allowed.  Entering 0 causes (nearly) continuous updates, with an unsatisfactory display as the system and tty driver try to keep up with top&#8217;s  demands.   The  delay  value  is inversely proportional to system loading, so set it with care.<br />
If  at  any time you wish to know the current delay time, simply ask for help and view the system summary on the second line.</p>
<p>&lt;G&gt; :Choose_Another_Window/Field_Group<br />
You will be prompted to enter a number between 1 and 4 designating the window/field group  which  should  be  made  the current&#8217;  window.   You  will  soon  grow comfortable with these 4 windows, especially after experimenting with alternate-display mode.</p>
<p>&lt;I&gt; :Irix/Solaris_Mode_toggle<br />
When operating in &#8216;Solaris mode&#8217; (&#8216;I&#8217; toggled Off), a task&#8217;s cpu usage will be divided by the  total  number  of  CPUs. After issuing this command, you&#8217;ll be informed of the new state of this toggle.</p>
<p>&lt;u&gt; :select a user<br />
You  will  be  prompted  for  a  UID or username. Only processes belonging to the selected user will be displayed. This option matches on the effective UID.</p>
<p>&lt;U&gt; :select a user<br />
You will be prompted for a UID or username. Only processes belonging to the  selected  user  will  be  displayed.  This option matches on the real, effective, saved, and filesystem UID.</p>
<p>* &lt;k&gt; :Kill_a_task<br />
You  will  be  prompted  for  a  PID  and  then the signal to send.  The default signal, as reflected in the prompt, is SIGTERM.  However, you can send any signal, via number or name.<br />
If you wish to abort the kill process, do one of the following depending on your progress:<br />
1) at the pid prompt, just press &lt;Enter&gt;<br />
2) at the signal prompt, type 0</p>
<p>&lt;q&gt; :Quit</p>
<p>* &lt;r&gt; :Renice_a_Task<br />
You will be prompted for a PID and then the value to nice it to.  Entering a positive value will  cause  a  process  to lose priority.  Conversely, a negative value will cause a process to be viewed more favorably by the kernel.</p>
<p>&lt;W&gt; :Write_the_Configuration_File<br />
This  will  save all of your options and toggles plus the current display mode and delay time.  By issuing this command just before quitting top, you will be able restart later in exactly that same state.</p>
<p>&lt;Z&gt; :Change_Color_Mapping<br />
This key will take you to a separate screen where you can change the colors for the &#8216;current&#8217; window, or for  all  windows.  For details regarding this interactive command see topic 3d. COLOR Mapping.<br />
*  The  commands  shown  with an asterisk (&#8216;*&#8217;) are not available in &#8216;Secure mode&#8217;, nor will they be shown on the level-1 help screen.</p>
<p>3b. SUMMARY Area Commands<br />
The summary area interactive commands are always available in both full-screen mode and alternate-display mode.   They  affect the beginning lines of your display and will determine the position of messages and prompts.</p>
<p>These  commands always impact just the &#8216;current&#8217; window/field group.  See topic 4. ALTERNATE-DISPLAY Mode and the &#8216;G&#8217; interactive command for insight into &#8216;current&#8217; windows and field groups.<br />
&lt;l&gt; :Toggle_Load_Average/Uptime  &#8211;  On/Off<br />
This is also the line containing the program name (possibly an alias) when operating in full-screen mode or  the   current&#8217; window name when operating in alternate-display mode.</p>
<p>&lt;m&gt; :Toggle_Memory/Swap_Usage  &#8211;  On/Off<br />
This command affects two summary area lines.</p>
<p>&lt;t&gt; :Toggle_Task/Cpu_States  &#8211;  On/Off<br />
This command affects from 2 to many summary area lines, depending on the state of the &#8217;1&#8242; toggle and whether or not top is running under true SMP.</p>
<p>&lt;1&gt; :Toggle_Single/Separate_Cpu_States  &#8211;  On/Off<br />
This command affects how the &#8216;t&#8217; command&#8217;s Cpu States portion is shown.  Although this toggle exists primarily to serve massively-parallel SMP machines, it is not restricted to solely SMP environments.</p>
<p>When  you see &#8216;Cpu(s):&#8217; in the summary area, the &#8217;1&#8242; toggle is On and all cpu information is gathered in a single line. Otherwise, each cpu is displayed separately as: &#8216;Cpu0, Cpu1, &#8230;&#8217;</p>
<p>Note: If the entire summary area has been toggled Off for any window, you would be left with just the message line.   In  that way,  you  will  have  maximized  available task rows but (temporarily) sacrificed the program name in full-screen mode or the current&#8217; window name when in alternate-display mode.</p>
<p>3c. TASK Area Commands<br />
The task area interactive commands are always available in full-screen mode.</p>
<p>The task area interactive commands are never available in alternate-display mode if the &#8216;current&#8217; window&#8217;s  task  display  has been toggled Off (see topic 4. ALTERNATE-DISPLAY Mode).</p>
<p>APPEARANCE of task window<br />
The following commands will also be influenced by the state of the global &#8216;B&#8217; (bold disable) toggle.</p>
<p>&lt;b&gt; :Bold/Reverse_toggle<br />
This  command  will impact how the &#8216;x&#8217; and &#8216;y&#8217; toggles are displayed.  Further, it will only be available when at least one of those toggles is On.</p>
<p>&lt;x&gt; :Column_Highlight_toggle<br />
Changes highlighting for the current sort field.  You probably don&#8217;t need a constant visual reminder of the sort  field and top hopes that you always run with &#8216;column highlight&#8217; Off, due to the cost in path-length.<br />
If you forget which field is being sorted this command can serve as a quick visual reminder.</p>
<p>&lt;y&gt; :Row_Highlight_toggle<br />
Changes  highlighting  for &#8220;running&#8221; tasks.  For additional insight into this task state, see topic 2a DESCRIPTIONS of Fields, Process Status.</p>
<p>Use of this provision provides important insight into your system&#8217;s health.  The only costs will be  a  few  additional tty escape sequences.</p>
<p>&lt;z&gt; :Color/Monochrome_toggle<br />
Switches  the  &#8216;current&#8217;  window  between your last used color scheme and the older form of black-on-white or white-on-black.  This command will alter both the summary area and task area but does not affect the state of the  &#8216;x&#8217;,  &#8216;y&#8217;  or &#8216;b&#8217; toggles.</p>
<p>CONTENT of task window<br />
&lt;c&gt; :Command_Line/Program_Name_toggle<br />
This  command  will be honored whether or not the &#8216;Command&#8217; column is currently visible.  Later, should that field come into view, the change you applied will be seen.</p>
<p>&lt;f&gt; and &lt;o&gt; :Fields_select or Order_fields<br />
These keys display separate screens where you can change which fields are displayed and their  order.   For  additional information on these interactive commands see topic 2b. SELECTING and ORDERING Columns.</p>
<p>&lt;S&gt; :Cumulative_Time_Mode_toggle<br />
When  this  toggle is On, all individual threads will be displayed.  Otherwise, top displays a summation of all threads in a process.</p>
<p>&#8216;S&#8217; :Cumulative_Time_Mode_toggle<br />
When &#8216;Cumulative mode&#8217; is On, each process is listed with the cpu time that it and its dead children have used.</p>
<p>When Off, programs that fork into many separate tasks will appear less demanding.  For programs like &#8216;init&#8217; or a  shell this  is  appropriate  but  for others, like compilers, perhaps not.  Experiment with two task windows sharing the same sort field but with different &#8216;S&#8217; states and see which representation you prefer.</p>
<p>After issuing this command, you&#8217;ll be informed of the new state of this toggle.  If you wish to know in advance whether or not &#8216;Cumulative mode&#8217; is in effect, simply ask for help and view the window summary on the second line.</p>
<p>&lt;u&gt; :Show_Specific_User_Only<br />
You will be prompted to enter the name of the user to display.  Thereafter, in that task window only matching User ID&#8217;s will be shown, or possibly no tasks will be shown. Later, if you wish to monitor all tasks again, re-issue this command but just press &lt;Enter&gt; at the prompt, without providing a name.</p>
<p>SIZE of task window<br />
&lt;i&gt; :Idle_Processes_toggle<br />
Displays all tasks or just active tasks.  When this toggle is Off, idled or zombied processes will not be displayed.</p>
<p>If  this  command  is applied to the last task display when in alternate-display mode, then it will not affect the window&#8217;s size, as all prior task displays will have already been painted.</p>
<p>&lt;n&gt; or &lt;#&gt; :Set_Maximum_Tasks<br />
You will be prompted to enter the number of tasks to display.  The lessor of your number and available screen rows will be used.</p>
<p>When used in alternate-display mode, this is the command that gives you precise control over the size of each currently visible task display, except for the very last.  It will not affect the last  window&#8217;s size, as all prior task  displays will have already been painted.</p>
<p>Note: If you wish to increase the size of the last visible task display when in alternate-display mode, simply decrease the size of the task display(s) above it.</p>
<p>SORTING of task window<br />
For compatibility, this top supports most of the former top sort keys.  Since this is primarily  a  service  to  former  top users, these commands do not appear on any help screen.<br />
command   sorted field                  supported<br />
A         start time (non-display)      No<br />
M         %MEM                             Yes<br />
N         PID                                    Yes<br />
P         %CPU                                Yes<br />
T         TIME+                               Yes</p>
<p>Before  using  any of the following sort provisions, top suggests that you temporarily turn on column highlighting using the &#8216;x&#8217; interactive command.  That will help ensure that the actual sort environment matches your intent.</p>
<p>The following interactive commands will only be honored when the current sort field is visible.  The sort field might not be visible because:<br />
1) there is insufficient Screen Width<br />
2) the &#8216;f&#8217; interactive command turned it Off</p>
<p>&lt;&lt;&gt; :Move_Sort_Field_Left<br />
Moves the sort column to the left unless the current sort field is the first field being displayed.</p>
<p>&lt;&gt;&gt; :Move_Sort_Field_Right<br />
Moves the sort column to the right unless the current sort field is the last field being displayed.</p>
<p>The following interactive commands will always be honored whether or not the current sort field is visible.</p>
<p>&lt;F&gt; or &lt;O&gt; :Select_Sort_Field<br />
These keys display a separate screen where you can change which field is used as the sort column.</p>
<p>If  a  field is selected which was not previously being displayed, it will be forced On when you return to the top display.  However, depending upon your screen width and the order of your fields, this sort field may not be  displayable.</p>
<p>This  interactive command can be a convenient way to simply verify the current sort field, when running top with column highlighting turned Off.</p>
<p>&lt;R&gt; :Reverse/Normal_Sort_Field_toggle<br />
Using this interactive command you can alternate between high-to-low and low-to-high sorts.</p>
<p>Note: Field sorting uses internal values, not those in column display.  Thus, the TTY and WCHAN fields will  violate  strict ASCII collating sequence.</p>
<p>3d. COLOR Mapping<br />
When  you  issue the &#8216;Z&#8217; interactive command, you will be presented with a separate screen.  That screen can be used to change the colors in just the current&#8217; window or in all four windows before returning to the top display.</p>
<p>Available interactive commands<br />
4 upper case letters to select a target<br />
8 numbers to select a color<br />
normal toggles available<br />
&#8216;B&#8217;       :bold disable/enable<br />
&#8216;b&#8217;       :running tasks &#8220;bold&#8221;/reverse<br />
&#8216;z&#8217;       :color/mono<br />
other commands available<br />
&#8216;a&#8217;/'w&#8217;   :apply, then go to next/prior<br />
&lt;Enter&gt;   :apply and exit<br />
&#8216;q&#8217;       :abandon current changes and exit</p>
<p>If your use &#8216;a&#8217; or &#8216;w&#8217; to cycle the targeted window, you will have applied the color scheme that was displayed when  you  left that  window.  You can, of course, easily return to any window and reapply different colors or turn colors Off completely with the &#8216;z&#8217; toggle.</p>
<p>The Color Mapping screen can also be used to change the &#8216;current&#8217; window/field group in  either  full-screen  mode  or  alternate-display  mode.   Whatever was targeted when &#8216;q&#8217; or &lt;Enter&gt; was pressed will be made current as you return to the top display.</p>
<p>4. ALTERNATE-DISPLAY Mode<br />
4a. WINDOWS Overview<br />
Field Groups/Windows:<br />
In full-screen mode there is a single window represented by the entire screen.  That single window can still be changed to display 1 of 4 different field groups (see the &#8216;G&#8217; interactive command, repeated below).  Each of the 4 field groups has a unique separately configurable summary area and its own configurable task area.</p>
<p>In alternate-display mode, those 4 underlying field groups can now be made visible simultaneously, or can be turned Off individually at your command.</p>
<p>The summary area will always exist, even if it&#8217;s only the message line.  At any given time only one summary area can be displayed.  However, depending on your commands, there could be from zero to  four  separate  task  displays  currently showing on the screen.</p>
<p>Current Window:<br />
The  current&#8217;  window is the window associated with the summary area and the window to which task related commands are always directed.  Since in alternate-display mode you  can  toggle  the  task  display  Off,  some  commands  might  be restricted for the current&#8217; window.</p>
<p>A  further complication arises when you have toggled the first summary area line Off.  With the loss of the window name (the &#8216;l&#8217; toggled line), you&#8217;ll not easily know what window is the &#8216;current&#8217; window.</p>
<p>4b. COMMANDS for Windows<br />
&lt;-&gt; and &lt;_&gt; :Show/Hide_Window(s)_toggles<br />
The &#8216;-&#8217; key turns the &#8216;current&#8217; window&#8217;s task display On and Off.  When On, that task area will show a minimum  of  the columns  header  you&#8217;ve  established  with  the  &#8216;f&#8217;  and  &#8216;o&#8217;  commands.   It  will  also  reflect any other task area options/toggles you&#8217;ve applied yielding zero or more tasks.</p>
<p>The &#8216;_&#8217; key does the same for all task displays.  In other words, it switches between the currently visible  task  display(s)  and  any  task display(s) you had toggled Off.  If all 4 task displays are currently visible, this interactive       command will leave the summary area as the only display element.</p>
<p>* &lt;=&gt; and &lt;+&gt; :Equalize_(re-balance)_Window(s)<br />
The &#8216;=&#8217; key forces the &#8216;current&#8217; window&#8217;s task display to be visible.  It also reverses any &#8216;i&#8217; (idle  tasks)  and  &#8216;n&#8217; (max tasks) commands that might be active.</p>
<p>The &#8216;+&#8217; key does the same for all windows.  The four task displays will reappear, evenly balanced.  They will also have retained any customizations you had previously applied, except for the &#8216;i&#8217; (idle tasks) and &#8216;n&#8217; (max tasks) commands.</p>
<p>* &lt;A&gt; :Alternate_Display_Mode_toggle<br />
This command will switch between full-screen mode and alternate-display mode.</p>
<p>The first time you issue this command, all four task displays will be shown.  Thereafter when  you  switch  modes,  you will see only the task display(s) you&#8217;ve chosen to make visible.</p>
<p>* &lt;a&gt; and &lt;w&gt; :Next_Window_Forward/Backward<br />
This will change the &#8216;current&#8217; window, which in turn changes the window to which commands are directed.  These keys act in a circular fashion so you can reach any desired &#8216;current&#8217; window using either key.</p>
<p>Assuming the window name is visible (you have not toggled &#8216;l&#8217; Off), whenever the &#8216;current&#8217; window name loses its emphasis/color, that&#8217;s a reminder the task display is Off and many commands will be restricted.</p>
<p>* &lt;G&gt; :Choose_Another_Window/Field_Group<br />
You  will  be  prompted  to  enter a number between 1 and 4 designating the window/field group which should be made the current&#8217; window.</p>
<p>In full-screen mode, this command is necessary to alter the &#8216;current&#8217; window.  In alternate-display mode, it is  simply a less convenient alternative to the &#8216;a&#8217; and &#8216;w&#8217; commands.</p>
<p>&lt;g&gt; :Change_Window/Field_Group_Name<br />
You will be prompted for a new name to be applied to the &#8216;current&#8217; window.  It does not require that the window name be visible (the &#8216;l&#8217; toggle to be On).</p>
<p>*  The interactive commands shown with an asterisk (&#8216;*&#8217;) have use beyond alternate-display mode.<br />
&#8216;=&#8217;, &#8216;A&#8217;, &#8216;G&#8217;  are always available<br />
&#8216;a&#8217;, &#8216;w&#8217;       act the same when color mapping</p>
<p>5. FILES<br />
5a. SYSTEM Configuration File<br />
The presence of this file will influence which version of the &#8216;help&#8217; screen is shown to an ordinary user.   More  importantly, it  will  limit  what ordinary users are allowed to do when top is running.  They will not be able to issue the following commands.<br />
k         Kill a task<br />
r         Renice a task<br />
d or s    Change delay/sleep interval</p>
<p>The system configuration file is not created by top.  Rather, you create this file manually and place it in  the  /etc  directory.  Its name must be &#8216;toprc&#8217; and must have no leading &#8216;.&#8217; (period).  It must have only two lines.</p>
<p>Here is an example of the contents of /etc/toprc:<br />
s         # line 1: &#8216;secure&#8217; mode switch<br />
5.0       # line 2: &#8216;delay&#8217;  interval in seconds</p>
<p>5b. PERSONAL Configuration File<br />
This file is written as &#8216;$HOME/.your-name-4-top&#8217; + &#8216;rc&#8217;.  Use the &#8216;W&#8217; interactive command to create it or update it.</p>
<p>Here is the general layout:<br />
global    # line 1: the program name/alias notation<br />
&#8220;       # line 2: id,altscr,irixps,delay,curwin<br />
per ea    # line a: winname,fieldscur<br />
window    # line b: winflags,sortindx,maxtasks<br />
&#8220;       # line c: summclr,msgsclr,headclr,taskclr</p>
<p>If  the $HOME variable is not present, top will try to write the personal configuration file to the current directory, subject to permissions.</p>
<p>6. STUPID TRICKS Sampler<br />
Many of these &#8216;tricks&#8217; work best when you give top a scheduling boost.  So plan on starting him with  a  nice  value  of  -10, assuming you&#8217;ve got the authority.</p>
<p>6a. Kernel Magic<br />
For these stupid tricks, top needs full-screen mode.</p>
<p>-*-  The  user  interface,  through  prompts and help, intentionally implies that the delay interval is limited to tenths of a second.  However, you&#8217;re free to set any desired delay.  If you want to see Linux at his scheduling best, try a delay  of  .09 seconds or less.</p>
<p>For this experiment, under x-windows open an xterm and maximize it.  Then do the following:<br />
. provide a scheduling boost and tiny delay via:<br />
nice -n -10 top -d.09<br />
. keep sorted column highlighting Off to minimize path length<br />
. turn On reverse row highlighting for emphasis<br />
. try various sort columns (TIME/MEM work well), and normal or reverse sorts to bring the<br />
most active processes into view</p>
<p>What  you&#8217;ll  see  is a very busy Linux doing what he&#8217;s always done for you, but there was no program available to illustrate this.</p>
<p>-*-  Under an xterm using &#8216;white-on-black&#8217; colors, try setting top&#8217;s task color to black and be sure that task highlighting is set to bold, not reverse.  Then set the delay interval to around .3 seconds.</p>
<p>After  bringing the most active processes into view, what you&#8217;ll see are the ghostly images of just the currently running tasks.</p>
<p>-*-  Delete the existing rcfile, or create a new symlink.  Start this new version then type &#8216;T&#8217; (a secret key, see  topic  3c.<br />
TASK Area Commands, Sorting) followed by &#8216;W&#8217; and &#8216;q&#8217;.  Finally, restart the program with -d0 (zero delay).</p>
<p>Your display will be refreshed at three times the rate of the former top, a 300% speed advantage.  As top climbs the TIME ladder, be as patient as you can while speculating on whether or not top will ever reach the top.</p>
<p>6b. Bouncing Windows<br />
For these stupid tricks, top needs alternate-display mode.</p>
<p>-*-  With 3 or 4 task displays visible, pick any window other than the last and turn idle processes Off.  Depending  on  where you applied &#8216;i&#8217;, sometimes several task displays are bouncing and sometimes it&#8217;s like an accordion, as top tries his best allocate space.</p>
<p>-*-  Set each window&#8217;s summary lines differently: one with no memory; another with no states; maybe one with nothing  at  all, just the message line.  Then hold down &#8216;a&#8217; or &#8216;w&#8217; and watch a variation on bouncing windows  &#8211;  hopping windows.</p>
<p>-*-  Display all 4 windows and for each, in turn, set idle processes to Off.  You&#8217;ve just entered the &#8220;extreme bounce&#8221; zone.</p>
<p>6c. The Big Bird Window<br />
This stupid trick also requires alternate-display mode.</p>
<p>-*-  Display  all 4 windows and make sure that 1:Def is the &#8216;current&#8217; window.  Then, keep increasing window size until the all the other task displays are &#8220;pushed out of the nest&#8221;.</p>
<p>When they&#8217;ve all been displaced, toggle between all visible/invisible windows.  Then ponder this:<br />
is top fibbing or telling honestly your imposed truth?</p>
<h2>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</h2>
<br />Posted in Misc, SysAd  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kaiwantech.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kaiwantech.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kaiwantech.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kaiwantech.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kaiwantech.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kaiwantech.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kaiwantech.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kaiwantech.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kaiwantech.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kaiwantech.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kaiwantech.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kaiwantech.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kaiwantech.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kaiwantech.wordpress.com/80/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=80&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kaiwantech.wordpress.com/2009/04/29/linux-cheatsheet-vmstat-ps-top/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5216008e0b231a760d20d22b01c4328?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kaiwan</media:title>
		</media:content>
	</item>
		<item>
		<title>Linux and Stale? Never!</title>
		<link>http://kaiwantech.wordpress.com/2009/04/16/linux-and-stale-never/</link>
		<comments>http://kaiwantech.wordpress.com/2009/04/16/linux-and-stale-never/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 05:47:53 +0000</pubDate>
		<dc:creator>Kaiwan</dc:creator>
				<category><![CDATA[Linux Kernel]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://kaiwantech.wordpress.com/?p=67</guid>
		<description><![CDATA[The words Linux (and all that it implies), stale/boring never go together. Take a look at LinuxDevice&#8217;s excellent report on the LF&#8217;s (Linux Foundation) Collabaration Summit held last week in SF, USA. A quick sampling to whet your appetite: Intel hands over the Moblin project to the LF KVM&#8217;s being pushed as the way to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=67&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The words Linux (and all that it implies), stale/boring <em>never</em> go together.</p>
<p>Take a look at<a href="http://www.linuxdevices.com/news/NS2721874402.html?kc=LXDEMNL041509" target="_blank"> LinuxDevice&#8217;s excellent report</a> on the LF&#8217;s (Linux Foundation) Collabaration Summit held last week in SF, USA.</p>
<p>A quick sampling to whet your appetite:</p>
<ul>
<li>Intel hands over the Moblin project to the LF</li>
<li>KVM&#8217;s being pushed as the way to go within Linux virtualization</li>
<li>The Kernel Summit / Panel discussion was energetic, techy and interesting-
<ul>
<li>2.6.29 kernel released two weeks back by LF</li>
<li>Andrew Morton bags the first-ever &#8220;Unsung Hero&#8221; award!</li>
<li>Intel and ATI will work towards greatly modernizing the kernel graphics stack</li>
<li>Ted Ts&#8217;o talks about moving to Oracle&#8217;s Btrfs filesystem</li>
</ul>
</li>
<li>LF announces the winning entries to the &#8220;We&#8217;re Linux&#8221; 1-minute video contest.</li>
</ul>
<p>Read about all this (and more!)  <a href="http://www.linuxdevices.com/news/NS2721874402.html?kc=LXDEMNL041509">here</a>.</p>
<br />Posted in Linux Kernel, Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/kaiwantech.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/kaiwantech.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/kaiwantech.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/kaiwantech.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/kaiwantech.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/kaiwantech.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/kaiwantech.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/kaiwantech.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/kaiwantech.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/kaiwantech.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/kaiwantech.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/kaiwantech.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/kaiwantech.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/kaiwantech.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=kaiwantech.wordpress.com&amp;blog=6153622&amp;post=67&amp;subd=kaiwantech&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://kaiwantech.wordpress.com/2009/04/16/linux-and-stale-never/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e5216008e0b231a760d20d22b01c4328?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kaiwan</media:title>
		</media:content>
	</item>
	</channel>
</rss>
