I have found this pice of code in xfs_repair.c:<br><br>/*<br> * Adjust libxfs cache sizes based on system memory,<br> * filesystem size and inode count.<br> *<br> * We'll set the cache size based on 3/4s the memory minus<br>
* space used by the inode AVL tree and block usage map.<br> *<br> * Inode AVL tree space is approximately 4 bytes per inode,<br> * block usage map is currently 1 byte for 2 blocks.<br> *<br>
* We assume most blocks will be inode clusters.<br> *<br> * Calculations are done in kilobyte units.<br> */<br><br> if (!bhash_option_used || max_mem_specified) {<br> unsigned long mem_used;<br>
unsigned long max_mem;<br> struct rlimit rlim;<br><br> libxfs_icache_purge();<br> libxfs_bcache_purge();<br> cache_destroy(libxfs_icache);<br>
cache_destroy(libxfs_bcache);<br><br> mem_used = (mp->m_sb.sb_icount >> (10 - 2)) +<br> (mp->m_sb.sb_dblocks >> (10 + 1)) +<br> 50000; /* rough estimate of 50MB overhead */<br>
max_mem = max_mem_specified ? max_mem_specified * 1024 :<br> libxfs_physmem() * 3 / 4;<br><br> if (getrlimit(RLIMIT_AS, &rlim) != -1 &&<br>
rlim.rlim_cur != RLIM_INFINITY) {<br> rlim.rlim_cur = rlim.rlim_max;<br> setrlimit(RLIMIT_AS, &rlim);<br> /* use approximately 80% of rlimit to avoid overrun */<br>
max_mem = MIN(max_mem, rlim.rlim_cur / 1280);<br> } else<br> max_mem = MIN(max_mem, (LONG_MAX >> 10) + 1);<br><br> if (verbose > 1)<br>
do_log(_(" - max_mem = %lu, icount = %llu, "<br> "imem = %llu, dblock = %llu, dmem = %llu\n"),<br> max_mem, mp->m_sb.sb_icount,<br>
mp->m_sb.sb_icount >> (10 - 2),<br> mp->m_sb.sb_dblocks,<br> mp->m_sb.sb_dblocks >> (10 + 1));<br><br> if (max_mem <= mem_used) {<br>
/*<br> * Turn off prefetch and minimise libxfs cache if<br> * physical memory is deemed insufficient<br> */<br> if (max_mem_specified) {<br>
do_abort(<br> _("Required memory for repair is greater that the maximum specified\n"<br> "with the -m option. Please increase it to at least %lu.\n"),<br>
mem_used / 1024);<br> } else {<br> do_warn(<br> _("Not enough RAM available for repair to enable prefetching.\n"<br>
"This will be _slow_.\n"<br> "You need at least %luMB RAM to run with prefetching enabled.\n"),<br> mem_used * 1280 / (1024 * 1024));<br> }<br>
do_prefetch = 0;<br> libxfs_bhash_size = 64;<br> } else {<br> max_mem -= mem_used;<br> if (max_mem >= (1 << 30))<br>
max_mem = 1 << 30;<br> libxfs_bhash_size = max_mem / (HASH_CACHE_RATIO *<br> (mp->m_inode_cluster_size >> 10));<br>
if (libxfs_bhash_size < 512)<br> libxfs_bhash_size = 512;<br> }<br><br> if (verbose)<br> do_log(_(" - block cache size set to %d entries\n"),<br>
libxfs_bhash_size * HASH_CACHE_RATIO);<br><br> if (!ihash_option_used)<br> libxfs_ihash_size = libxfs_bhash_size;<br><br> libxfs_icache = cache_init(libxfs_ihash_size,<br>
&libxfs_icache_operations);<br> libxfs_bcache = cache_init(libxfs_bhash_size,<br> &libxfs_bcache_operations);<br>
}<br><br>I'm lack of programming skills to analyze the code and create formula which would allow me to predict memory usage of xfs_repair.<br>Can some one explain how is it calculated, please?<br><br>My goal is to be able, to specify minimal requirements. <br>
<br>Cheers <br><br>Łukasz Korczyk<br><br><br><br><br><div class="gmail_quote">W dniu 4 lipca 2011 14:13 użytkownik Dave Chinner <span dir="ltr"><<a href="mailto:david@fromorbit.com">david@fromorbit.com</a>></span> napisał:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im">On Mon, Jul 04, 2011 at 11:41:49AM +0200, Łukasz Korczyk wrote:<br>
> Helo<br>
><br>
> I have a question I wasn't able to find answer for.<br>
><br>
> Which factors influence memory usage of xfs_repair?<br>
> Does any formula exist to count possible memory usage?<br>
<br>
</div># xfs_repair -n -vv -m 1 /dev/vda<br>
Phase 1 - find and verify superblock...<br>
- max_mem = 1024, icount = 64, imem = 0, dblock = 4294967296, dmem = 2097152<br>
Required memory for repair is greater that the maximum specified<br>
with the -m option. Please increase it to at least 2096.<br>
<br>
So it's telling me I need at least 2096MB of RAM to repair my 16TB<br>
filesystem, of which 2097152KB is needed for tracking free space...<br>
<br>
I just added 50 million inodes to the filesystem (it now has 50M +<br>
10 inodes in it), and the result is:<br>
<br>
# xfs_repair -vv -m 1 /dev/vda<br>
Phase 1 - find and verify superblock...<br>
- max_mem = 1024, icount = 50401792, imem = 196882, dblock = 4294967296, dmem = 2097152<br>
Required memory for repair is greater that the maximum specified<br>
with the -m option. Please increase it to at least 2289.<br>
<br>
That is now needs at least another 200MB of RAM to run.<br>
<br>
It is worth noting that these numbers are the absolute minimum<br>
required and repair may require more RAM than this to complete<br>
successfully. If you only give it this much RAM, it will be slow;<br>
for best repair performance, the more RAM you can give it the<br>
better.<br>
<br>
Cheers,<br>
<br>
Dave.<br>
<font color="#888888">--<br>
Dave Chinner<br>
<a href="mailto:david@fromorbit.com">david@fromorbit.com</a><br>
</font></blockquote></div><br>