In message <c810d5090804292307y2884b169t5c27b50fb7c94c30@mail.gmail.com>, "NAGABHUSHAN BS" writes:[...] Here's one idea: 1. Your main data structure is a linear array of struct dirents. You perform seekdir/readdir on this linear structure, which should be trivial. Each time you find a dirent which definitely needs to go into this structure, you append to it. If you're about to run out of space in it, you can realloc it 2x its previous size (a common technique). This structure remains cached in memory for as long as the directory is open. Optimization 1: you can keep it cached past close(fd), b/c recursive programs like /bin/find may close and reopen a directory several times. But you'll need to determine if the directory's mtime had changed and if so, purge the cached content and reconstruct it. Optimization 2: if you can do a stat(2) on each directory in the union, and sum their total size, that'll provide you with an upper bound on the size of your dirent cache. In that case, you can forego the realloc I mentioned, and just malloc one large array at once. This could be more efficient than realloc'ing for two reasons: (a) realloc may have to memcpy data, which you can avoid; and (b) the rest of the malloc'ed array, near its end, may be unused, but as long as you don't touch it, it'll be one large-ish extent of virtual memory for which physical page frames won't be actually needed. Even better, you can realloc() that large malloc'ed area to cut back on its size to exactly what you need. 2. During the construction of the dirent array above, you keep two hash tables: 2a. HT1 is used for duplicate elimination. It contains POINTERS ONLY (or offsets) into the dirent cache buffer. You add entries into it each time you append a name to the dirent cache array. This HT1 allows you to quickly find out if a string name had been seen before. When you're done constructing the dirent cache, free(HT1). 2b. HT2 is used for whiteouts. It contains the actual strings of whited-out entries you've seen, which you add each time you find a whiteout. You look this HT2 each time you need to determine if an entry you're about to add to the dirent cache had been whited-out or not. When you're done constructing the dirent cache, free(HT2). Hope you can use this as a starting point. Cheers, Erez. -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
| Chuck Ebbert | Why do so many machines need "noapic"? |
| Linus Torvalds | Linux 2.6.27 |
| Alan Cox | Re: Dual-Licensing Linux Kernel with GPL V2 and GPL V3 |
| Bart Van Assche | Re: Integration of SCST in the mainstream Linux kernel |
git: | |
| Frank Lichtenheld | Re: Trying to use git-filter-branch to compress history by removing large, obsolet... |
| Imran M Yousuf | Re: [kernel.org users] [RFD] On deprecating "git-foo" for builtins |
| Petr Baudis | Re: VCS comparison table |
| Aubrey Li | git clone problem through HTTP |
| Richard Stallman | Real men don't attack straw men |
| Marcos Laufer | dmesg IBM x3650 OpenBSD 4.3 |
| Parvinder Bhasin | OpenBSD and SYNFlood / DDoS protection |
| sonjaya | openvpn on openbsd 4.1 |
| Hugh Dickins | Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin" |
| Arjan van de Ven | Re: [GIT]: Networking |
| Jens Axboe | Re: [BUG] New Kernel Bugs |
| Francois Romieu | Re: 8169 Intermittent ifup Failure Issue With RTL8102E Chipset in Intel's New D945... |
| Shared swap partition | 9 hours ago | Linux general |
| high memory | 2 days ago | Linux kernel |
| semaphore access speed | 2 days ago | Applications and Utilities |
| the kernel how to power off the machine | 2 days ago | Linux kernel |
| Easter Eggs in windows XP | 2 days ago | Windows |
| Root password | 2 days ago | Linux general |
| Where/when DNOTIFY is used? | 2 days ago | Linux kernel |
| How to convert Linux Kernel built-in module into a loadable module | 2 days ago | Linux kernel |
| Linux 2.6.24 and I/O schedulers | 2 days ago | Linux kernel |
| USB Driver -- Interrupt Polling -- A Little Help Please | 2 days ago | Linux general |
