<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-37856708</id><updated>2011-07-08T00:04:26.681+02:00</updated><title type='text'>Same Old Stuff : a procrastinator's notebook</title><subtitle type='html'>(random unfinished engineering notes)</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://devcs.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://devcs.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Alek</name><uri>http://www.blogger.com/profile/07619493115870095288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-37856708.post-2171925751528146079</id><published>2010-03-04T14:30:00.010+01:00</published><updated>2010-03-04T20:46:18.443+01:00</updated><title type='text'>Web Services Interoperability Soup</title><content type='html'>Some notes on .net - j2ee and cros-j2ee web services integrations :&lt;br /&gt;&lt;br /&gt;* Compatibility stepping stones : interaction styles, data types, namespace issues. &lt;br /&gt;* wsdl standard - 1.1 vs 2.0 ?&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;axis2 vs jax-ws 2.0:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1) &lt;span style="font-style:italic;"&gt;generated wsdl styles&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;- namespace : wsdl-namespace for axis2 vs flat-namespace for jax-ws&lt;br /&gt;- axis2 lacks name property in &lt;definitions&gt; tag - introduces definitions/documentation tag&lt;br /&gt;- endpoint vs port (though they should be equivalent)&lt;br /&gt;- axis2 - direct schema in wsdl vs external reference for jax-ws&lt;br /&gt;- elementFormDefault="qualified" property in axis2 schema / missing in jax-ws&lt;br /&gt;- for base types, schema seems similar&lt;br /&gt;- separate xsd is often more "natural" setting&lt;br /&gt;- jax-ws misses Action properties for input/output of each operation&lt;br /&gt;- axis2 generates multiple ports - HttpEndpoint / HttpSoap11Endpoint / HttpSoap12Endpoint - depending on the version - 1.1, 1.2, 2.0 - jax-ws assumes default version (1.1 ?)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37856708-2171925751528146079?l=devcs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://devcs.blogspot.com/feeds/2171925751528146079/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37856708&amp;postID=2171925751528146079' title='37 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/2171925751528146079'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/2171925751528146079'/><link rel='alternate' type='text/html' href='http://devcs.blogspot.com/2010/03/web-services-interoperability-soup.html' title='Web Services Interoperability Soup'/><author><name>Alek</name><uri>http://www.blogger.com/profile/07619493115870095288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>37</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37856708.post-2485198260873945195</id><published>2008-12-15T12:23:00.006+01:00</published><updated>2008-12-15T13:17:09.223+01:00</updated><title type='text'>cURL out of memory on Xen instance (use and abuse series)</title><content type='html'>cURL, a part of everyone's favorite UNIX tool subset, got me into a bit of trouble recently, while trying to post a relatively large file, following a common 'just curl it' - logic (so commonplace that a lot of major projects simply incorporate curlin' as a part of standard deploy procedure).&lt;br /&gt;&lt;br /&gt;The case was posting 8Gb file on 16Gb Xen instance. While this worked quite nice on real box, on virtual box curl said hello with :&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;out of memory&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now that seemed quite bizzare. Figurng out that the process actually gets ENOMEM, it was logical to look at curl code and figure out what's going on. &lt;br /&gt;&lt;br /&gt;And there it was, power-of-two allocator in the file read loop : &lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;static ParameterError file2memory(char **bufp, size_t *size, FILE *file) &lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;  char *newbuf;&lt;br /&gt;  char *buffer = NULL;&lt;br /&gt;  size_t alloc = 512;&lt;br /&gt;  size_t nused = 0;&lt;br /&gt;  size_t nread;&lt;br /&gt;&lt;br /&gt;do {&lt;br /&gt;      if(!buffer || (alloc == nused)) {&lt;br /&gt;        /* size_t overflow detection for huge files */&lt;br /&gt;        if(alloc+1 &gt; ((size_t)-1)/2) {&lt;br /&gt;          if(buffer)&lt;br /&gt;            free(buffer);&lt;br /&gt;          return PARAM_NO_MEM;&lt;br /&gt;        }&lt;br /&gt; alloc *= 2;&lt;br /&gt;&lt;br /&gt;        if((newbuf = realloc(buffer, alloc+1)) == NULL) {&lt;br /&gt;          if(buffer)&lt;br /&gt;            free(buffer);&lt;br /&gt;          return PARAM_NO_MEM;&lt;br /&gt;        }&lt;br /&gt;        buffer = newbuf;&lt;br /&gt;      }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Whoa :) - now apparently someone didn't expect some geniuses will try po post XX Gb files with curl - so it's the abusers that are to blame. Stop abusing curl and do your own posts !&lt;br /&gt;&lt;br /&gt;However, if you don't have the time to change your app, and still want to post files of the size (N,2N) Gb on a 2N Gb box, a simple hack of given form should do it :&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;br /&gt;        if (alloc &lt; ALLOC_THRESHOLD)&lt;br /&gt;   alloc *= 2;&lt;br /&gt;  else&lt;br /&gt;   alloc = alloc + ALLOC_THRESHOLD;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;span style="font-style:italic;"&gt;(Where ALLOC_THRESHOLD would usually be 1Gb)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This should make allocation linear, rather than exponential, once the allocated memory passes given threshold.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now - what does is all has to do with XEN, you might ask?. &lt;br /&gt;&lt;br /&gt;Couple of things, actually. First off, such environment (local or any virtualized cloud platform offering xen instances) usually provide user with something like effective 2^N - penalty memory space (say 15Gb instead of 16Gb) - and that's where the impact of power of two allocator becomes apparent much sooner. Also - memory allocation policies are quite stricter and enomems are dispatched much earlier, oom killer is fast on the trigger, etc :) - so that's why the curl ooms immediately, rather than trying to make that darn realloc() after all.&lt;br /&gt;&lt;br /&gt;Moral of the story - don't abuse standard unix tools ! &lt;br /&gt;Be nice to curl - do not POST binary data larger than 50% of effective RAM. &lt;br /&gt;Keep it safe !&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37856708-2485198260873945195?l=devcs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://devcs.blogspot.com/feeds/2485198260873945195/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37856708&amp;postID=2485198260873945195' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/2485198260873945195'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/2485198260873945195'/><link rel='alternate' type='text/html' href='http://devcs.blogspot.com/2008/12/curl-out-of-memory-on-xen-instance-use.html' title='cURL out of memory on Xen instance (use and abuse series)'/><author><name>Alek</name><uri>http://www.blogger.com/profile/07619493115870095288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37856708.post-1525675673805741753</id><published>2008-07-10T20:14:00.009+02:00</published><updated>2008-07-20T19:18:42.056+02:00</updated><title type='text'>Instrumenting Java code for fun&amp;profit</title><content type='html'>By code instrumentation we assume a proces of adding bytecodes to methods in order to intercept their execution (usually for the profiling purpose)&lt;br /&gt;Some of the purposes include : code tracing (getting the method calls and regenerating the call tree), code profiling (getting the execution times between calls, automatic detection of bottlenecks etc), code monitoring (event/method invocation detection, code state monitoring - getting the structure size etc), and all of the above(for eaxmple, monitoring performance dependent of the code state, size of structures, number of predefined objects, etc)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The java.lang.instrument interface, available since java 1.5, enables us to write a handler,acessible via agent loaded into JVM, to which, all class load requests are passed. This enables us to calculate time,performance, analyze state, or even instrument the classes loaded.&lt;br /&gt;&lt;br /&gt;the instrumentation is done via modification of method bytecodes&lt;br /&gt;&lt;br /&gt;Creating a instrument agent is pretty straightforward :&lt;br /&gt;&lt;br /&gt;- the Premain-Class is defined =&gt; which must implement &lt;span style="font-style:italic;"&gt;premain&lt;/span&gt; method (taking a args string, and a Instrumentation object instance,which is created by jvm and automatically passed to the premain method of Premain-Class). The Instrumentation instance is then passed on, and can be used to monitor list and usage of all loaded/initialized classes, and add/remove transformers and redefine classes).&lt;br /&gt;&lt;br /&gt;.....&lt;br /&gt;&lt;br /&gt;- what we need to do next in order to reconstruct the full call-tree trace, is the information when which method ends. We cannot get this information via classloader, especially not in execution-time (we might try to get some post-exec via call stack reconstuction). However - we can get the return info the other way -&gt; and that is via mangling the bytecode using the transformation framework and BCEL bytecode engineering library. We are simply altering the bytecode either via creating a wrapper method or by notifying the static method from the added instruction before the final return in the method. All in all this gives us all the necessary ingredients for making a proper runtime-profiler-call-dinamic-executinon-tracing-whatever :) Anyway, once i get it all together and start writing decent posts, i might write a proper post about it :)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;References :&lt;br /&gt;&lt;br /&gt;http://java.sun.com/j2se/1.5.0/docs/api/java/lang/instrument/package-summary.html&lt;br /&gt;http://www.javalobby.org/java/forums/t19309.html&lt;br /&gt;http://www.ibm.com/developerworks/java/library/j-jtp09196/index.html&lt;br /&gt;http://www.cs.nuim.ie/~jpower/Research/instrument/&lt;br /&gt;http://www-128.ibm.com/developerworks/java/library/j-jip/&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37856708-1525675673805741753?l=devcs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://devcs.blogspot.com/feeds/1525675673805741753/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37856708&amp;postID=1525675673805741753' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/1525675673805741753'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/1525675673805741753'/><link rel='alternate' type='text/html' href='http://devcs.blogspot.com/2008/07/instrumenting-java-code-for-fun.html' title='Instrumenting Java code for fun&amp;profit'/><author><name>Alek</name><uri>http://www.blogger.com/profile/07619493115870095288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37856708.post-699167249808344610</id><published>2008-06-25T12:57:00.003+02:00</published><updated>2008-06-25T14:36:32.469+02:00</updated><title type='text'>Profiling java apps using DTrace</title><content type='html'>- monitoring operational performance of java apps&lt;br /&gt;- finding bottlenecks&lt;br /&gt;- examining cache effects&lt;br /&gt;- example : heavily IO-bound app&lt;br /&gt;- OS/X / Solaris&lt;br /&gt;&lt;br /&gt;idea :&lt;br /&gt;(a) current java profiling options : (what/where)&lt;br /&gt;(b) java options on system/level profiling (we can debug / but cannot to the strace-like detailed to-syscall-mapping, oprofile-like stuff etc)&lt;br /&gt;&lt;br /&gt;dtrace - cool caps :&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;references :&lt;br /&gt;&lt;br /&gt;http://www.devx.com/Java/Article/33943/0/page/3&lt;br /&gt;http://www.solarisinternals.com/wiki/index.php/DTrace_Topics_Java&lt;br /&gt;http://developers.sun.com/solaris/articles/java_on_solaris.html&lt;br /&gt;http://developers.sun.com/solaris/articles/dtrace_ajax.html&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37856708-699167249808344610?l=devcs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://devcs.blogspot.com/feeds/699167249808344610/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37856708&amp;postID=699167249808344610' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/699167249808344610'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/699167249808344610'/><link rel='alternate' type='text/html' href='http://devcs.blogspot.com/2008/06/profiling-java-apps-using-dtrace.html' title='Profiling java apps using DTrace'/><author><name>Alek</name><uri>http://www.blogger.com/profile/07619493115870095288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37856708.post-7951224704504018377</id><published>2008-03-29T12:57:00.002+01:00</published><updated>2008-04-26T21:37:21.099+02:00</updated><title type='text'>Managing shared state in Erlang</title><content type='html'>Though a functional language, with no apparent shared state, we can trivially implement state in erlang by (ab)using the single-bounded value concept (each value can be bound only once)&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;whereis(list_to_atom("portServer" ++ integer_to_list(PORT))).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37856708-7951224704504018377?l=devcs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://devcs.blogspot.com/feeds/7951224704504018377/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37856708&amp;postID=7951224704504018377' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/7951224704504018377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/7951224704504018377'/><link rel='alternate' type='text/html' href='http://devcs.blogspot.com/2008/03/managing-shared-state-in-erlang.html' title='Managing shared state in Erlang'/><author><name>Alek</name><uri>http://www.blogger.com/profile/07619493115870095288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37856708.post-8058044856519420596</id><published>2008-03-29T12:55:00.002+01:00</published><updated>2008-03-29T12:56:37.959+01:00</updated><title type='text'>Bloom filters for profit &amp; fun</title><content type='html'>&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37856708-8058044856519420596?l=devcs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://devcs.blogspot.com/feeds/8058044856519420596/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37856708&amp;postID=8058044856519420596' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/8058044856519420596'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/8058044856519420596'/><link rel='alternate' type='text/html' href='http://devcs.blogspot.com/2008/03/bloom-filters-for-fun-profit.html' title='Bloom filters for profit &amp; fun'/><author><name>Alek</name><uri>http://www.blogger.com/profile/07619493115870095288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37856708.post-650800209734612963</id><published>2008-03-29T12:54:00.002+01:00</published><updated>2008-03-29T12:55:06.096+01:00</updated><title type='text'>Perfect Hash Functions for fun and profit</title><content type='html'>&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37856708-650800209734612963?l=devcs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://devcs.blogspot.com/feeds/650800209734612963/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37856708&amp;postID=650800209734612963' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/650800209734612963'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/650800209734612963'/><link rel='alternate' type='text/html' href='http://devcs.blogspot.com/2008/03/perfect-hash-functions-for-fun-and.html' title='Perfect Hash Functions for fun and profit'/><author><name>Alek</name><uri>http://www.blogger.com/profile/07619493115870095288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37856708.post-1379255163441193552</id><published>2008-03-27T17:52:00.002+01:00</published><updated>2008-03-27T17:56:35.915+01:00</updated><title type='text'>Breakpoint</title><content type='html'>Okie, cut here&lt;br /&gt;&lt;br /&gt;This is another attempt into actually starting to write something ;)&lt;br /&gt;So, stay tuned for a bunch of stupid posts :) I need something in order to get started. Hopefuly, I might be able to actually post something usefull some day. (in which case i will erase all the posts until that day :) ). So, some value after all .... these posts won't last forever .... :) :) read them while they are still here ... and have mercy :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37856708-1379255163441193552?l=devcs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://devcs.blogspot.com/feeds/1379255163441193552/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37856708&amp;postID=1379255163441193552' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/1379255163441193552'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/1379255163441193552'/><link rel='alternate' type='text/html' href='http://devcs.blogspot.com/2008/03/breakpoint.html' title='Breakpoint'/><author><name>Alek</name><uri>http://www.blogger.com/profile/07619493115870095288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37856708.post-776003063248627441</id><published>2007-12-31T15:36:00.000+01:00</published><updated>2008-01-02T23:55:50.289+01:00</updated><title type='text'>Linux buffer cache &amp; how to disable it  (and why ?)</title><content type='html'>Linux buffer cache provides a excelent mechanism for black-box performance optimization by a modest cost or max 2 memory hits (hit 1 -&gt; page not found -&gt; fetch buffer from disk to buffer cache (free heap space) -&gt; hit 2 -&gt; found in memory -&gt; get block).&lt;br /&gt;&lt;br /&gt;However, there are 2 cases when we would want to disable such behaviour :&lt;br /&gt;&lt;br /&gt;(1) When 2-hit is too much of price to pay, we might want to think about direct io (O_DIRECT/ madvise()-style), and doing the memory buffer management by hand from userspace - often done for db cache management&lt;br /&gt;&lt;br /&gt;(2) When we want to do unbiased benchmarking of heavily IO-dependent software (usually a single shot-benchmark is ok - pages are on the disk), but upont 2nd take , most of the pages remains in buffcache, which results in better performance, so no real metric can be imposed afterwards - so the only way to do the proper benchmark would be to disable buffacahe&lt;br /&gt;&lt;br /&gt;Currently, we are interested in (2) , so here are couple of ideas how that could be done :&lt;br /&gt;&lt;br /&gt;(a) create a non-trivial file of available memory size and write a simple code that mmap()'s it&lt;br /&gt;(b) tune the swappiness kernel knob (/proc/sys/vm/swappiness) to 0 (proc memory over buffers), and fork() some ~64k dummy (nontrivial) processes :) - this should do the trick&lt;br /&gt;(c) mounting the partition as raw device (no buffering then) - but this is usually highly impractical&lt;br /&gt;(d) seting the O_DIRECT flag for every open() in the source (this is often tedious unless open() is invoked through a wrapper - a nice argument for doing so in such applications). We could write a simple wrapper (if possible for doing so):&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;int dopen(char *file) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;       return  open(file, O_DIRECT);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:courier new;font-size:100%;"  &gt;&lt;span style="font-family:arial;"&gt;or in case of fopen() :&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;FILE *dfopen(char *file,  char *pern) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    int fd = open(file, O_DIRECT | O_RDONLY);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;    return fdopen(fd,perm);    &lt;/span&gt;&lt;br /&gt;&lt;code style="font-family: courier new;"&gt;&lt;/code&gt;&lt;span style="font-family:courier new;"&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial;"&gt;(note theat O_DIRECT is conditionaly defined by _GNU_SOURCE &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="font-family:arial;"&gt;, so don't forget to use &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;code&gt;-D_GNU_SOURCE &lt;/code&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="font-family:arial;"&gt;flag when building)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="font-family:arial;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;(e) reboot the machine (if you are really desperate) :)&lt;br /&gt;(f) allthough one might think that invoking "sync" from command line might do the trick - it actually just flushes *changed* blocks to the disk - which is not actually what we need (flushing the read-buffered blocks)&lt;br /&gt;(g) the dirty way of doing (a) would be simply touching a very big file (for example dd if=/dev/urandom of=file_4GB bs=1024 count=4000000) and doing 'cat file_4GB &gt; /dev/null'&lt;br /&gt;(h) writing a simple code that allocates a huge chunk of memory and locks the allocated pages (using mlock() or similar) - thus reducing the available buffcache to a arbitrary size&lt;br /&gt;(i) doing fcntl() with F_NOCACHE on all file descriptors in the source code - again quite tedious especially if there is no wrapper for open() call in the code&lt;br /&gt;(g) using madvise() mechanism for telling kernel that the pages allocated won't be used in the future (which should result in kernel freeing the allocated pages from buffcache immidiatelly):&lt;br /&gt;&lt;span style=";font-family:courier new;font-size:85%;"  &gt;&lt;br /&gt;size_t dfread(void *ptr,size_t size,size_t nmemb, FILE *stream) {&lt;br /&gt;     size_t n;&lt;br /&gt;     n = fread(ptr,size,nmemb,stream);&lt;br /&gt;     madvise(ptr,size*nmemb,MADV_DONTNEED);&lt;br /&gt;     return n;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;(h) if we're to just flush the entire buffercache, on the 2.6.16+ kernels we could use a a "drop caches" mechanism to free all pages from buffcache :&lt;br /&gt;&lt;pre&gt;echo 1 &gt; /proc/sys/vm/drop_caches&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37856708-776003063248627441?l=devcs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://devcs.blogspot.com/feeds/776003063248627441/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37856708&amp;postID=776003063248627441' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/776003063248627441'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/776003063248627441'/><link rel='alternate' type='text/html' href='http://devcs.blogspot.com/2007/12/linux-buffer-cache-how-to-disable-it.html' title='Linux buffer cache &amp; how to disable it  (and why ?)'/><author><name>Alek</name><uri>http://www.blogger.com/profile/07619493115870095288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37856708.post-116510092172613301</id><published>2006-12-03T00:08:00.000+01:00</published><updated>2006-12-03T15:36:22.450+01:00</updated><title type='text'>Topics in compiler implementation</title><content type='html'>&lt;span style="font-size:85%;"&gt;Some compiler-related ideas &amp; problems (&lt;span style="font-style: italic;"&gt;Appel : Modern compiler implementation in Java&lt;/span&gt;):&lt;br /&gt;- Instruction selection : Machine instructions are represented by tree pattern. The optimal code is generated by selecting tree patterns which form the minimum tree. Thus, instruction selection becomes a task of tiling the tree with minimal set of tree patterms. There is a number of approaches to this problem, most notably, the Maximal Munch algorithm and Dynamic Programming.&lt;br /&gt;In pratice, tree pattern - based approach can be a problem when optimizing for cics, rather than risc machine...&lt;br /&gt;- Liveness Analysis : In order to optimize the register allocation, the compiler must analyze which variables are used ("alive") during every segment of program (for example, we can observe every basic block as one segment). Variables which are not used at the same time can be allocated in the same register. We observe the control-flow-graph of the program and determine the "live" variables at every edge of the graph. Then, we can perform graph partitioning in order to divide the program into segments with a number of alive variables which correspond to number of system registers. Again, we should do this in a optimal manner (every segment should allocate all registers, but among segments there should be minimum needed transfer of data between registers and memory).&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37856708-116510092172613301?l=devcs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://devcs.blogspot.com/feeds/116510092172613301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37856708&amp;postID=116510092172613301' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/116510092172613301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/116510092172613301'/><link rel='alternate' type='text/html' href='http://devcs.blogspot.com/2006/12/topics-in-compiler-implementation_03.html' title='Topics in compiler implementation'/><author><name>Alek</name><uri>http://www.blogger.com/profile/07619493115870095288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37856708.post-116506706016911984</id><published>2006-12-02T14:39:00.000+01:00</published><updated>2006-12-02T20:13:02.490+01:00</updated><title type='text'>Notes on automata theory</title><content type='html'>&lt;span style="font-size:85%;"&gt;Remarks from &lt;/span&gt;&lt;span style="font-style: italic;font-size:85%;" &gt;Motwani, Hopcroft &amp; Ullman&lt;/span&gt;&lt;span style="font-size:85%;"&gt; : &lt;/span&gt;&lt;span style="font-weight: bold;font-size:85%;" &gt;Introduction to Automata Theory, Languages and Computation&lt;/span&gt;&lt;span style="font-size:85%;"&gt; (during 45min reading) :&lt;br /&gt;&lt;/span&gt;&lt;span style="font-style: italic;font-size:85%;" &gt;Chapter 2 : Finite Automata&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;- Give an example of practical communication/transaction protocol which can only be analyzed via automata model&lt;br /&gt;- Examples of structural patterns which require formal verification of correctness ?&lt;br /&gt;- Complexity bound for automata which require formal verification?&lt;br /&gt;(even in the case of 2 simple, say 4-state automata, their single interconnection yields a product of automata resulting in 16-state automata )&lt;br /&gt;&lt;br /&gt;- Optimal representation of DFA ? (space-efficient Transition Tables). Alternative methods of representation ?&lt;br /&gt;- Algorithm-efficient representations ? (ex. finding all loops in automation by observing transition table -&gt; can we speedup the algoritm by using structure other than table)&lt;br /&gt;&lt;br /&gt;A NFA models the ability of input to "guess" the right state. Actually this can be seen as increasing complexity in order to simplify the description. The automata can reduce complexity of the problem by increasing the description. However, there are problems that cannot be treated in this manner.&lt;br /&gt;&lt;br /&gt;A NFA is more descriptive than DFA, while there should be a 1-1 mapping NFA &lt;-&gt; DFA (Using a Tompson's algorithm , we can efficiently construct the DFA corresponding to NFA). Still, a NFA of size N corresponds to a DFA of size N+K . How do we prove the 1-1 mapping then ?&lt;br /&gt;&lt;br /&gt;- [Offtopic] -&gt; how can we efficiently create a program for automata generation via feeding it with a list of input examples and accept/reject results for each example ?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37856708-116506706016911984?l=devcs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://devcs.blogspot.com/feeds/116506706016911984/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37856708&amp;postID=116506706016911984' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/116506706016911984'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/116506706016911984'/><link rel='alternate' type='text/html' href='http://devcs.blogspot.com/2006/12/notes-on-automata-theory.html' title='Notes on automata theory'/><author><name>Alek</name><uri>http://www.blogger.com/profile/07619493115870095288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-37856708.post-116506663729439873</id><published>2006-12-02T14:36:00.000+01:00</published><updated>2006-12-02T14:37:17.303+01:00</updated><title type='text'>&amp; stuff.....</title><content type='html'>Here it is... I will be typing some random stuff on development, cs &amp; stuff...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/37856708-116506663729439873?l=devcs.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://devcs.blogspot.com/feeds/116506663729439873/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=37856708&amp;postID=116506663729439873' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/116506663729439873'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/37856708/posts/default/116506663729439873'/><link rel='alternate' type='text/html' href='http://devcs.blogspot.com/2006/12/stuff.html' title='&amp; stuff.....'/><author><name>Alek</name><uri>http://www.blogger.com/profile/07619493115870095288</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
