Generic B-tree implementation
Subsystems (7)
Hello folks
I am attaching source files containing a very generic implementation of B-trees in C. The implementation corresponds to in memory B-Tree data structure. The B-tree library consists of two files, btree.h and btree.c. I am also attaching a sample program main.c which should hopefully make the use of the library clear.
I would be happy to receive inputs from the community for changes (enchancements) to the library. All the more I would like to help someone with a project which would take advantage of the B-Tree implementation.
- Vishal
PS: This code is being released under GPL version 2.
Signature · 1 line
Motivation will almost always beat mere talent.
Quoted 5 lines · Vishal Patil
I am attaching source files containing a very generic implementation of B-trees in C. The implementation corresponds to in memory B-Tree data structure. The B-tree library consists of two files,
btree.handbtree.c. I am also attaching a sample programmain.cwhich should hopefully make the use of the library clear.
B-trees are useful mainly when you can get a bunch of pointers in one swoop, i.e., by reading nodes from disk.
Quoted 4 lines
I would be happy to receive inputs from the community for changes (enchancements) to the library. All the more I would like to help someone with a project which would take advantage of the B-Tree implementation.
Build infrastructure (== library) without clear users won't go very far on LKML.
Signature · 4 lines
Dr. Horst H. von Brand User #22616 counter.li.org Departamento de Informatica Fono: +56 32 654431 Universidad Tecnica Federico Santa Maria +56 32 654239 Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513
Agreed, however if I am not mistaken B-trees are useful even for virtual memory implementation, for example HP-UX uses B-trees for managing virtual memory pages.
Also I did not get the statement
"Build infrastructure (== library) without clear users won't go very far on LKML"
- Vishal
Quoted 23 lines · Horst von Brand
Quoted 5 lines · Vishal Patil
I am attaching source files containing a very generic implementation of B-trees in C. The implementation corresponds to in memory B-Tree data structure. The B-tree library consists of two files,
btree.handbtree.c. I am also attaching a sample programmain.cwhich should hopefully make the use of the library clear.B-trees are useful mainly when you can get a bunch of pointers in one swoop, i.e., by reading nodes from disk.
Quoted 4 lines
I would be happy to receive inputs from the community for changes (enchancements) to the library. All the more I would like to help someone with a project which would take advantage of the B-Tree implementation.
Build infrastructure (== library) without clear users won't go very far on LKML.
--
Dr. Horst H. von Brand User #22616 counter.li.org
Departamento de Informatica Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria +56 32 654239
Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513
Signature · 1 line
Motivation will almost always beat mere talent.
Quoted 3 lines · Vishal Patil
Agreed, however if I am not mistaken B-trees are useful even for virtual memory implementation, for example HP-UX uses B-trees for managing virtual memory pages.
OK, sounds at least somewhat plausible..
Quoted 3 lines
Also I did not get the statement
"Build infrastructure (== library) without clear users won't go very far on LKML"
Your patch would go a lot further if it came as 2 parts:
PATCH 1/2: Add Generic B-tree implementation
PATCH 2/2: Convert mm/foobar.c to track VM pages using B-trees.
Barring an actual patch 2/2, a *clear* explanation of why it would benefit a *specific* piece of code so somebody else can do it...
Quoted 6 lines · Vishal Patil
I am attaching source files containing a very generic implementation of B-trees in C. The implementation corresponds to in memory B-Tree data structure. The B-tree library consists of two files,
btree.handbtree.c. I am also attaching a sample programmain.cwhich should hopefully make the use of the library clear.
Couple of thoughts:
1. red/black b-trees have superior worst case performance as it relates to rebalancing, and the implementation doesn't add a lot of complexity:
http://www.nist.gov/dads/HTML/redblack.html
2. Paul Vixie's b-tree implementation has been around since the mid-80's or so, and simply from an historical perspective is worth a look (comp.sources.unix anyone?):
http://www.isc.org/index.pl?/sources/devel/func/avl-subs-2.php
3. GCC uses 'splay trees' to good advantage:
http://www.nist.gov/dads/HTML/splaytree.html
which have the property that most-recently referenced nodes tend to be higher up in the tree.
Gary
I said B-Tree and not binary tree, please read the explaination about B-tree at http://en.wikipedia.org/wiki/B-tree. Also I am aware of AVL trees.
I never claimed that my implementation is better or anything like that. I posted the code so that someone in need of the data structure might use it. Also I would be willing them to help with their project.
- Vishal
Quoted 27 lines · Gary Funck
Quoted 6 lines · Vishal Patil
I am attaching source files containing a very generic implementation of B-trees in C. The implementation corresponds to in memory B-Tree data structure. The B-tree library consists of two files,
btree.handbtree.c. I am also attaching a sample programmain.cwhich should hopefully make the use of the library clear.Couple of thoughts:
1. red/black b-trees have superior worst case performance as it relates to rebalancing, and the implementation doesn't add a lot of complexity:
http://www.nist.gov/dads/HTML/redblack.html2. Paul Vixie's b-tree implementation has been around since the mid-80's or so, and simply from an historical perspective is worth a look (comp.sources.unix anyone?):
http://www.isc.org/index.pl?/sources/devel/func/avl-subs-2.php3. GCC uses 'splay trees' to good advantage:
http://www.nist.gov/dads/HTML/splaytree.html
which have the property that most-recently referenced nodes tend to be higher up in the tree.
Signature · 1 line
Motivation will almost always beat mere talent.
Quoted 7 lines · Vishal Patil
I said B-Tree and not binary tree, please read the explaination about B-tree at http://en.wikipedia.org/wiki/B-tree. Also I am aware of AVL trees.
I never claimed that my implementation is better or anything like that. I posted the code so that someone in need of the data structure might use it. Also I would be willing them to help with their project.
My reason for pointing out the other data strucutres is to note that there might be search tree representations that are more appropriate for implementation inside the kernel, and to perhaps encourage you to have a look at implementing them as well. Red-black trees in particular have the property that they're reasonably well-balanced, and that the balancing algorithm makes use of local information. That means that the kernel might be able to limit the level of locking required to update the tree.
I liked your B-tree implementation, and have saved a copy. Too bad there isn't the C/C++ equivalent of CPAN (comp.unix.sources is so passe`). Your B-tree implementation would make a nice addition to an archive of handy C algorithm implementations.
Quoted 4 lines · Gary Funck
I liked your B-tree implementation, and have saved a copy. Too bad there isn't the C/C++ equivalent of CPAN (comp.unix.sources is so passe`). Your B-tree implementation would make a nice addition to an archive of handy C algorithm implementations.
FWIW C++ has http://boost.org/... and C has /usr/lib/ :)
-Bob
B-trees are good for parellel updates as well. Anyway it would be great to have inputs from other folks about how B-trees could help inside the kernel (if at all)
- Vishal
Quoted 23 lines · Gary Funck
Quoted 7 lines · Vishal Patil
I said B-Tree and not binary tree, please read the explaination about B-tree at http://en.wikipedia.org/wiki/B-tree. Also I am aware of AVL trees.
I never claimed that my implementation is better or anything like that. I posted the code so that someone in need of the data structure might use it. Also I would be willing them to help with their project.
My reason for pointing out the other data strucutres is to note that there might be search tree representations that are more appropriate for implementation inside the kernel, and to perhaps encourage you to have a look at implementing them as well. Red-black trees in particular have the property that they're reasonably well-balanced, and that the balancing algorithm makes use of local information. That means that the kernel might be able to limit the level of locking required to update the tree.
I liked your B-tree implementation, and have saved a copy. Too bad there isn't the C/C++ equivalent of CPAN (comp.unix.sources is so passe`). Your B-tree implementation would make a nice addition to an archive of handy C algorithm implementations.
Signature · 1 line
Motivation will almost always beat mere talent.
Quoted 3 lines · Vishal Patil
B-trees are good for parellel updates as well. Anyway it would be great to have inputs from other folks about how B-trees could help inside the kernel (if at all)
B-trees are mostly used in file systems in the kernel. For example NTFS and HFS (and I think HPFS) use B-trees for various metadata like directory indexes for example.
But of course your implementation is purely userspace and cannot be used in the kernel (you use recursion for example...) so I am not sure how you envisage to help the kernel with your code...
Best regards,
Anton
Signature · 4 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
I can get rid of recursions using loops, will need to work a little more on it.
Also I will be working on developing a patch for VM management using B-trees instead of RB-trees.
- Vishal
Quoted 23 lines · Anton Altaparmakov
Quoted 3 lines · Vishal Patil
B-trees are good for parellel updates as well. Anyway it would be great to have inputs from other folks about how B-trees could help inside the kernel (if at all)
B-trees are mostly used in file systems in the kernel. For example NTFS and HFS (and I think HPFS) use B-trees for various metadata like directory indexes for example.
But of course your implementation is purely userspace and cannot be used in the kernel (you use recursion for example...) so I am not sure how you envisage to help the kernel with your code...
Best regards,
Anton
--
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @) Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/
Signature · 1 line
Motivation will almost always beat mere talent.
Quoted 2 lines · Vishal Patil
I can get rid of recursions using loops, will need to work a little more on it.
Before doing the above you may want to learn about all possible malloc retvals too and to make sure the interface has all needed oom failure paths that you're obviously missing.
One of the advantages of rbtree vs b-trees (and vs radixtrees too) is the fact they require zero dynamic metadata allocations of ram. They use the same trick of list.h to avoid it while still being mostly generic and sharable library code. Imagine rbtrees like scalable lists. The kernel usage is quite optimized too, the mmap path for example does a single lookup and it stores the last "lookup" point before restarting with an insertion while keeping the mmap_sem (or mutex renaming of the day) on hold so to avoid the insertion operation to start over with a second (wasteful) lookup (again very similar to what you could do if you had list, and the rebalancing is a very immediate operation too involving only a limited number of pointers).
Quoted 2 lines
Also I will be working on developing a patch for VM management using B-trees instead of RB-trees.
Once you start changing those bits, you'll notice the further requirement of the btrees due to the oom failures in code paths that are already reasonably complex with vma oom failures.
As speed of cache raises faster than speed of ram, memory seeks tends to cost more than they did in the past, but I doubt it worth it, most important especially in the common case of very few vmas. I like the common case of only a few dozen vmas to be so fast and low overhead. The corner cases like uml and oracle already use nonlinear, to also avoid the ram overhead of the vmas, with btree the lowmem overhead would be even higher (the only 4/8 bytes of overhead of the rbtrees would even be fixable with David's patch, but nobody considered it very important so far to eliminate those 4/8 bytes 32bit/64bit per vma, though we can do that in the future). So even if btree would be faster for those extreme corner cases, it would still not be a replacement for the nonlinear (I wish there was a decent replacement for nonlinear, whose only reason to exist seems to be uml on 64bit archs).
If I would be in you, as a slightly more likely to succeed experiment, I would be looking into replacing the pagecache radix-tree with a btree, as long as you can leave intact the tagging properties we have in the radix-tree needed for finding only dirty elements in the tree etc... (we use that to avoid separate dirty lists for the pages). You should also size the order to automatically match the cache size of the arch (dunno if it's better at compile or run time). I'm no a radix-tree guru but the btree may save some ram if you've all pagecache pages scattered all over the place with random access. It also won't require all levels to be allocated. However it will require rebalancing, something the radix tree doesn't require, it seems a bit of a tradeoff, and I suspect the radix-tree will still win in all common cases. But at least all oom failure paths should already exists for you, so that should avoid you having to touch much code externally to your own btree files.
I wish you to have fun with the btrees, I remember I had fun back then when I was playing with the rbtrees ;).
Andrea
Thank you for your time and a very valuable input. I was thinking of implementing the VM management using B-trees because I wanted to play with something interesting in the kernel. However I will definately look into your idea of page cache as well.
Will keep everyone informed about my progress.
- Vishal
Quoted 61 lines · Andrea Arcangeli
Quoted 2 lines · Vishal Patil
I can get rid of recursions using loops, will need to work a little more on it.
Before doing the above you may want to learn about all possible malloc retvals too and to make sure the interface has all needed oom failure paths that you're obviously missing.
One of the advantages of rbtree vs b-trees (and vs radixtrees too) is the fact they require zero dynamic metadata allocations of ram. They use the same trick of
list.hto avoid it while still being mostly generic and sharable library code. Imagine rbtrees like scalable lists. The kernel usage is quite optimized too, the mmap path for example does a single lookup and it stores the last "lookup" point before restarting with an insertion while keeping themmap_sem(or mutex renaming of the day) on hold so to avoid the insertion operation to start over with a second (wasteful) lookup (again very similar to what you could do if you had list, and the rebalancing is a very immediate operation too involving only a limited number of pointers).Quoted 2 lines
Also I will be working on developing a patch for VM management using B-trees instead of RB-trees.
Once you start changing those bits, you'll notice the further requirement of the btrees due to the oom failures in code paths that are already reasonably complex with vma oom failures.
As speed of cache raises faster than speed of ram, memory seeks tends to cost more than they did in the past, but I doubt it worth it, most important especially in the common case of very few vmas. I like the common case of only a few dozen vmas to be so fast and low overhead. The corner cases like uml and oracle already use nonlinear, to also avoid the ram overhead of the vmas, with btree the lowmem overhead would be even higher (the only 4/8 bytes of overhead of the rbtrees would even be fixable with David's patch, but nobody considered it very important so far to eliminate those 4/8 bytes 32bit/64bit per vma, though we can do that in the future). So even if btree would be faster for those extreme corner cases, it would still not be a replacement for the nonlinear (I wish there was a decent replacement for nonlinear, whose only reason to exist seems to be uml on 64bit archs).
If I would be in you, as a slightly more likely to succeed experiment, I would be looking into replacing the pagecache radix-tree with a btree, as long as you can leave intact the tagging properties we have in the radix-tree needed for finding only dirty elements in the tree etc... (we use that to avoid separate dirty lists for the pages). You should also size the order to automatically match the cache size of the arch (dunno if it's better at compile or run time). I'm no a radix-tree guru but the btree may save some ram if you've all pagecache pages scattered all over the place with random access. It also won't require all levels to be allocated. However it will require rebalancing, something the radix tree doesn't require, it seems a bit of a tradeoff, and I suspect the radix-tree will still win in all common cases. But at least all oom failure paths should already exists for you, so that should avoid you having to touch much code externally to your own btree files.
I wish you to have fun with the btrees, I remember I had fun back then when I was playing with the rbtrees ;).
Signature · 1 line
Motivation will almost always beat mere talent.
Folks
Following Andrea's suggestions I have implemented the Linux kernel page cache using B-Trees. I am attaching the patch along with this email. Note that the patch was developed against 2.6.16.2. Also the patch offers the B-tree data structure as a library (like the radix tree)
Also I haven't made any performance measurements to compare it with the radix tree implementation. However ideas to do this are most welcome.
Thanks
- Vishal
Quoted 79 lines · Vishal Patil
Andrea
Thank you for your time and a very valuable input. I was thinking of implementing the VM management using B-trees because I wanted to play with something interesting in the kernel. However I will definately look into your idea of page cache as well.
Will keep everyone informed about my progress.
- Vishal
Quoted 58 lines · Andrea Arcangeli
Quoted 2 lines · Vishal Patil
I can get rid of recursions using loops, will need to work a little more on it.
Before doing the above you may want to learn about all possible malloc retvals too and to make sure the interface has all needed oom failure paths that you're obviously missing.
One of the advantages of rbtree vs b-trees (and vs radixtrees too) is the fact they require zero dynamic metadata allocations of ram. They use the same trick of
list.hto avoid it while still being mostly generic and sharable library code. Imagine rbtrees like scalable lists. The kernel usage is quite optimized too, the mmap path for example does a single lookup and it stores the last "lookup" point before restarting with an insertion while keeping themmap_sem(or mutex renaming of the day) on hold so to avoid the insertion operation to start over with a second (wasteful) lookup (again very similar to what you could do if you had list, and the rebalancing is a very immediate operation too involving only a limited number of pointers).Quoted 2 lines
Also I will be working on developing a patch for VM management using B-trees instead of RB-trees.
Once you start changing those bits, you'll notice the further requirement of the btrees due to the oom failures in code paths that are already reasonably complex with vma oom failures.
As speed of cache raises faster than speed of ram, memory seeks tends to cost more than they did in the past, but I doubt it worth it, most important especially in the common case of very few vmas. I like the common case of only a few dozen vmas to be so fast and low overhead. The corner cases like uml and oracle already use nonlinear, to also avoid the ram overhead of the vmas, with btree the lowmem overhead would be even higher (the only 4/8 bytes of overhead of the rbtrees would even be fixable with David's patch, but nobody considered it very important so far to eliminate those 4/8 bytes 32bit/64bit per vma, though we can do that in the future). So even if btree would be faster for those extreme corner cases, it would still not be a replacement for the nonlinear (I wish there was a decent replacement for nonlinear, whose only reason to exist seems to be uml on 64bit archs).
If I would be in you, as a slightly more likely to succeed experiment, I would be looking into replacing the pagecache radix-tree with a btree, as long as you can leave intact the tagging properties we have in the radix-tree needed for finding only dirty elements in the tree etc... (we use that to avoid separate dirty lists for the pages). You should also size the order to automatically match the cache size of the arch (dunno if it's better at compile or run time). I'm no a radix-tree guru but the btree may save some ram if you've all pagecache pages scattered all over the place with random access. It also won't require all levels to be allocated. However it will require rebalancing, something the radix tree doesn't require, it seems a bit of a tradeoff, and I suspect the radix-tree will still win in all common cases. But at least all oom failure paths should already exists for you, so that should avoid you having to touch much code externally to your own btree files.
Quoted 3 lines
I wish you to have fun with the btrees, I remember I had fun back then when I was playing with the rbtrees ;).
--
Motivation will almost always beat mere talent.
Signature · 1 line
Motivation will almost always beat mere talent.
mm/filemap.c +28 -16
@@ -112,10 +112,16 @@*/ void __remove_from_page_cache (struct page *page) { +struct page * bpage;struct address_space *mapping = page->mapping; +unsigned long index = page->index; -radix_tree_delete (&mapping->page_tree, page->index); - page->mapping =NULL ; + bpage =btree_delete (&mapping->btree,mapping->btree.root,index).val; +if ( bpage != page) { +panic ("DEBUG: Deleting wrong page in remove from page" +"cache %d,0x%x\n" ,index,bpage); + } + page->mapping =NULL ; mapping->nrpages--;pagecache_acct (-1 ); }
@@ -395,12 +401,14 @@int add_to_page_cache (struct page *page,struct address_space *mapping,pgoff_t offset,gfp_t gfp_mask) { -int error =radix_tree_preload (gfp_mask & ~__GFP_HIGHMEM); - -if (error ==0 ) { +int btree_error =btree_preload (gfp_mask & ~__GFP_HIGHMEM); + +if (btree_error ==0 ) {write_lock_irq (&mapping->tree_lock); - error =radix_tree_insert (&mapping->page_tree, offset, page); -if (!error) { + btree_error = +btree_insert (&mapping->btree,offset,page); + +if (!btree_error) {page_cache_get (page);SetPageLocked (page); page->mapping = mapping;
@@ -409,9 +417,11 @@pagecache_acct (1 ); }write_unlock_irq (&mapping->tree_lock); -radix_tree_preload_end (); +if (btree_error ==0 ) { +btree_preload_end (); + } } -return error; +return btree_error; }EXPORT_SYMBOL (add_to_page_cache);
@@ -522,7 +532,7 @@struct page *page;read_lock_irq (&mapping->tree_lock); - page =radix_tree_lookup (&mapping->page_tree, offset); + page =btree_lookup (&mapping->btree,offset);if (page)page_cache_get (page);read_unlock_irq (&mapping->tree_lock);
@@ -539,7 +549,7 @@struct page *page;read_lock_irq (&mapping->tree_lock); - page =radix_tree_lookup (&mapping->page_tree, offset); + page =btree_lookup (&mapping->btree,offset);if (page &&TestSetPageLocked (page)) page =NULL ;read_unlock_irq (&mapping->tree_lock);
@@ -563,10 +573,9 @@ unsigned long offset) {struct page *page; -read_lock_irq (&mapping->tree_lock); repeat: - page =radix_tree_lookup (&mapping->page_tree, offset); + page =btree_lookup (&mapping->btree,offset);if (page) {page_cache_get (page);if (TestSetPageLocked (page)) {
@@ -658,8 +667,10 @@unsigned int ret;read_lock_irq (&mapping->tree_lock); - ret =radix_tree_gang_lookup (&mapping->page_tree, - (void **)pages, start, nr_pages); + + ret =btree_gang_lookup (&mapping->btree,(void **)pages, + start,nr_pages); +for (i =0 ; i < ret; i++)page_cache_get (pages[i]);read_unlock_irq (&mapping->tree_lock);
@@ -677,8 +688,9 @@unsigned int ret;read_lock_irq (&mapping->tree_lock); - ret =radix_tree_gang_lookup_tag (&mapping->page_tree, + ret =btree_gang_lookup_tag (&mapping->btree, (void **)pages, *index, nr_pages, tag); +for (i =0 ; i < ret; i++)page_cache_get (pages[i]);if (ret)
mm/page-writeback.c +45 -10
93 lines not on this page · raw message
mm/readahead.c +2 -1
@@ -282,7 +282,8 @@if (page_offset > end_index)break ; - page =radix_tree_lookup (&mapping->page_tree, page_offset); + page =btree_lookup (&mapping->btree,page_offset); +if (page)continue ;
mm/swap_state.c +20 -8
@@ -37,6 +37,7 @@struct address_space swapper_space = { .page_tree =RADIX_TREE_INIT (GFP_ATOMIC |__GFP_NOWARN), + .btree =BTREE_INIT (GFP_ATOMIC |__GFP_NOWARN), .tree_lock =RW_LOCK_UNLOCKED , .a_ops = &swap_aops, .i_mmap_nonlinear =LIST_HEAD_INIT (swapper_space.i_mmap_nonlinear),
@@ -71,16 +72,21 @@static int __add_to_swap_cache (struct page *page,swp_entry_t entry,gfp_t gfp_mask) { -int error; +int btree_error;BUG_ON (PageSwapCache (page));BUG_ON (PagePrivate (page)); - error =radix_tree_preload (gfp_mask); -if (!error) { + + btree_error =btree_preload (gfp_mask); + +if (!btree_error) {write_lock_irq (&swapper_space.tree_lock); - error =radix_tree_insert (&swapper_space.page_tree, +if (!btree_error) { + btree_error =btree_insert (&swapper_space.btree, entry.val, page); -if (!error) { + } + +if (!btree_error) {page_cache_get (page);SetPageLocked (page);SetPageSwapCache (page);
@@ -89,9 +95,12 @@pagecache_acct (1 ); }write_unlock_irq (&swapper_space.tree_lock); -radix_tree_preload_end (); + +if (!btree_error) { +btree_preload_end (); + } } -return error; +return btree_error; }static int add_to_swap_cache (struct page *page,swp_entry_t entry)
@@ -127,7 +136,10 @@BUG_ON (PageWriteback (page));BUG_ON (PagePrivate (page)); -radix_tree_delete (&swapper_space.page_tree,page_private (page)); +if (btree_delete (&swapper_space.btree,swapper_space.btree.root, +page_private (page)).val != page) { +panic ("DEBUG: Deleting wrong page from swap cache\n" ); + }set_page_private (page,0 );ClearPageSwapCache (page); total_swapcache_pages--;
mm/vmscan.c +5 -5
@@ -692,7 +692,7 @@ struct page *page, int nr_refs) {struct address_space *mapping =page_mapping (page); -struct page **radix_pointer; +struct page * btree_pointer;/* * Avoid doing any of the following work if the page count
@@ -733,12 +733,12 @@write_lock_irq (&mapping->tree_lock); - radix_pointer = (struct page **)radix_tree_lookup_slot ( - &mapping->page_tree, + btree_pointer = (struct page *)btree_lookup_slot ( + &mapping->btree,page_index (page));if (!page_mapping (page) ||page_count (page) != nr_refs || - *radix_pointer != page) { + btree_pointer != page) {write_unlock_irq (&mapping->tree_lock);return -EAGAIN ; }
@@ -759,7 +759,7 @@set_page_private (newpage,page_private (page)); } - *radix_pointer = newpage; + btree_pointer = newpage;__put_page (page);write_unlock_irq (&mapping->tree_lock);
lib/btree.c +1273 -0
1,273 lines not on this page · raw message
lib/Makefile +1 -1
@@ -3,7 +3,7 @@ # lib-y := errno.o ctype.o string.o vsprintf.o cmdline.o \ - bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \ + bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o btree.o\ idr.o div64.o int_sqrt.o bitmap.o extable.o prio_tree.o \ sha1.o
init/main.c +3 -1
@@ -84,6 +84,7 @@extern void pidmap_init (void );extern void prio_tree_init (void );extern void radix_tree_init (void ); +extern void btree_init (void );extern void free_initmem (void );extern void populate_rootfs (void );extern void driver_init (void );
@@ -529,7 +530,8 @@key_init ();security_init ();vfs_caches_init (num_physpages); -radix_tree_init (); +// radix_tree_init(); +btree_init ();signals_init ();/* rootfs populating might need page-writeback */ page_writeback_init ();
fs/buffer.c +7 -1
@@ -859,9 +859,15 @@if (page->mapping) {/* Race with truncate? */ if (mapping_cap_account_dirty (mapping))inc_page_state (nr_dirty); -radix_tree_tag_set (&mapping->page_tree, +btree_tag_set (&mapping->btree,page_index (page),PAGECACHE_TAG_DIRTY ); + +if (btree_tag_get (&mapping->btree, +page_index (page),PAGECACHE_TAG_DIRTY ) !=1 ) { +panic ("Problem setting the tag\n" ); + } + }write_unlock_irq (&mapping->tree_lock);__mark_inode_dirty (mapping->host,I_DIRTY_PAGES );
fs/inode.c +2 -0
@@ -16,6 +16,7 @@#include <linux/backing-dev.h> #include <linux/wait.h> #include <linux/hash.h> +#include <linux/btree.h> #include <linux/swap.h> #include <linux/security.h> #include <linux/pagemap.h>
@@ -196,6 +197,7 @@mutex_init (&inode->i_mutex);init_rwsem (&inode->i_alloc_sem);INIT_RADIX_TREE (&inode->i_data.page_tree,GFP_ATOMIC ); +INIT_BTREE (&inode->i_data.btree,GFP_ATOMIC );rwlock_init (&inode->i_data.tree_lock);spin_lock_init (&inode->i_data.i_mmap_lock);INIT_LIST_HEAD (&inode->i_data.private_list);
include/linux/btree.h +89 -0
89 lines not on this page · raw message
include/linux/fs.h +2 -0
@@ -214,6 +214,7 @@#include <linux/kobject.h> #include <linux/list.h> #include <linux/radix-tree.h> +#include <linux/btree.h> #include <linux/prio_tree.h> #include <linux/init.h> #include <linux/sched.h>
@@ -372,6 +373,7 @@struct address_space {struct inode *host;/* owner: inode, block_device */ struct radix_tree_root page_tree;/* radix tree of all pages */ +struct btree btree;/* BTree of all pages*/ rwlock_t tree_lock;/* and rwlock protecting it */ unsigned int i_mmap_writable;/* count VM_SHARED mappings */ struct prio_tree_root i_mmap;/* tree of private and shared mappings */