Skip to contentSkip to conversation

fsblock

RFC In review Nick Piggin 14 participants 53 messages Jun 24, 2007 – Jul 10, 2007

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

I'm announcing "fsblock" now because it is quite intrusive and so I'd like to get some thoughts about significantly changing this core part of the kernel.

fsblock is a rewrite of the "buffer layer" (ding dong the witch is dead), which I have been working on, on and off and is now at the stage where some of the basics are working-ish. This email is going to be long...

Firstly, what is the buffer layer? The buffer layer isn't really a buffer layer as in the buffer cache of unix: the block device cache is unified with the pagecache (in terms of the pagecache, a blkdev file is just like any other, but with a 1:1 mapping between offset and block).

There are filesystem APIs to access the block device, but these go through the block device pagecache as well. These don't exactly define the buffer layer either.

The buffer layer is a layer between the pagecache and the block device for block based filesystems. It keeps a translation between logical offset and physical block number, as well as meta information such as locks, dirtyness, and IO status of each block. This information is tracked via the buffer_head structure.

Why rewrite the buffer layer? Lots of people have had a desire to completely rip out the buffer layer, but we can't do that[*] because it does actually serve a useful purpose. Why the bad rap? Because the code is old and crufty, and buffer_head is an awful name. It must be among the oldest code in the core fs/vm, and the main reason is because of the inertia of so many and such complex filesystems.

[*] About the furthest we could go is use the struct page for the information otherwise stored in the buffer_head, but this would be tricky and suboptimal for filesystems with non page sized blocks and would probably bloat the struct page as well.

So why rewrite rather than incremental improvements? Incremental improvements are logically the correct way to do this, and we probably could go from buffer.c to fsblock.c in steps. But I didn't do this
because: a) the blinding pace at which things move in this area would make me an old man before it would be complete; b) I didn't actually know exactly what it was going to look like before starting on it; c) I wanted stable root filesystems and such when testing it; and d) I found it reasonably easy to have both layers coexist (it uses an extra page flag, but even that wouldn't be needed if the old buffer layer was better decoupled from the page cache).

I started this as an exercise to see how the buffer layer could be improved, and I think it is working out OK so far. The name is fsblock because it basically ties the fs layer to the block layer. I think Andrew has wanted to rename buffer_head to block before, but block is too clashy, and it isn't a great deal more descriptive than buffer_head. I believe fsblock is.

I'll go through a list of things where I have hopefully improved on the buffer layer, off the top of my head. The big caveat here is that minix is the only real filesystem I have converted so far, and complex journalled filesystems might pose some problems that water down its goodness (I don't know).

- data structure size. struct fsblock is 20 bytes on 32-bit, and 40 on 64-bit (could easily be 32 if we can have int bitops). Compare this to around 50 and 100ish for struct buffer_head. With a 4K page and 1K blocks, IO requires 10% RAM overhead in buffer heads alone. With fsblocks you're down to around 3%.

- Structure packing. A page gets a number of buffer heads that are allocated in a linked list. fsblocks are allocated contiguously, so cacheline footprint is smaller in the above situation.

- Data / metadata separation. I have a struct fsblock and a struct fsblock_meta, so we could put more stuff into the usually less used fsblock_meta without bloating it up too much. After a few tricks, these are no longer any different in my code, and dirty up the typing quite a lot (and I'm aware it still has some warnings, thanks). So if not useful this could be taken out.

- Locking. fsblocks completely use the pagecache for locking and lookups. The page lock is used, but there is no extra per-inode lock that buffer has. Would go very nicely with lockless pagecache. RCU is used for one non-blocking fsblock lookup (find_get_block), but I'd really rather hope filesystems can tolerate that blocking, and get rid of RCU completely. (actually this is not quite true because mapping->private_lock is still used for mark_buffer_dirty_inode equivalent, but that's a relatively rare operation).

- Coupling with pagecache metadata. Pagecache pages contain some metadata that is logically redundant because it is tracked in buffers as well (eg. a page is dirty if one or more buffers are dirty, or uptodate if all buffers are uptodate). This is great because means we can avoid that layer in some situations, but they can get out of sync. eg. if a filesystem writes a buffer out by hand, its pagecache page will stay dirty, and the next "writeout" will notice it has no dirty buffers and call it clean. fsblock-based writeout or readin will update page metadata too, which is cleaner. It also uses page locking for IO ops instead of an extra layer of locking which seems nice.

- No deadlocks (hopefully). The buffer layer is technically deadlocky by design, because it can require memory allocations at page writeout-time. It also has one path that cannot tolerate memory allocation failures. No such problems for fsblock, which keeps fsblock metadata around for as long as a page is dirty (this still has problems vs get_user_pages, but that's going to require an audit of all get_user_pages sites. Phew).

- In line with the above item, filesystem block allocation is performed before a page is dirtied. In the buffer layer, mmap writes can dirty a page with no backing blocks which is a problem if the filesystem is ENOSPC (patches exist for buffer.c for this).

- Block memory accessors for filesystems. If the buffer layer was to ever be replaced completely, this means block device pagecache would not be restricted to lowmem. It also doesn't have theoretical CPU cache aliasing problems that buffer heads do.

- A real "nobh" mode. nobh was created I think mainly to avoid problems with buffer_head memory consumption, especially on lowmem machines. It is basically a hack (sorry), which requires special code in filesystems, and duplication of quite a bit of tricky buffer layer code (and bugs). It also doesn't work so well for buffers with non-trivial private data (like most journalling ones). fsblock implements this with basically a few lines of code, and it shold work in situations like ext3.

- Similarly, it gets around the circular reference problem where a buffer holds a ref on a page and a page holds a ref on a buffer, but the page has been removed from pagecache. These occur with some journalled fses like ext3 ordered, and eventually fill up memory and have to be reclaimed via the LRU (which is often not a problem, but I have seen real workloads where the reclaim causes throughput to drop quite a lot).

- An inode's metadata must be tracked per-inode in order for fsync to work correctly. buffer contains helpers to do this for basic filesystems, but any block can be only the metadata for a single inode. This is not really correct for things like inode descriptor blocks. fsblock can track multiple inodes per block. (This is non trivial, and it may be overkill so it could be reverted to a simpler scheme like buffer).

- Large block support. I can mount and run an 8K block size minix3 fs on my 4K page system and it didn't require anything special in the fs. We can go up to about 32MB blocks now, and gigabyte+ blocks would only require one more bit in the fsblock flags. fsblock_superpage blocks are > PAGE_CACHE_SIZE, midpage ==, and subpage <.

Core pagecache code is pretty creaky with respect to this. I think it is mostly race free, but it requires stupid unlocking and relocking hacks because the vm usually passes single locked pages to the fs layers, and we need to lock all pages of a block in offset ascending order. This could be avoided by doing locking on only the first page of a block for locking in the fsblock layer, but that's a bit scary too. Probably better would be to move towards offset,length rather than page based fs APIs where everything can be batched up nicely and this sort of non-trivial locking can be more optimal.

Large blocks also have a performance black spot where an 8K sized and aligned write(2) would require an RMW in the filesystem. Again because of the page based nature of the fs API, and this too would be fixed if the APIs were better.

Large block memory access via filesystem uses vmap, but it will go back to kmap if the access doesn't cross a page. Filesystems really should do this because vmap is slow as anything. I've implemented a vmap cache which basically wouldn't work on 32-bit systems (because of limited vmap space) for performance testing (and yes it sometimes tries to unmap in interrupt context, I know, I'm using loop). We could possibly do a self limiting cache, but I'd rather build some helpers to hide the raw multi page access for things like bitmap scanning and bit setting etc. and avoid too much vmaps.

- Code size. I'm sure I'm still missing some things, but at the moment we can do this in about the same amount of icache as buffer.c. If we turn off large block support, I think it is around 2/3 the size.

That's basically it for now. I have a few more ideas for cool things, but there are only so many hours in a day. Comments are non-existant so far, and there is lots of debugging stuff and some things are a little dirty, but it should be slightly familiar if you understand buffer.c. I'm not so interested in hearing about trivial nitpicking at this point because things are far from final or proposed for upstream. There is still a race or two, but I think they can all be solved.

So. Comments? Is this something we want? If yes, then how would we transition from buffer.c to fsblock.c?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

PATCH 1/3 add the fsblock layer

Rewrite the buffer layer.

---
 fs/Makefile                   |    2 
 fs/buffer.c                   |   31 
 fs/fs-writeback.c             |   13 
 fs/fsblock.c                  | 2511 ++++++++++++++++++++++++++++++++++++++++++
 fs/inode.c                    |   37 
 fs/splice.c                   |    3 
 include/linux/buffer_head.h   |    1 
 include/linux/fsblock.h       |  347 +++++
 include/linux/fsblock_types.h |   70 +
 include/linux/page-flags.h    |   15 
 init/main.c                   |    2 
 mm/filemap.c                  |    7 
 mm/page_alloc.c               |    3 
 mm/swap.c                     |    7 
 mm/truncate.c                 |   93 -
 mm/vmscan.c                   |    6 
 16 files changed, 3077 insertions(+), 71 deletions(-)
include/linux/page-flags.h +15 -0
Index: linux-2.6/include/linux/page-flags.h
===================================================================
@@ -90,6 +90,8 @@
 #define PG_reclaim		17	/* To be reclaimed asap */
 #define PG_buddy		19	/* Page is free, on buddy lists */
 
+#define PG_blocks		20	/* Page has block mappings */
+
 /* PG_owner_priv_1 users should have descriptive aliases */
 #define PG_checked		PG_owner_priv_1 /* Used by some filesystems */
 
@@ -134,8 +136,17 @@ static inline void SetPageUptodate(struc
 	if (!test_and_set_bit(PG_uptodate, &page->flags))
 		page_clear_dirty(page);
 }
+static inline void TestSetPageUptodate(struct page *page)
+{
+	if (!test_and_set_bit(PG_uptodate, &page->flags)) {
+		page_clear_dirty(page);
+		return 0;
+	}
+	return 1;
+}
 #else
 #define SetPageUptodate(page)	set_bit(PG_uptodate, &(page)->flags)
+#define TestSetPageUptodate(page) test_and_set_bit(PG_uptodate, &(page)->flags)
 #endif
 #define ClearPageUptodate(page)	clear_bit(PG_uptodate, &(page)->flags)
 
@@ -217,6 +228,10 @@ static inline void SetPageUptodate(struc
 #define __SetPageBuddy(page)	__set_bit(PG_buddy, &(page)->flags)
 #define __ClearPageBuddy(page)	__clear_bit(PG_buddy, &(page)->flags)
 
+#define PageBlocks(page)	test_bit(PG_blocks, &(page)->flags)
+#define SetPageBlocks(page)	set_bit(PG_blocks, &(page)->flags)
+#define ClearPageBlocks(page)	clear_bit(PG_blocks, &(page)->flags)
+
 #define PageMappedToDisk(page)	test_bit(PG_mappedtodisk, &(page)->flags)
 #define SetPageMappedToDisk(page) set_bit(PG_mappedtodisk, &(page)->flags)
 #define ClearPageMappedToDisk(page) clear_bit(PG_mappedtodisk, &(page)->flags)
fs/Makefile +1 -1
Index: linux-2.6/fs/Makefile
===================================================================
@@ -14,7 +14,7 @@ obj-y :=	open.o read_write.o file_table.
 		stack.o
 
 ifeq ($(CONFIG_BLOCK),y)
-obj-y +=	buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o
+obj-y +=	fsblock.o buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o
 else
 obj-y +=	no-block.o
 endif
fs/fsblock.c new file +2511 -0

2,511 lines not on this page · raw message

include/linux/fsblock.h new file +347 -0

347 lines not on this page · raw message

include/linux/fsblock_types.h new file +70 -0

70 lines not on this page · raw message

init/main.c +2 -0
Index: linux-2.6/init/main.c
===================================================================
@@ -50,6 +50,7 @@
 #include <linux/key.h>
 #include <linux/unwind.h>
 #include <linux/buffer_head.h>
+#include <linux/fsblock.h>
 #include <linux/debug_locks.h>
 #include <linux/lockdep.h>
 #include <linux/pid_namespace.h>
@@ -613,6 +614,7 @@ asmlinkage void __init start_kernel(void
 	fork_init(num_physpages);
 	proc_caches_init();
 	buffer_init();
+	fsblock_init();
 	unnamed_dev_init();
 	key_init();
 	security_init();
mm/page_alloc.c +3 -0
Index: linux-2.6/mm/page_alloc.c
===================================================================
@@ -199,6 +199,7 @@ static void bad_page(struct page *page)
 	dump_stack();
 	page->flags &= ~(1 << PG_lru	|
 			1 << PG_private |
+			1 << PG_blocks	|
 			1 << PG_locked	|
 			1 << PG_active	|
 			1 << PG_dirty	|
@@ -436,6 +437,7 @@ static inline int free_pages_check(struc
 		(page->flags & (
 			1 << PG_lru	|
 			1 << PG_private |
+			1 << PG_blocks	|
 			1 << PG_locked	|
 			1 << PG_active	|
 			1 << PG_slab	|
@@ -590,6 +592,7 @@ static int prep_new_page(struct page *pa
 		(page->flags & (
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

fs/buffer.c +28 -3
Index: linux-2.6/fs/buffer.c
===================================================================

Lines of this file are not shown. View the raw message.

fs/splice.c +2 -1
Index: linux-2.6/fs/splice.c
===================================================================

Lines of this file are not shown. View the raw message.

include/linux/buffer_head.h +1 -0
Index: linux-2.6/include/linux/buffer_head.h
===================================================================

Lines of this file are not shown. View the raw message.

mm/filemap.c +6 -1
Index: linux-2.6/mm/filemap.c
===================================================================

Lines of this file are not shown. View the raw message.

mm/swap.c +5 -2
Index: linux-2.6/mm/swap.c
===================================================================

Lines of this file are not shown. View the raw message.

mm/truncate.c +44 -49

93 lines not on this page · raw message

mm/vmscan.c +3 -3
Index: linux-2.6/mm/vmscan.c
===================================================================

Lines of this file are not shown. View the raw message.

fs/fs-writeback.c +10 -3
Index: linux-2.6/fs/fs-writeback.c
===================================================================

Lines of this file are not shown. View the raw message.

fs/inode.c +29 -8
Index: linux-2.6/fs/inode.c
===================================================================

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#2 lore raw

Re: [patch 1/3] add the fsblock layer

Nick Piggin <[email protected]> writes:

[haven't read everything, just commenting on something that caught my eye]

include/linux/fsblock_types.h line 42

Quoted 5 lines
include/linux/fsblock_types.h new file +5 -0
+struct fsblock {
+	atomic_t	count;
+	union {
+		struct {
+			unsigned long	flags; /* XXX: flags could be int for better packing */

int is not supported by many architectures, but works on x86 at least.

Hmm, could define a macro DECLARE_ATOMIC_BITMAP(maxbit) that expands to the smallest possible type for each architecture. And a couple of ugly casts for set_bit et.al. but those could be also hidden in macros. Should be relatively easy to do.

-Andi

#3 lore raw

Re: [patch 1/3] add the fsblock layer

Quoted 3 lines

Hmm, could define a macro DECLARE_ATOMIC_BITMAP(maxbit) that expands to the smallest possible type for each architecture. And a couple of ugly casts for set_bit et.al. but those could be also hidden in macros. Should be relatively easy to do.

or make a "smallbit" type that is small/supported, so 64 bit if 32 bit isn't supported, otherwise 32

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw

Re: [patch 1/3] add the fsblock layer

Quoted 7 lines · Arjan van de Ven
Quoted 4 lines

Hmm, could define a macro DECLARE_ATOMIC_BITMAP(maxbit) that expands to the smallest possible type for each architecture. And a couple of ugly casts for set_bit et.al. but those could be also hidden in macros. Should be relatively easy to do.

or make a "smallbit" type that is small/supported, so 64 bit if 32 bit isn't supported, otherwise 32

That wouldn't handle the case where you only need e.g. 8 bits That's fine for x86 too. It only hates atomic accesses crossing cache line boundaries (but handles them too, just slow)

-Andi

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

Re: [patch 1/3] add the fsblock layer

In reply to Andi Kleen
Quoted 6 lines · Andi Kleen

Nick Piggin <[email protected]> writes:

[haven't read everything, just commenting on something that caught my eye]

Quoted 8 lines

include/linux/fsblock_types.h line 42

Quoted 5 lines
include/linux/fsblock_types.h new file +5 -0
+struct fsblock {
+	atomic_t	count;
+	union {
+		struct {
+			unsigned long	flags; /* XXX: flags could be int for better packing */

int is not supported by many architectures, but works on x86 at least.

Yeah, that would be nice. We could actually use this for buffer_head as well, but saving 4% there isn't so important as saving 20% for fsblock :)

Quoted 3 lines

Hmm, could define a macro DECLARE_ATOMIC_BITMAP(maxbit) that expands to the smallest possible type for each architecture. And a couple of ugly casts for set_bit et.al. but those could be also hidden in macros. Should be relatively easy to do.

Cool. It would probably be useful for other things as well.

Signature · 7 lines
SUSE Labs, Novell Inc.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw

Re: [patch 1/3] add the fsblock layer

In reply to Nick Piggin

include/linux/page-flags.h line 94

Quoted 3 lines · On Sunday June 24, [email protected] wrote:
include/linux/page-flags.h +2 -0
+#define PG_blocks		20	/* Page has block mappings */
+

I've only had a very quick look, but this line looks *very* wrong. You should be using PG_private.

There should never be any confusion about whether ->private has buffers or blocks attached as the only routines that ever look in ->private are address_space operations (or should be. I think 'NULL' is sometimes special cased, as in try_to_release_page. It would be good to do some preliminary work and tidy all that up).

Why do you think you need PG_blocks?

NeilBrown

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw

Re: [patch 1/3] add the fsblock layer

Quoted 10 lines · Neil Brown

include/linux/page-flags.h line 94

Quoted 3 lines · On Sunday June 24, [email protected] wrote:
include/linux/page-flags.h +2 -0
+#define PG_blocks		20	/* Page has block mappings */
+

I've only had a very quick look, but this line looks *very* wrong. You should be using PG_private.

Quoted 5 lines

There should never be any confusion about whether ->private has buffers or blocks attached as the only routines that ever look in ->private are address_space operations (or should be. I think 'NULL' is sometimes special cased, as in try_to_release_page. It would be good to do some preliminary work and tidy all that up).

There is a lot of confusion, actually :)
But as you see in the patch, I added a couple more aops APIs, and am working toward decoupling it as much as possible. It's pretty close after the fsblock patch... however:

Quoted 1 line

Why do you think you need PG_blocks?

Block device pagecache (buffer cache) has to be able to accept attachment of either buffers or blocks for filesystem metadata, and call into either buffer.c or fsblock.c based on that.

If the page flag is really important, we can do some awful hack like assuming the first long of the private data is flags, and those flags will tell us whether the structure is a buffer_head or fsblock ;) But for now it is just easier to use a page flag.

Signature · 7 lines
SUSE Labs, Novell Inc.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#8 lore raw

Re: [patch 1/3] add the fsblock layer

Quoted 25 lines · Nick Piggin
Quoted 10 lines · Neil Brown

include/linux/page-flags.h line 94

Quoted 3 lines · On Sunday June 24, [email protected] wrote:
include/linux/page-flags.h +2 -0
+#define PG_blocks		20	/* Page has block mappings */
+

I've only had a very quick look, but this line looks *very* wrong. You should be using PG_private.

Quoted 5 lines

There should never be any confusion about whether ->private has buffers or blocks attached as the only routines that ever look in ->private are address_space operations (or should be. I think 'NULL' is sometimes special cased, as in try_to_release_page. It would be good to do some preliminary work and tidy all that up).

There is a lot of confusion, actually :)
But as you see in the patch, I added a couple more aops APIs, and am working toward decoupling it as much as possible. It's pretty close after the fsblock patch... however:

Quoted 1 line

Why do you think you need PG_blocks?

Quoted 8 lines

Block device pagecache (buffer cache) has to be able to accept attachment of either buffers or blocks for filesystem metadata, and call into either buffer.c or fsblock.c based on that.

If the page flag is really important, we can do some awful hack like assuming the first long of the private data is flags, and those flags will tell us whether the structure is a buffer_head or fsblock ;) But for now it is just easier to use a page flag.

The block device pagecache isn't special, and certainly isn't that much code. I would suggest keeping it buffer head specific and making a second variant that does only fsblocks. This is mostly to keep the semantics of PagePrivate sane, lets not fuzz the line.

-chris

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#9 lore raw

Re: [patch 1/3] add the fsblock layer

Quoted 16 lines · Chris Mason
Quoted 4 lines · Nick Piggin
Quoted 1 line · Neil Brown

Why do you think you need PG_blocks?

Quoted 8 lines

Block device pagecache (buffer cache) has to be able to accept attachment of either buffers or blocks for filesystem metadata, and call into either buffer.c or fsblock.c based on that.

If the page flag is really important, we can do some awful hack like assuming the first long of the private data is flags, and those flags will tell us whether the structure is a buffer_head or fsblock ;) But for now it is just easier to use a page flag.

Quoted 4 lines

The block device pagecache isn't special, and certainly isn't that much code. I would suggest keeping it buffer head specific and making a second variant that does only fsblocks. This is mostly to keep the semantics of PagePrivate sane, lets not fuzz the line.

That would require a new inode and address_space for the fsblock type blockdev pagecache, wouldn't it? I just can't think of a better non-intrusive way of allowing a buffer_head filesystem and an fsblock filesystem to live on the same blkdev together.

Signature · 7 lines
SUSE Labs, Novell Inc.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#10 lore raw

Re: [patch 1/3] add the fsblock layer

Quoted 11 lines · On Tuesday June 26, [email protected] wrote:
Quoted 5 lines · Chris Mason

The block device pagecache isn't special, and certainly isn't that much code. I would suggest keeping it buffer head specific and making a second variant that does only fsblocks. This is mostly to keep the semantics of PagePrivate sane, lets not fuzz the line.

That would require a new inode and address_space for the fsblock type blockdev pagecache, wouldn't it? I just can't think of a better non-intrusive way of allowing a buffer_head filesystem and an fsblock filesystem to live on the same blkdev together.

I don't think they would ever try to. Both filesystems would bd_claim the blkdev, and only one would win.

The issue is more of a filesystem sharing a blockdev with the block-special device (i.e. open("/dev/sda1"), read) isn't it?

If a filesystem wants to attach information to the blockdev pagecache that is different to what blockdev want to attach, then I think "Yes"
- a new inode and address space is what it needs to create.

Then you get into consistency issues between the metadata and direct blockdevice access. Do we care about those?

NeilBrown

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#11 lore raw

Re: [patch 1/3] add the fsblock layer

Quoted 9 lines · Neil Brown
Quoted 7 lines · On Tuesday June 26, [email protected] wrote:
Quoted 4 lines · Chris Mason

The block device pagecache isn't special, and certainly isn't that much code. I would suggest keeping it buffer head specific and making a second variant that does only fsblocks. This is mostly to keep the semantics of PagePrivate sane, lets not fuzz the line.

Quoted 8 lines
Quoted 4 lines

That would require a new inode and address_space for the fsblock type blockdev pagecache, wouldn't it? I just can't think of a better non-intrusive way of allowing a buffer_head filesystem and an fsblock filesystem to live on the same blkdev together.

I don't think they would ever try to. Both filesystems would bd_claim the blkdev, and only one would win.

Hmm OK, I might have confused myself thinking about partitions...

Quoted 9 lines

The issue is more of a filesystem sharing a blockdev with the block-special device (i.e. open("/dev/sda1"), read) isn't it?

If a filesystem wants to attach information to the blockdev pagecache that is different to what blockdev want to attach, then I think "Yes"
- a new inode and address space is what it needs to create.

Then you get into consistency issues between the metadata and direct blockdevice access. Do we care about those?

Yeah that issue is definitely a real one. The problem is not just consistency, but "how do the block device aops even know that the PG_private page they have has buffer heads or fsblocks", so it is an oopsable condition rather than just a plain consistency issue (consistency is already not guaranteed).

Signature · 7 lines
SUSE Labs, Novell Inc.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#12 lore raw

Re: [patch 1/3] add the fsblock layer

Quoted 28 lines · Nick Piggin
Quoted 9 lines · Neil Brown
Quoted 7 lines · On Tuesday June 26, [email protected] wrote:
Quoted 4 lines · Chris Mason

The block device pagecache isn't special, and certainly isn't that much code. I would suggest keeping it buffer head specific and making a second variant that does only fsblocks. This is mostly to keep the semantics of PagePrivate sane, lets not fuzz the line.

Quoted 8 lines
Quoted 4 lines

That would require a new inode and address_space for the fsblock type blockdev pagecache, wouldn't it? I just can't think of a better non-intrusive way of allowing a buffer_head filesystem and an fsblock filesystem to live on the same blkdev together.

I don't think they would ever try to. Both filesystems would bd_claim the blkdev, and only one would win.

Hmm OK, I might have confused myself thinking about partitions...

Quoted 7 lines

The issue is more of a filesystem sharing a blockdev with the block-special device (i.e. open("/dev/sda1"), read) isn't it?

If a filesystem wants to attach information to the blockdev pagecache that is different to what blockdev want to attach, then I think "Yes"
- a new inode and address space is what it needs to create.

Quoted 8 lines
Quoted 2 lines

Then you get into consistency issues between the metadata and direct blockdevice access. Do we care about those?

Yeah that issue is definitely a real one. The problem is not just consistency, but "how do the block device aops even know that the PG_private page they have has buffer heads or fsblocks", so it is an oopsable condition rather than just a plain consistency issue (consistency is already not guaranteed).

Since we're testing new code, I would just leave the blkdev address space alone. If a filesystem wants to use fsblocks, they allocate a new inode during mount, stuff it into their private super block (or in the generic super), and use that for everything. Basically ignoring the block device address space completely.

It means there will be some inconsistency between what you get when reading the block device file and the filesystem metadata, but we've got that already (ext2 dir in page cache).

-chris

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw

Re: [patch 1/3] add the fsblock layer

Quoted 5 lines · Chris Mason

Since we're testing new code, I would just leave the blkdev address space alone. If a filesystem wants to use fsblocks, they allocate a new inode during mount, stuff it into their private super block (or in the generic super), and use that for everything. Basically ignoring the block device address space completely.

Exactly, same thing XFS does.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#14 lore raw

Re: [patch 1/3] add the fsblock layer

In reply to Nick Piggin
Quoted 2 lines · Nick Piggin

That would require a new inode and address_space for the fsblock type blockdev pagecache, wouldn't it?

Yes. That's easily possible, XFS already does it for it's own buffer cache.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#15 lore raw

Re: [patch 1/3] add the fsblock layer

In reply to Nick Piggin
Quoted 1 line · Nick Piggin

Rewrite the buffer layer.

Overall, I like the basic concepts, but it is hard to track the locking rules. Could you please write them up?

I like the way you split out the assoc_buffers from the main fsblock code, but the list setup is still something of a wart. It also provides poor ordering of blocks for writeback.

I think it makes sense to replace the assoc_buffers list head with a radix tree sorted by block number. mark_buffer_dirty_inode would up the reference count and put it into the radix, the various flushing routines would walk the radix etc.

If you wanted to be able to drop the reference count once the block was written you could have a back pointer to the appropriate inode.

-chris

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#16 lore raw

Re: [patch 1/3] add the fsblock layer

Quoted 7 lines · Chris Mason
Quoted 1 line · Nick Piggin

Rewrite the buffer layer.

Overall, I like the basic concepts, but it is hard to track the locking rules. Could you please write them up?

Yeah I will do that.

Thanks for taking a look. One thing I am thinking about is to get rid of the unmap_underlying_metadata calls from the generic code. I found they were required for minix to prevent corruption, however I don't know exactly what metadata is interfering here (maybe it is indirect blocks or something?). Anyway, I think I will make it a requirement that the filesystem has to already handle this before returning a newly allocated block -- they can probably do it more efficiently and we avoid the extra work on every block allocation.

Quoted 3 lines

I like the way you split out the assoc_buffers from the main fsblock code, but the list setup is still something of a wart. It also provides poor ordering of blocks for writeback.

Yeah, I didn't know how much effort to put in here because I don't know whether modern filesystems are going to need to implement their own management of this stuff or not.

I haven't actually instrumented this in something like ext2 to see how much IO comes from the assoc buffers...

Quoted 7 lines

I think it makes sense to replace the assoc_buffers list head with a radix tree sorted by block number. mark_buffer_dirty_inode would up the reference count and put it into the radix, the various flushing routines would walk the radix etc.

If you wanted to be able to drop the reference count once the block was written you could have a back pointer to the appropriate inode.

I was actually thinking about a radix-tree :) One annoyance is that unsigned long != sector_t :P rbtree would probably be OK.

Signature · 7 lines
SUSE Labs, Novell Inc.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#17 lore raw

PATCH 2/3 block_dev: convert to fsblock

In reply to Nick Piggin

Convert block_dev mostly to fsblocks.

---
 fs/block_dev.c              |  204 +++++++++++++++++++++++++++++++++++++++-----
 fs/buffer.c                 |  113 ++----------------------
 fs/super.c                  |    2 
 include/linux/buffer_head.h |    9 -
 include/linux/fs.h          |   29 ++++++
 5 files changed, 225 insertions(+), 132 deletions(-)
fs/block_dev.c +185 -19
Index: linux-2.6/fs/block_dev.c
===================================================================
@@ -16,7 +16,9 @@
 #include <linux/blkdev.h>
 #include <linux/module.h>
 #include <linux/blkpg.h>
+#include <linux/fsblock.h>
 #include <linux/buffer_head.h>
+#include <linux/pagevec.h>
 #include <linux/writeback.h>
 #include <linux/mpage.h>
 #include <linux/mount.h>
@@ -61,14 +63,14 @@ static void kill_bdev(struct block_devic
 {
 	if (bdev->bd_inode->i_mapping->nrpages == 0)
 		return;
-	invalidate_bh_lrus();
+	invalidate_bh_lrus(); /* XXX: this can go when buffers goes */
 	truncate_inode_pages(bdev->bd_inode->i_mapping, 0);
 }	
 
 int set_blocksize(struct block_device *bdev, int size)
 {
 	/* Size must be a power of two, and between 512 and PAGE_SIZE */
-	if (size > PAGE_SIZE || size < 512 || !is_power_of_2(size))
+	if (size < 512 || !is_power_of_2(size))
 		return -EINVAL;
 
 	/* Size cannot be smaller than the size supported by the device */
@@ -92,7 +94,7 @@ int sb_set_blocksize(struct super_block 
 	if (set_blocksize(sb->s_bdev, size))
 		return 0;
 	/* If we get here, we know size is power of two
-	 * and it's value is between 512 and PAGE_SIZE */
+	 * and it's value is >= 512 */
 	sb->s_blocksize = size;
 	sb->s_blocksize_bits = blksize_bits(size);
 	return sb->s_blocksize;
@@ -112,19 +114,12 @@ EXPORT_SYMBOL(sb_min_blocksize);
 
 static int
 blkdev_get_block(struct inode *inode, sector_t iblock,
-		struct buffer_head *bh, int create)
+                struct buffer_head *bh, int create)
 {
 	if (iblock >= max_block(I_BDEV(inode))) {
 		if (create)
 			return -EIO;
-
-		/*
-		 * for reads, we're just trying to fill a partial page.
-		 * return a hole, they will have to call get_block again
-		 * before they can fill it, and they will get -EIO at that
-		 * time
-		 */
-		return 0;
+                return 0;
 	}
 	bh->b_bdev = I_BDEV(inode);
 	bh->b_blocknr = iblock;
@@ -132,6 +127,66 @@ blkdev_get_block(struct inode *inode, se
 	return 0;
 }
 
+static int blkdev_insert_mapping(struct address_space *mapping, loff_t off,
+					size_t len, int create)
+{
+	sector_t blocknr;
+	struct inode *inode = mapping->host;
+	pgoff_t next, end;
+	struct pagevec pvec;
+	int ret = 0;
+
+	pagevec_init(&pvec, 0);
+	next = off >> PAGE_CACHE_SHIFT;
+	end = (off + len) >> PAGE_CACHE_SHIFT;
+	blocknr = off >> inode->i_blkbits;
+	while (next <= end && pagevec_lookup(&pvec, mapping, next,
+				min(end - next, (pgoff_t)PAGEVEC_SIZE))) {
+		unsigned int i;
+
+		for (i = 0; i < pagevec_count(&pvec); i++) {
+			struct fsblock *block;
+			struct page *page = pvec.pages[i];
+
+			BUG_ON(page->index != next);
+			BUG_ON(blocknr != pgoff_sector(next, inode->i_blkbits));
+			BUG_ON(!PageLocked(page));
+
+			if (blocknr >= max_block(I_BDEV(inode))) {
+				if (create)
+					ret = -ENOMEM;
+
+				/*
+				 * for reads, we're just trying to fill a
+				 * partial page.  return a hole, they will
+				 * have to call in again before they can fill
+				 * it, and they will get -EIO at that time
+				 */
+				continue; /* xxx: could be smarter, stop now */
+			}
+
+			block = page_blocks(page);
+			if (fsblock_subpage(block)) {
+				struct fsblock *b;
+				for_each_block(block, b) {
+					if (!test_bit(BL_mapped, &b->flags))
+						map_fsblock(b, blocknr);
+					blocknr++;
+				}
+			} else {
+				if (!test_bit(BL_mapped, &block->flags))
+					map_fsblock(block, blocknr);
+				blocknr++;
+			}
+			next++;
+		}
+		pagevec_release(&pvec);
+	}
+
+	return ret;
+}
+
+#if 0
 static int
 blkdev_get_blocks(struct inode *inode, sector_t iblock,
 		struct buffer_head *bh, int create)
@@ -170,6 +225,7 @@ blkdev_direct_IO(int rw, struct kiocb *i
 	return blockdev_direct_IO_no_locking(rw, iocb, inode, I_BDEV(inode),
 				iov, offset, nr_segs, blkdev_get_blocks, NULL);
 }
+#endif
 
 #if 0
 static int blk_end_aio(struct bio *bio, unsigned int bytes_done, int error)
@@ -368,24 +424,127 @@ backout:
 }
 #endif
 
+/*
+ * Write out and wait upon all the dirty data associated with a block
+ * device via its mapping.  Does not take the superblock lock.
+ */
+int sync_blockdev(struct block_device *bdev)
+{
+	int ret = 0;
+
+	if (bdev)
+		ret = filemap_write_and_wait(bdev->bd_inode->i_mapping);
+	return ret;
+}
+EXPORT_SYMBOL(sync_blockdev);
+
+/*
+ * Write out and wait upon all dirty data associated with this
+ * device.   Filesystem data as well as the underlying block
+ * device.  Takes the superblock lock.
+ */
+int fsync_bdev(struct block_device *bdev)
+{
+	struct super_block *sb = get_super(bdev);
+	if (sb) {
+		int res = fsync_super(sb);
+		drop_super(sb);
+		return res;
+	}
+	return sync_blockdev(bdev);
+}
+
+/**
+ * freeze_bdev  --  lock a filesystem and force it into a consistent state
+ * @bdev:	blockdevice to lock
+ *
+ * This takes the block device bd_mount_mutex to make sure no new mounts
+ * happen on bdev until thaw_bdev() is called.
+ * If a superblock is found on this device, we take the s_umount semaphore
+ * on it to make sure nobody unmounts until the snapshot creation is done.
+ */
+struct super_block *freeze_bdev(struct block_device *bdev)
+{
+	struct super_block *sb;
+
+	down(&bdev->bd_mount_sem);
+	sb = get_super(bdev);
+	if (sb && !(sb->s_flags & MS_RDONLY)) {
+		sb->s_frozen = SB_FREEZE_WRITE;
+		smp_wmb();
+
+		__fsync_super(sb);
+
+		sb->s_frozen = SB_FREEZE_TRANS;
+		smp_wmb();
+
+		sync_blockdev(sb->s_bdev);
+
+		if (sb->s_op->write_super_lockfs)
+			sb->s_op->write_super_lockfs(sb);
+	}
+
+	sync_blockdev(bdev);
+	return sb;	/* thaw_bdev releases s->s_umount and bd_mount_sem */
+}
+EXPORT_SYMBOL(freeze_bdev);
+
+/**
+ * thaw_bdev  -- unlock filesystem
+ * @bdev:	blockdevice to unlock
+ * @sb:		associated superblock
+ *
+ * Unlocks the filesystem and marks it writeable again after freeze_bdev().
+ */
+void thaw_bdev(struct block_device *bdev, struct super_block *sb)
+{
+	if (sb) {
+		BUG_ON(sb->s_bdev != bdev);
+
+		if (sb->s_op->unlockfs)
+			sb->s_op->unlockfs(sb);
+		sb->s_frozen = SB_UNFROZEN;
+		smp_wmb();
+		wake_up(&sb->s_wait_unfrozen);
+		drop_super(sb);
+	}
+
+	up(&bdev->bd_mount_sem);
+}
+EXPORT_SYMBOL(thaw_bdev);
+
 static int blkdev_writepage(struct page *page, struct writeback_control *wbc)
 {
-	return block_write_full_page(page, blkdev_get_block, wbc);
+	if (PagePrivate(page))
+		return block_write_full_page(page, blkdev_get_block, wbc);
+	return fsblock_write_page(page, blkdev_insert_mapping, wbc);
 }
 
 static int blkdev_readpage(struct file * file, struct page * page)
 {
-	return block_read_full_page(page, blkdev_get_block);
+	return fsblock_read_page(page, blkdev_insert_mapping);
 }
 
 static int blkdev_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to)
 {
-	return block_prepare_write(page, from, to, blkdev_get_block);
+	if (PagePrivate(page))
+		return block_prepare_write(page, from, to, blkdev_get_block);
+	return fsblock_prepare_write(page, from, to, blkdev_insert_mapping);
 }
 
 static int blkdev_commit_write(struct file *file, struct page *page, unsigned from, unsigned to)
 {
-	return block_commit_write(page, from, to);
+	if (PagePrivate(page))
+		return generic_commit_write(file, page, from, to);
+	return fsblock_commit_write(file, page, from, to);
+}
+
+static void blkdev_invalidate_page(struct page *page, unsigned long offset)
+{
+	if (PagePrivate(page))
+		block_invalidatepage(page, offset);
+	else
+		fsblock_invalidate_page(page, offset);
 }
 
 /*
@@ -840,7 +999,7 @@ static void free_bd_holder(struct bd_hol
 /**
  * find_bd_holder - find matching struct bd_holder from the block device
  *
- * @bdev:	struct block device to be searched
+ * @bdev:	struct fsblock device to be searched
  * @bo:		target struct bd_holder
  *
  * Returns matching entry with @bo in @bdev->bd_holder_list.
@@ -1272,6 +1431,10 @@ static int __blkdev_put(struct block_dev
 		bdev->bd_part_count--;
 
 	if (!--bdev->bd_openers) {
+		/*
+		 * XXX: This could go away when block dev and inode
+		 * mappings are in sync?
+		 */
 		sync_blockdev(bdev);
 		kill_bdev(bdev);
 	}
@@ -1325,11 +1488,14 @@ static long block_ioctl(struct file *fil
 const struct address_space_operations def_blk_aops = {
 	.readpage	= blkdev_readpage,
 	.writepage	= blkdev_writepage,
-	.sync_page	= block_sync_page,
+//	.sync_page	= block_sync_page, /* xxx: gone w/ explicit plugging */
 	.prepare_write	= blkdev_prepare_write,
 	.commit_write	= blkdev_commit_write,
 	.writepages	= generic_writepages,
-	.direct_IO	= blkdev_direct_IO,
+//	.direct_IO	= blkdev_direct_IO,
+	.set_page_dirty	= fsblock_set_page_dirty,
+	.invalidatepage = blkdev_invalidate_page,
+	/* XXX: .sync */
 };
 
 const struct file_operations def_blk_fops = {
fs/buffer.c +10 -103

169 lines not on this page · raw message

fs/super.c +1 -1
Index: linux-2.6/fs/super.c
===================================================================
@@ -28,7 +28,7 @@
 #include <linux/blkdev.h>
 #include <linux/quotaops.h>
 #include <linux/namei.h>
-#include <linux/buffer_head.h>		/* for fsync_super() */
+#include <linux/fs.h>			/* for fsync_super() */
 #include <linux/mount.h>
 #include <linux/security.h>
 #include <linux/syscalls.h>
include/linux/buffer_head.h +0 -9
Index: linux-2.6/include/linux/buffer_head.h
===================================================================
@@ -158,22 +158,14 @@ void end_buffer_write_sync(struct buffer
 
 /* Things to do with buffers at mapping->private_list */
 void mark_buffer_dirty_inode(struct buffer_head *bh, struct inode *inode);
-int inode_has_buffers(struct inode *);
 void invalidate_inode_buffers(struct inode *);
 int remove_inode_buffers(struct inode *inode);
 int sync_mapping_buffers(struct address_space *mapping);
 void unmap_underlying_metadata(struct block_device *bdev, sector_t block);
 
 void mark_buffer_async_write(struct buffer_head *bh);
-void invalidate_bdev(struct block_device *);
-int sync_blockdev(struct block_device *bdev);
 void __wait_on_buffer(struct buffer_head *);
 wait_queue_head_t *bh_waitq_head(struct buffer_head *bh);
-int fsync_bdev(struct block_device *);
-struct super_block *freeze_bdev(struct block_device *);
-void thaw_bdev(struct block_device *, struct super_block *);
-int fsync_super(struct super_block *);
-int fsync_no_super(struct block_device *);
 struct buffer_head *__find_get_block(struct block_device *bdev, sector_t block,
 			unsigned size);
 struct buffer_head *__getblk(struct block_device *bdev, sector_t block,
@@ -317,7 +309,6 @@ extern int __set_page_dirty_buffers(stru
 static inline void buffer_init(void) {}
 static inline int try_to_free_buffers(struct page *page) { return 1; }
 static inline int sync_blockdev(struct block_device *bdev) { return 0; }
-static inline int inode_has_buffers(struct inode *inode) { return 0; }
 static inline void invalidate_inode_buffers(struct inode *inode) {}
 static inline int remove_inode_buffers(struct inode *inode) { return 1; }
 static inline int sync_mapping_buffers(struct address_space *mapping) { return 0; }
include/linux/fs.h +29 -0
Index: linux-2.6/include/linux/fs.h
===================================================================
@@ -430,6 +430,20 @@ struct address_space_operations {
 	int (*migratepage) (struct address_space *,
 			struct page *, struct page *);
 	int (*launder_page) (struct page *);
+
+	/*
+	 * release_mapping releases any private data on the mapping so that
+	 * it may be reclaimed. Returns 1 on success or 0 on failure. Second
+	 * parameter 'force' causes dirty data to be invalidated. (XXX: could
+	 * have other flags like sync/async, etc).
+	 */
+	int (*release)(struct address_space *, int);
+
+	/*
+	 * sync writes back and waits for any private data on the mapping,
+	 * as a data consistency operation.
+	 */
+	int (*sync)(struct address_space *);
 };
 
 struct backing_dev_info;
@@ -497,6 +511,14 @@ struct block_device {
 int mapping_tagged(struct address_space *mapping, int tag);
 
 /*
+ * Does this mapping have anything on its private list?
+ */
+static inline int mapping_has_private(struct address_space *mapping)
+{
+	return !list_empty(&mapping->private_list);
+}
+
+/*
  * Might pages of this file be mapped into userspace?
  */
 static inline int mapping_mapped(struct address_space *mapping)
@@ -1503,6 +1525,13 @@ extern void bd_forget(struct inode *inod
 extern void bdput(struct block_device *);
 extern struct block_device *open_by_devnum(dev_t, unsigned);
 extern const struct address_space_operations def_blk_aops;
+void invalidate_bdev(struct block_device *);
+int sync_blockdev(struct block_device *bdev);
+struct super_block *freeze_bdev(struct block_device *);
+void thaw_bdev(struct block_device *, struct super_block *);
+int fsync_bdev(struct block_device *);
+int fsync_super(struct super_block *);
+int fsync_no_super(struct block_device *);
 #else
 static inline void bd_forget(struct inode *inode) {}
 #endif

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#18 lore raw

PATCH 3/3 minix: convert to fsblock

In reply to Nick Piggin

Convert minix from buffer head to fsblock.

---
 fs/minix/bitmap.c       |  148 +++++++++++++++++++++----------
 fs/minix/file.c         |    6 -
 fs/minix/inode.c        |  172 ++++++++++++++++++++++--------------
 fs/minix/itree_common.c |  227 ++++++++++++++++++++++++++++++++----------------
 fs/minix/itree_v1.c     |    7 -
 fs/minix/itree_v2.c     |    7 -
 fs/minix/minix.h        |   17 ++-
 7 files changed, 382 insertions(+), 202 deletions(-)
fs/minix/minix.h +10 -7
Index: linux-2.6/fs/minix/minix.h
===================================================================
@@ -1,4 +1,5 @@
 #include <linux/fs.h>
+#include <linux/fsblock.h>
 #include <linux/pagemap.h>
 #include <linux/minix_fs.h>
 
@@ -37,16 +38,18 @@ struct minix_sb_info {
 	int s_dirsize;
 	int s_namelen;
 	int s_link_max;
-	struct buffer_head ** s_imap;
-	struct buffer_head ** s_zmap;
-	struct buffer_head * s_sbh;
+	struct fsblock_meta ** s_imap;
+	struct fsblock_meta ** s_zmap;
+	struct fsblock_meta * s_smblock;
 	struct minix_super_block * s_ms;
 	unsigned short s_mount_state;
 	unsigned short s_version;
 };
 
-extern struct minix_inode * minix_V1_raw_inode(struct super_block *, ino_t, struct buffer_head **);
-extern struct minix2_inode * minix_V2_raw_inode(struct super_block *, ino_t, struct buffer_head **);
+extern struct minix_inode * minix_V1_raw_inode(struct super_block *, ino_t, struct fsblock_meta **);
+extern void minix_put_raw_inode(struct super_block *sb, ino_t ino, struct fsblock_meta *mblock, struct minix_inode *p);
+extern struct minix2_inode * minix_V2_raw_inode(struct super_block *, ino_t, struct fsblock_meta **);
+extern void minix2_put_raw_inode(struct super_block *sb, ino_t ino, struct fsblock_meta *mblock, struct minix2_inode *p);
 extern struct inode * minix_new_inode(const struct inode * dir, int * error);
 extern void minix_free_inode(struct inode * inode);
 extern unsigned long minix_count_free_inodes(struct minix_sb_info *sbi);
@@ -60,8 +63,8 @@ extern void V2_minix_truncate(struct ino
 extern void minix_truncate(struct inode *);
 extern int minix_sync_inode(struct inode *);
 extern void minix_set_inode(struct inode *, dev_t);
-extern int V1_minix_get_block(struct inode *, long, struct buffer_head *, int);
-extern int V2_minix_get_block(struct inode *, long, struct buffer_head *, int);
+extern int V1_minix_insert_mapping(struct address_space *, loff_t, size_t, int);
+extern int V2_minix_insert_mapping(struct address_space *, loff_t, size_t, int);
 extern unsigned V1_minix_blocks(loff_t, struct super_block *);
 extern unsigned V2_minix_blocks(loff_t, struct super_block *);
 
fs/minix/itree_common.c +155 -72

405 lines not on this page · raw message

fs/minix/itree_v1.c +3 -4
Index: linux-2.6/fs/minix/itree_v1.c
===================================================================
@@ -1,4 +1,4 @@
-#include <linux/buffer_head.h>
+#include <linux/fsblock.h>
 #include "minix.h"
 
 enum {DEPTH = 3, DIRECT = 7};	/* Only double indirect */
@@ -44,10 +44,9 @@ static int block_to_path(struct inode * 
 
 #include "itree_common.c"
 
-int V1_minix_get_block(struct inode * inode, long block,
-			struct buffer_head *bh_result, int create)
+int V1_minix_insert_mapping(struct address_space *mapping, loff_t off, size_t len, int create)
 {
-	return get_block(inode, block, bh_result, create);
+	return insert_mapping(mapping, off, len, create);
 }
 
 void V1_minix_truncate(struct inode * inode)
fs/minix/itree_v2.c +3 -4
Index: linux-2.6/fs/minix/itree_v2.c
===================================================================
@@ -1,4 +1,4 @@
-#include <linux/buffer_head.h>
+#include <linux/fsblock.h>
 #include "minix.h"
 
 enum {DIRECT = 7, DEPTH = 4};	/* Have triple indirect */
@@ -50,10 +50,9 @@ static int block_to_path(struct inode * 
 
 #include "itree_common.c"
 
-int V2_minix_get_block(struct inode * inode, long block,
-			struct buffer_head *bh_result, int create)
+int V2_minix_insert_mapping(struct address_space *mapping, loff_t off, size_t len, int create)
 {
-	return get_block(inode, block, bh_result, create);
+	return insert_mapping(mapping, off, len, create);
 }
 
 void V2_minix_truncate(struct inode * inode)
fs/minix/bitmap.c +100 -48

311 lines not on this page · raw message

fs/minix/inode.c +108 -64

399 lines not on this page · raw message

fs/minix/file.c +3 -3
Index: linux-2.6/fs/minix/file.c
===================================================================
@@ -6,7 +6,7 @@
  *  minix regular file handling primitives
  */
 
-#include <linux/buffer_head.h>		/* for fsync_inode_buffers() */
+#include <linux/fsblock.h>
 #include "minix.h"
 
 /*
@@ -21,7 +21,7 @@ const struct file_operations minix_file_
 	.aio_read	= generic_file_aio_read,
 	.write		= do_sync_write,
 	.aio_write	= generic_file_aio_write,
-	.mmap		= generic_file_mmap,
+	.mmap		= fsblock_file_mmap,
 	.fsync		= minix_sync_file,
 	.sendfile	= generic_file_sendfile,
 };
@@ -36,7 +36,7 @@ int minix_sync_file(struct file * file, 
 	struct inode *inode = dentry->d_inode;
 	int err;
 
-	err = sync_mapping_buffers(inode->i_mapping);
+	err = fsblock_sync(inode->i_mapping);
 	if (!(inode->i_state & I_DIRTY))
 		return err;
 	if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
#19 lore raw
In reply to Nick Piggin

Just clarify a few things. Don't you hate rereading a long work you wrote? (oh, you're supposed to do that *before* you press send?).

Quoted 10 lines · Nick Piggin

I'm announcing "fsblock" now because it is quite intrusive and so I'd like to get some thoughts about significantly changing this core part of the kernel.

fsblock is a rewrite of the "buffer layer" (ding dong the witch is dead), which I have been working on, on and off and is now at the stage where some of the basics are working-ish. This email is going to be long...

Quoted 5 lines

Firstly, what is the buffer layer? The buffer layer isn't really a buffer layer as in the buffer cache of unix: the block device cache is unified with the pagecache (in terms of the pagecache, a blkdev file is just like any other, but with a 1:1 mapping between offset and block).

I mean, in Linux, the block device cache is unified. UNIX I believe did all its caching in a buffer cache, below the filesystem.

Quoted 2 lines

- Large block support. I can mount and run an 8K block size minix3 fs on my 4K page system and it didn't require anything special in the fs. We

Oh, and I don't have a Linux mkfs that makes minixv3 filesystems. I had an image kindly made for me because I don't use minix. If you want to test large block support, I won't email it to you though:
you can just convert ext2 or ext3 to fsblock ;)

#20 lore raw
In reply to Nick Piggin
Quoted 11 lines · Nick Piggin

- No deadlocks (hopefully). The buffer layer is technically deadlocky by design, because it can require memory allocations at page writeout-time. It also has one path that cannot tolerate memory allocation failures. No such problems for fsblock, which keeps fsblock metadata around for as long as a page is dirty (this still has problems vs get_user_pages, but that's going to require an audit of all get_user_pages sites. Phew).

- In line with the above item, filesystem block allocation is performed before a page is dirtied. In the buffer layer, mmap writes can dirty a page with no backing blocks which is a problem if the filesystem is ENOSPC (patches exist for buffer.c for this).

This raises an eyebrow... The handling of ENOSPC prior to mmap write is more an ABI behavior, so I don't see how this can be fixed with internal changes, yet without changing behavior currently exported to userland (and thus affecting code based on such assumptions).

Quoted 7 lines

- An inode's metadata must be tracked per-inode in order for fsync to work correctly. buffer contains helpers to do this for basic filesystems, but any block can be only the metadata for a single inode. This is not really correct for things like inode descriptor blocks. fsblock can track multiple inodes per block. (This is non trivial, and it may be overkill so it could be reverted to a simpler scheme like buffer).

hrm; no specific comment but this seems like an idea/area that needs to be fleshed out more, by converting some of the more advanced filesystems.

Quoted 5 lines

- Large block support. I can mount and run an 8K block size minix3 fs on my 4K page system and it didn't require anything special in the fs. We can go up to about 32MB blocks now, and gigabyte+ blocks would only require one more bit in the fsblock flags. fsblock_superpage blocks are > PAGE_CACHE_SIZE, midpage ==, and subpage <.

definitely useful, especially if I rewrite my ibu filesystem for 2.6.x, like I've been planning.

Quoted 2 lines

So. Comments? Is this something we want? If yes, then how would we transition from buffer.c to fsblock.c?

Your work is definitely interesting, but I think it will be even more interesting once ext2 (w/ dir in pagecache) and ext3 (journalling) are converted.

My gut feeling is that there are several problem areas you haven't hit yet, with the new code.

Also, once things are converted, the question of transitioning from buffer.c will undoubtedly answer itself. That's the way several of us handle transitions: finish all the work, then look with fresh eyes and conceive a path from the current code to your enhanced code.

Jeff

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#21 lore raw
Quoted 13 lines · Jeff Garzik
Quoted 11 lines · Nick Piggin

- No deadlocks (hopefully). The buffer layer is technically deadlocky by design, because it can require memory allocations at page writeout-time. It also has one path that cannot tolerate memory allocation failures. No such problems for fsblock, which keeps fsblock metadata around for as long as a page is dirty (this still has problems vs get_user_pages, but that's going to require an audit of all get_user_pages sites. Phew).

- In line with the above item, filesystem block allocation is performed before a page is dirtied. In the buffer layer, mmap writes can dirty a page with no backing blocks which is a problem if the filesystem is ENOSPC (patches exist for buffer.c for this).

Quoted 4 lines

This raises an eyebrow... The handling of ENOSPC prior to mmap write is more an ABI behavior, so I don't see how this can be fixed with internal changes, yet without changing behavior currently exported to userland (and thus affecting code based on such assumptions).

I believe people are happy to have it SIGBUS (which is how the VM is already set up with page_mkwrite, and what fsblock does).

Quoted 10 lines
Quoted 7 lines

- An inode's metadata must be tracked per-inode in order for fsync to work correctly. buffer contains helpers to do this for basic filesystems, but any block can be only the metadata for a single inode. This is not really correct for things like inode descriptor blocks. fsblock can track multiple inodes per block. (This is non trivial, and it may be overkill so it could be reverted to a simpler scheme like buffer).

hrm; no specific comment but this seems like an idea/area that needs to be fleshed out more, by converting some of the more advanced filesystems.

Yep. It's conceptually fairly simple though, and it might be easier than having filesystems implement their own complex syncing that finds and syncs everything themselves.

Quoted 8 lines
Quoted 5 lines

- Large block support. I can mount and run an 8K block size minix3 fs on my 4K page system and it didn't require anything special in the fs. We can go up to about 32MB blocks now, and gigabyte+ blocks would only require one more bit in the fsblock flags. fsblock_superpage blocks are > PAGE_CACHE_SIZE, midpage ==, and subpage <.

definitely useful, especially if I rewrite my ibu filesystem for 2.6.x, like I've been planning.

Yeah, it wasn't the primary motivation for the rewrite, but it would be negligent to not even consider large blocks in such a rewrite, I think.

Quoted 6 lines
Quoted 2 lines

So. Comments? Is this something we want? If yes, then how would we transition from buffer.c to fsblock.c?

Your work is definitely interesting, but I think it will be even more interesting once ext2 (w/ dir in pagecache) and ext3 (journalling) are converted.

Well minix has dir in pagecache ;) But you're completely right: ext2 will be the next step and then ext3 and things like XFS and NTFS will be the real test. I think I could eventually get ext2 done (one of the biggest headaches is simply just converting ->b_data accesses), however unlikely a journalling one.

Quoted 2 lines

My gut feeling is that there are several problem areas you haven't hit yet, with the new code.

I would agree with your gut :)

Quoted 4 lines

Also, once things are converted, the question of transitioning from buffer.c will undoubtedly answer itself. That's the way several of us handle transitions: finish all the work, then look with fresh eyes and conceive a path from the current code to your enhanced code.

Yeah that would be nice. It's very difficult because of so much filesystem code. I'd say it would be feasible to step buffer.c into fsblock.c, however if we were to track all (or even the common) filesystems along with that it would introduce a huge number of kind-of-redundant changes that I don't think all fs maintainers would have time to write (and as I said, I can't do it myself). Anyway, let's cross that bridge if and when we come to it.

For now, the big thing that needs to be done is convert a "big" fs and see if the results tell us that it's workable.

Thanks for the comments Jeff.

#22 lore raw
Quoted 8 lines · Nick Piggin
Quoted 6 lines · Jeff Garzik
Quoted 5 lines

- Large block support. I can mount and run an 8K block size minix3 fs on my 4K page system and it didn't require anything special in the fs. We can go up to about 32MB blocks now, and gigabyte+ blocks would only require one more bit in the fsblock flags. fsblock_superpage blocks are > PAGE_CACHE_SIZE, midpage ==, and subpage <.

Quoted 6 lines
Quoted 2 lines

definitely useful, especially if I rewrite my ibu filesystem for 2.6.x, like I've been planning.

Yeah, it wasn't the primary motivation for the rewrite, but it would be negligent to not even consider large blocks in such a rewrite, I think.

I'll join the cheering here, thanks for starting on this.

Quoted 6 lines
Quoted 3 lines

My gut feeling is that there are several problem areas you haven't hit yet, with the new code.

I would agree with your gut :)

Without having read the code yet (light reading for monday morning ;), ext3 and reiserfs use buffers heads for data=ordered to help them do deadlock free writeback. Basically they need to be able to write out the pending data=ordered pages, potentially with the transaction lock held (or if not held, while blocking new transactions from starting).

But, writepage, prepare_write and commit_write all need to start a transaction with the page lock already held. So, if the page lock were used for data=ordered writeback, there would be a lock inversion between the transaction lock and the page lock.

Using buffer heads instead allows the FS to send file data down inside the transaction code, without taking the page lock. So, locking wrt data=ordered is definitely going to be tricky.

The best long term option may be making the locking order transaction -> page lock, and change writepage to punt to some other queue when it needs to start a transaction.

-chris

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#23 lore raw
Quoted 14 lines · Chris Mason
Quoted 4 lines · Nick Piggin
Quoted 1 line

My gut feeling is that there are several problem areas you haven't hit yet, with the new code.

I would agree with your gut :)

Without having read the code yet (light reading for monday morning ;), ext3 and reiserfs use buffers heads for data=ordered to help them do deadlock free writeback. Basically they need to be able to write out the pending data=ordered pages, potentially with the transaction lock held (or if not held, while blocking new transactions from starting).

Quoted 4 lines

But, writepage, prepare_write and commit_write all need to start a transaction with the page lock already held. So, if the page lock were used for data=ordered writeback, there would be a lock inversion between the transaction lock and the page lock.

Ah, thanks for that information.

Quoted 7 lines

Using buffer heads instead allows the FS to send file data down inside the transaction code, without taking the page lock. So, locking wrt data=ordered is definitely going to be tricky.

The best long term option may be making the locking order transaction -> page lock, and change writepage to punt to some other queue when it needs to start a transaction.

Yeah, that's what I would like, and I think it would come naturally if we move away from these "pass down a single, locked page APIs" in the VM, and let the filesystem do the locking and potentially batching of larger ranges.

write_begin/write_end is a step in that direction (and it helps OCFS and GFS quite a bit). I think there is also not much reason for writepage sites to require the page to lock the page and clear the dirty bit themselves (which has seems ugly to me).

So yes, I definitely want to move the aops API along with fsblock.

That I have tried to keep it within the existing API for the moment is just because that makes things a bit easier...

Signature · 1 line
SUSE Labs, Novell Inc.
#24 lore raw
Quoted 5 lines · Nick Piggin
Quoted 5 lines

Using buffer heads instead allows the FS to send file data down inside the transaction code, without taking the page lock. So, locking wrt data=ordered is definitely going to be tricky.

Quoted 8 lines
Quoted 3 lines

The best long term option may be making the locking order transaction -> page lock, and change writepage to punt to some other queue when it needs to start a transaction.

Yeah, that's what I would like, and I think it would come naturally if we move away from these "pass down a single, locked page APIs" in the VM, and let the filesystem do the locking and potentially batching of larger ranges.

Definitely.

Quoted 5 lines

write_begin/write_end is a step in that direction (and it helps OCFS and GFS quite a bit). I think there is also not much reason for writepage sites to require the page to lock the page and clear the dirty bit themselves (which has seems ugly to me).

If we keep the page mapping information with the page all the time (ie writepage doesn't have to call get_block ever), it may be possible to avoid sending down a locked page. But, I don't know the delayed allocation internals well enough to say for sure if that is true.

Either way, writepage is the easiest of the bunch because it can be deferred.

-chris

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#25 lore raw
Quoted 9 lines · Chris Mason
Quoted 4 lines

write_begin/write_end is a step in that direction (and it helps OCFS and GFS quite a bit). I think there is also not much reason for writepage sites to require the page to lock the page and clear the dirty bit themselves (which has seems ugly to me).

If we keep the page mapping information with the page all the time (ie writepage doesn't have to call get_block ever), it may be possible to avoid sending down a locked page. But, I don't know the delayed allocation internals well enough to say for sure if that is true.

The point of delayed allocations is that the mapping information doesn't even exist until writepage for new allocations :)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#26 lore raw
In reply to Jeff Garzik
Quoted 9 lines · Jeff Garzik
Quoted 4 lines

- In line with the above item, filesystem block allocation is performed before a page is dirtied. In the buffer layer, mmap writes can dirty a page with no backing blocks which is a problem if the filesystem is ENOSPC (patches exist for buffer.c for this).

This raises an eyebrow... The handling of ENOSPC prior to mmap write is more an ABI behavior, so I don't see how this can be fixed with internal changes, yet without changing behavior currently exported to userland (and thus affecting code based on such assumptions).

Not really, the current behaviour is a bug. And it's not actually buffer layer specific - XFS now has a fix for that bug and it's generic enough that everyone could use it.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#27 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Jeff Garzik
Quoted 4 lines

- In line with the above item, filesystem block allocation is performed before a page is dirtied. In the buffer layer, mmap writes can dirty a page with no backing blocks which is a problem if the filesystem is ENOSPC (patches exist for buffer.c for this).

This raises an eyebrow... The handling of ENOSPC prior to mmap write is more an ABI behavior, so I don't see how this can be fixed with internal changes, yet without changing behavior currently exported to userland (and thus affecting code based on such assumptions).

Not really, the current behaviour is a bug. And it's not actually buffer layer specific - XFS now has a fix for that bug and it's generic enough that everyone could use it.

I'm not sure I follow. If you require block allocation at mmap(2) time, rather than when a page is actually dirtied, you are denying userspace the ability to do sparse files with mmap.

A quick Google readily turns up people who have built upon the mmap-sparse-file assumption, and I don't think we want to break those assumptions as a "bug fix."

Where is the bug?

Jeff

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#28 lore raw
Quoted 8 lines · Jeff Garzik
Quoted 3 lines

Not really, the current behaviour is a bug. And it's not actually buffer layer specific - XFS now has a fix for that bug and it's generic enough that everyone could use it.

I'm not sure I follow. If you require block allocation at mmap(2) time, rather than when a page is actually dirtied, you are denying userspace the ability to do sparse files with mmap.

Quoted 5 lines

A quick Google readily turns up people who have built upon the mmap-sparse-file assumption, and I don't think we want to break those assumptions as a "bug fix."

Where is the bug?

It's not mmap time but page dirtying time. Currently the default behaviour is not to allocate at page dirtying time but rather at writeout time in some scenarious.

(and s/allocation/reservation/ applies for delalloc of course)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#29 lore raw
In reply to Nick Piggin
Quoted 4 lines · Nick Piggin

fsblock is a rewrite of the "buffer layer" (ding dong the witch is dead), which I have been working on, on and off and is now at the stage where some of the basics are working-ish. This email is going to be long...

Long overdue. Thank you.

-- wli

#30 lore raw
In reply to Nick Piggin
Quoted 4 lines · Nick Piggin

- Structure packing. A page gets a number of buffer heads that are allocated in a linked list. fsblocks are allocated contiguously, so cacheline footprint is smaller in the above situation.

It would be interesting to test if that makes a difference for database benchmarks running over file systems. Databases eat a lot of cache so in theory any cache improvements
in the kernel which often runs cache cold then should be beneficial.

But I guess it would need at least ext2 to test; Minix is probably not good enough.

In general have you benchmarked the CPU overhead of old vs new code? e.g. when we went to BIO scalability went up, but CPU costs of a single request also went up. It would be nice to not continue or better reverse that trend.

Quoted 5 lines

- Large block support. I can mount and run an 8K block size minix3 fs on my 4K page system and it didn't require anything special in the fs. We can go up to about 32MB blocks now, and gigabyte+ blocks would only require one more bit in the fsblock flags. fsblock_superpage blocks are > PAGE_CACHE_SIZE, midpage ==, and subpage <.

Can it be cleanly ifdefed or optimized away? Unless the fragmentation problem is not solved it would seem rather pointless to me. Also I personally still think the right way to approach this is larger softpage size.

-Andi

#31 lore raw
Quoted 7 lines · Andi Kleen
Quoted 3 lines · Nick Piggin

- Structure packing. A page gets a number of buffer heads that are allocated in a linked list. fsblocks are allocated contiguously, so cacheline footprint is smaller in the above situation.

Quoted 6 lines

It would be interesting to test if that makes a difference for database benchmarks running over file systems. Databases eat a lot of cache so in theory any cache improvements
in the kernel which often runs cache cold then should be beneficial.

But I guess it would need at least ext2 to test; Minix is probably not good enough.

Yeah, you are right. ext2 would be cool to port as it would be a reasonable platform for basic performance testing and comparisons.

Quoted 3 lines

In general have you benchmarked the CPU overhead of old vs new code? e.g. when we went to BIO scalability went up, but CPU costs of a single request also went up. It would be nice to not continue
or better reverse that trend.

At the moment there are still a few silly things in the code, such as always calling the insert_mapping indirect function (which is the get_block equivalent). And it does a bit more RMWing than it should still.

Also, it always goes to the pagecache radix-tree to find fsblocks, wheras the buffer layer has a per-CPU cache front-end... so in that regard, fsblock is really designed with lockless pagecache in mind, where find_get_page is much faster even in the serial case (though fsblock shouldn't exactly be slow with the current pagecache).

However, I don't think there are any fundamental performance problems with fsblock. It even uses one less layer of locking to do regular IO compared with buffer.c, so in theory it might even have some advantage.

Single threaded performance of request submission is something I will definitely try to keep optimal.

Quoted 8 lines
Quoted 5 lines

- Large block support. I can mount and run an 8K block size minix3 fs on my 4K page system and it didn't require anything special in the fs. We can go up to about 32MB blocks now, and gigabyte+ blocks would only require one more bit in the fsblock flags. fsblock_superpage blocks are > PAGE_CACHE_SIZE, midpage ==, and subpage <.

Can it be cleanly ifdefed or optimized away?

Yeah, it pretty well stays out of the way when using <= PAGE_CACHE_SIZE size blocks, generally just a single test and branch of an already-used cacheline. It can be optimised away completely by commenting out #define BLOCK_SUPERPAGE_SUPPORT from fsblock.h.

Quoted 3 lines

Unless the fragmentation
problem is not solved it would seem rather pointless to me. Also I personally still think the right way to approach this is larger softpage size.

It does not suffer from a fragmentation problem. It will do scatter gather IO if the pagecache of that block is not contiguous. My naming may be a little confusing: fsblock_superpage (which is a function that returns true if the given fsblock is larger than PAGE_CACHE_SIZE) is just named as to whether the fsblock is larger than a page, rather than having a connection to VM superpages.

Don't get me wrong, I think soft page size is a good idea for other reasons as well (less page metadata and page operations), and that 8 or 16K would probably be a good sweet spot for today's x86 systems.

Signature · 7 lines
SUSE Labs, Novell Inc.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#32 lore raw
In reply to Nick Piggin
Quoted 4 lines · Nick Piggin

I'm announcing "fsblock" now because it is quite intrusive and so I'd like to get some thoughts about significantly changing this core part of the kernel.

Can you rename it to something other than shorthand for "filesystem block"? e.g. When you say:

Quoted 1 line

- In line with the above item, filesystem block allocation is performed

What are we actually talking aout here? filesystem block allocation is something a filesystem does to allocate blocks on disk, not allocate a mapping structure in memory.

Realistically, this is not about "filesystem blocks", this is about file offset to disk blocks. i.e. it's a mapping.

Quoted 4 lines

Probably better would be to
move towards offset,length rather than page based fs APIs where everything can be batched up nicely and this sort of non-trivial locking can be more optimal.

If we are going to turn over the API completely like this, can we seriously look at moving to this sort of interface at the same time?

With a offset/len interface, we can start to track contiguous ranges of blocks rather than persisting with a structure per filesystem block. If you want to save memory, thet's where we need to go.

XFS uses "iomaps" for this purpose - it's basically:

- start offset into file
- start block on disk
- length of mapping
- state

With special "disk blocks" for indicating delayed allocation blocks (-1) and unwritten extents (-2). Worst case we end up with is an iomap per filesystem block.

If we allow iomaps to be split and combined along with range locking, we can parallelise read and write access to each file on an iomap basis, etc. There's plenty of goodness that comes from indexing by range....

FWIW, I really see little point in making all the filesystems work with fsblocks if the plan is to change the API again in a major way a year down the track. Let's get all the changes we think are necessary in one basket first, and then work out a coherent plan to implement them ;)

Quoted 5 lines

- Large block support. I can mount and run an 8K block size minix3 fs on my 4K page system and it didn't require anything special in the fs. We can go up to about 32MB blocks now, and gigabyte+ blocks would only require one more bit in the fsblock flags. fsblock_superpage blocks are > PAGE_CACHE_SIZE, midpage ==, and subpage <.

My 2c worth - this is a damn complex way of introducing large block size support. It has all the problems I pointed out that it would have (locking issues, vmap overhead, every filesystem needs needs major changes and it's not very efficient) and it's going to take quite some time to stabilise.

If this is the only real feature that fsblocks are going to give us, then I think this is a waste of time. If we are going to replace buffer heads, lets do it with something that is completely independent of filesystem block size and not introduce something that is just a bufferhead on steroids.

Cheers,

Dave.

Signature · 9 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#33 lore raw
Quoted 14 lines · David Chinner
Quoted 3 lines · Nick Piggin

I'm announcing "fsblock" now because it is quite intrusive and so I'd like to get some thoughts about significantly changing this core part of the kernel.

Can you rename it to something other than shorthand for "filesystem block"? e.g. When you say:

Quoted 1 line

- In line with the above item, filesystem block allocation is performed

Quoted 6 lines

What are we actually talking aout here? filesystem block allocation is something a filesystem does to allocate blocks on disk, not allocate a mapping structure in memory.

Realistically, this is not about "filesystem blocks", this is about file offset to disk blocks. i.e. it's a mapping.

Yeah, fsblock ~= the layer between the fs and the block layers. But don't take the name too literally, like a struct page isn't actually a page of memory ;)

Quoted 9 lines
Quoted 4 lines

Probably better would be to
move towards offset,length rather than page based fs APIs where everything can be batched up nicely and this sort of non-trivial locking can be more optimal.

If we are going to turn over the API completely like this, can we seriously look at moving to this sort of interface at the same time?

Yeah we can move to anything. But note that fsblock is perfectly happy with <= PAGE_CACHE_SIZE blocks today, and isn't _terrible_ at >.

Quoted 7 lines

With a offset/len interface, we can start to track contiguous ranges of blocks rather than persisting with a structure per filesystem block. If you want to save memory, thet's where we need to go.

XFS uses "iomaps" for this purpose - it's basically:

Quoted 8 lines

- start offset into file
- start block on disk
- length of mapping
- state

With special "disk blocks" for indicating delayed allocation blocks (-1) and unwritten extents (-2). Worst case we end up with is an iomap per filesystem block.

I was thinking about doing an extent based scheme, but it has some issues as well. Block based is light weight and simple, it aligns nicely with the pagecache structures.

Quoted 4 lines

If we allow iomaps to be split and combined along with range locking, we can parallelise read and write access to each file on an iomap basis, etc. There's plenty of goodness that comes from indexing by range....

Some operations AFAIKS will always need to be per-page (eg. in the core VM it wants to lock a single page to fault it in, or wait for a single page to writeout etc). So I didn't see a huge gain in a one-lock-per-extent type arrangement.

If you're worried about parallelisability, then I don't see what iomaps give you that buffer heads or fsblocks do not? In fact they would be worse because there are fewer of them? :)

But remember that once the filesystems have accessor APIs and can handle multiple pages per fsblock, that would already be most of the work done for the fs and the mm to go to an extent based representation.

Quoted 5 lines

FWIW, I really see little point in making all the filesystems work with fsblocks if the plan is to change the API again in a major way a year down the track. Let's get all the changes we think are necessary in one basket first, and then work out a coherent plan to implement them ;)

The aops API changes and the fsblock layer are kind of two seperate things. I'm slowly implementing things as I go (eg. see perform_write aop, which is exactly the offset,length based API that I'm talking about).

fsblocks can be implemented on the old or the new APIs. New APIs won't invalidate work to convert a filesystem to fsblocks.

Quoted 7 lines
Quoted 5 lines

- Large block support. I can mount and run an 8K block size minix3 fs on my 4K page system and it didn't require anything special in the fs. We can go up to about 32MB blocks now, and gigabyte+ blocks would only require one more bit in the fsblock flags. fsblock_superpage blocks are > PAGE_CACHE_SIZE, midpage ==, and subpage <.

Quoted 5 lines

My 2c worth - this is a damn complex way of introducing large block size support. It has all the problems I pointed out that it would have (locking issues, vmap overhead, every filesystem needs needs major changes and it's not very efficient) and it's going to take quite some time to stabilise.

What locking issues? It locks pages in pagecache offset ascending order, which already has precedent and is really the only sane way to do it so it's not like it precludes other possible sane lock orderings.

vmap overhead is an issue, however I did it mainly for easy of conversion. I guess things like superblocks and such would make use of it happily. Most other things should be able to be implemented with page based helpers (just a couple of bitops helpers would pretty much cover minix). If it is still a problem, then I can implement a proper vmap cache.

But the major changes in the filesystem are not for vmaps, but for page accessors. As I said, this allows blkdev to move out of lowmem and also closes CPU cache coherency problems. (as well as not having to carry around a vmem pointer of course).

Quoted 5 lines

If this is the only real feature that fsblocks are going to give us, then I think this is a waste of time. If we are going to replace buffer heads, lets do it with something that is completely independent of filesystem block size and not introduce something that is just a bufferhead on steroids.

Well if you ignore all my other points, then yes it is the only thing that fsblocks gives us :) But it would be very easy to overengineer this. I don't really see a good case for extents here because we have to manage these discrete pages anyway. The large block support in fsblock is probably 500 lines when you take out the debugging stuff.

And I don't see how you think an extent representation would solve the page locking, complexity, intrusiveness, or vmap problems at all? Solve them for one and it should be a good solution for the other, right?

Anyway, let's suppose that we move to a virtually mapped kernel with defragmentation support and did higher order pagecache for large block support and decided the remaining advantages of fsblock were not worth keeping around support for that. Well that could be taken out and fsblock still wouldn't be a bad thing to have IMO. fsblock is actually supposed to be a simplified and slimmed down buffer_head, rather than a steorid filled one.

Signature · 7 lines
SUSE Labs, Novell Inc.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#34 lore raw
Quoted 11 lines · Nick Piggin
Quoted 10 lines · David Chinner
Quoted 3 lines · Nick Piggin

I'm announcing "fsblock" now because it is quite intrusive and so I'd like to get some thoughts about significantly changing this core part of the kernel.

Can you rename it to something other than shorthand for "filesystem block"? e.g. When you say:

Quoted 1 line

- In line with the above item, filesystem block allocation is performed

Quoted 8 lines
Quoted 6 lines

What are we actually talking aout here? filesystem block allocation is something a filesystem does to allocate blocks on disk, not allocate a mapping structure in memory.

Realistically, this is not about "filesystem blocks", this is about file offset to disk blocks. i.e. it's a mapping.

Yeah, fsblock ~= the layer between the fs and the block layers.

Sure, but it's not a "filesystem block" which is what you are calling it. IMO, it's overloading a well known term with something different, and that's just confusing.

Can we call it a block mapping layer or something like that? e.g. struct blkmap?

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Probably better would be to
move towards offset,length rather than page based fs APIs where everything
can be batched up nicely and this sort of non-trivial locking can be more optimal.

Quoted 7 lines
Quoted 3 lines

If we are going to turn over the API completely like this, can we seriously look at moving to this sort of interface at the same time?

Yeah we can move to anything. But note that fsblock is perfectly happy with <= PAGE_CACHE_SIZE blocks today, and isn't _terrible_ at >.

Extent based block mapping is entirely independent of block size. Please don't confuse the two....

Quoted 12 lines
Quoted 12 lines

With a offset/len interface, we can start to track contiguous ranges of blocks rather than persisting with a structure per filesystem block. If you want to save memory, thet's where we need to go.

XFS uses "iomaps" for this purpose - it's basically:

- start offset into file
- start block on disk
- length of mapping
- state

Quoted 7 lines
Quoted 3 lines

With special "disk blocks" for indicating delayed allocation blocks (-1) and unwritten extents (-2). Worst case we end up with is an iomap per filesystem block.

I was thinking about doing an extent based scheme, but it has some issues as well. Block based is light weight and simple, it aligns nicely with the pagecache structures.

Yes. Block based is simple, but has flexibility and scalability problems. e.g the number of fsblocks that are required to map large files. It's not uncommon for use to have millions of bufferheads lying around after writing a single large file that only has a handful of extents. That's 5-6 orders of magnitude difference there in memory usage and as memory and disk sizes get larger, this will become more of a problem....

Quoted 9 lines
Quoted 4 lines

If we allow iomaps to be split and combined along with range locking, we can parallelise read and write access to each file on an iomap basis, etc. There's plenty of goodness that comes from indexing by range....

Some operations AFAIKS will always need to be per-page (eg. in the core VM it wants to lock a single page to fault it in, or wait for a single page to writeout etc). So I didn't see a huge gain in a one-lock-per-extent type arrangement.

For VM operations, no, but they would continue to be locked on a per-page basis. However, we can do filesystem block operations without needing to hold page locks. e.g. space reservation and allocation......

Quoted 3 lines

If you're worried about parallelisability, then I don't see what iomaps give you that buffer heads or fsblocks do not? In fact they would be worse because there are fewer of them? :)

No, that's wrong. I'm not talking about VM parallelisation, I want to be able to support multiple writers to a single file. i.e. removing the i_mutex restriction on writes. To do that you've got to have a range locking scheme integrated into the block map for the file so that concurrent lookups and allocations don't trip over each other.

iomaps can double as range locks simply because iomaps are expressions of ranges within the file. Seeing as you can only access a given range exclusively to modify it, inserting an empty mapping into the tree as a range lock gives an effective method of allowing safe parallel reads, writes and allocation into the file.

The fsblocks and the vm page cache interface cannot be used to facilitate this because a radix tree is the wrong type of tree to store this information in. A sparse, range based tree (e.g. btree) is the right way to do this and it matches very well with a range based API.

None of what I'm talking about requires any changes to the existing page cache or VM address space. I'm proposing that we should be treat the block mapping as an address space in it's own right. i.e. perhaps the struct page should not have block mapping objects attached to it at all.

By separating out the block mapping from the page cache, we make the page cache completely independent of filesystem block size, and it can just operate wholly on pages. We can implement a generic extent mapping tree instead of every filesystem having to (re)implement their own. And if the filesystem does it's job of preventing fragmentation, the amount of memory consumed by the tree will be orders of magnitude lower than any fsblock based indexing.

I also like what this implies for keeping track of sub-block dirty ranges. i.e. no need for RMW cycles for if we are doing sector sized and aligned I/O - we can keep track of sub-block dirty state in the block mapping tree easily *and* we know exactly what sector on disk it maps to. That means we don't care about filesystem block size as it no longer has any influence on RMW boundaries.

None of this is possible with fsblocks, so I really think that fsblocks are not the step forward we need. They are just bufferheads under another name and hence have all the same restrictions that bufferheads imply. We should be looking to eliminate bufferheads entirely rather than perpetuating them as fsblocks.....

Cheers,

Dave.

Signature · 9 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#35 lore raw
Quoted 10 lines · David Chinner
Quoted 5 lines · Nick Piggin
Quoted 3 lines

Realistically, this is not about "filesystem blocks", this is about file offset to disk blocks. i.e. it's a mapping.

Yeah, fsblock ~= the layer between the fs and the block layers.

Sure, but it's not a "filesystem block" which is what you are calling it. IMO, it's overloading a well known term with something different, and that's just confusing.

Well it is the metadata used to manage the filesystem block for the given bit of pagecache (even if the block is not actually allocated or even a hole, it is deemed to be so by the filesystem).

Quoted 2 lines

Can we call it a block mapping layer or something like that? e.g. struct blkmap?

I'm not fixed on fsblock, but blkmap doesn't grab me either. It is a map from the pagecache to the block layer, but blkmap sounds like it is a map from the block to somewhere.

fsblkmap ;)

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines

Probably better would be to
move towards offset,length rather than page based fs APIs where everything
can be batched up nicely and this sort of non-trivial locking can be more optimal.

If we are going to turn over the API completely like this, can we seriously look at moving to this sort of interface at the same time?

Quoted 6 lines
Quoted 3 lines

Yeah we can move to anything. But note that fsblock is perfectly happy with <= PAGE_CACHE_SIZE blocks today, and isn't _terrible_ at >.

Extent based block mapping is entirely independent of block size. Please don't confuse the two....

I'm not, but it seemed like you were confused that fsblock is tied to changing the aops APIs. It is not, but they can be changed to give improvements in a good number of areas (*including* better large block support).

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

With special "disk blocks" for indicating delayed allocation blocks (-1) and unwritten extents (-2). Worst case we end up with is an iomap per filesystem block.

I was thinking about doing an extent based scheme, but it has some issues as well. Block based is light weight and simple, it aligns nicely with the pagecache structures.

Quoted 7 lines

Yes. Block based is simple, but has flexibility and scalability problems. e.g the number of fsblocks that are required to map large files. It's not uncommon for use to have millions of bufferheads lying around after writing a single large file that only has a handful of extents. That's 5-6 orders of magnitude difference there in memory usage and as memory and disk sizes get larger, this will become more of a problem....

I guess fsblock is 3 times smaller and you would probably have 16 times fewer of them for such a filesystem (given a 4K page size) still leaves a few orders of magnitude ;)

However, fsblock has this nice feature where it can drop the blocks when the last reference goes away, so you really only have fsblocks around for dirty or currently-being-read blocks...

But you give me a good idea: I'll gear the filesystem-side APIs to be more extent based as well (eg. fsblock's get_block equivalent). That way it should be much easier to change over to such extents in future or even have an extent based representation sitting in front of the fsblock one and acting as a high density cache in your above situation.

Quoted 10 lines
Quoted 9 lines
Quoted 4 lines

If we allow iomaps to be split and combined along with range locking, we can parallelise read and write access to each file on an iomap basis, etc. There's plenty of goodness that comes from indexing by range....

Some operations AFAIKS will always need to be per-page (eg. in the core VM it wants to lock a single page to fault it in, or wait for a single page to writeout etc). So I didn't see a huge gain in a one-lock-per-extent type arrangement.

Quoted 4 lines

For VM operations, no, but they would continue to be locked on a per-page basis. However, we can do filesystem block operations without needing to hold page locks. e.g. space reservation and allocation......

You could do that without holding the page locks as well AFAIKS. Actually again it might be a bit troublesome with the current aops APIs, but I don't think fsblock stands in your way there either.

Quoted 29 lines
Quoted 3 lines

If you're worried about parallelisability, then I don't see what iomaps give you that buffer heads or fsblocks do not? In fact they would be worse because there are fewer of them? :)

No, that's wrong. I'm not talking about VM parallelisation, I want to be able to support multiple writers to a single file. i.e. removing the i_mutex restriction on writes. To do that you've got to have a range locking scheme integrated into the block map for the file so that concurrent lookups and allocations don't trip over each other.

iomaps can double as range locks simply because iomaps are expressions of ranges within the file. Seeing as you can only access a given range exclusively to modify it, inserting an empty mapping into the tree as a range lock gives an effective method of allowing safe parallel reads, writes and allocation into the file.

The fsblocks and the vm page cache interface cannot be used to facilitate this because a radix tree is the wrong type of tree to store this information in. A sparse, range based tree (e.g. btree) is the right way to do this and it matches very well with a range based API.

None of what I'm talking about requires any changes to the existing page cache or VM address space. I'm proposing that we should be treat the block mapping as an address space in it's own right. i.e. perhaps the struct page should not have block mapping objects attached to it at all.

Quoted 7 lines

By separating out the block mapping from the page cache, we make the page cache completely independent of filesystem block size, and it can just operate wholly on pages. We can implement a generic extent mapping tree instead of every filesystem having to (re)implement their own. And if the filesystem does it's job of preventing fragmentation, the amount of memory consumed by the tree will be orders of magnitude lower than any fsblock based indexing.

The independent mapping tree is something I have been thinking about, but you still need to tie the page to the block at some point and you need to track IO details and such.

The problem with implementing it in generic code is that it will add another layer of locking and data structure that may be better done in the filesystem. (because you _do_ already need to do all the per-page stuff as well). This was my thing about overengineering: fsblock is supposed to be just a very light layer.

Quoted 7 lines

I also like what this implies for keeping track of sub-block dirty ranges. i.e. no need for RMW cycles for if we are doing sector sized and aligned I/O - we can keep track of sub-block dirty state in the block mapping tree easily *and* we know exactly what sector on disk it maps to. That means we don't care about filesystem block size as it no longer has any influence on RMW boundaries.

Quoted 5 lines

None of this is possible with fsblocks, so I really think that fsblocks are not the step forward we need. They are just bufferheads under another name and hence have all the same restrictions that bufferheads imply. We should be looking to eliminate bufferheads entirely rather than perpetuating them as fsblocks.....

I don't know why you think none of that is possible with fsblocks. You could easily keep an in-memory btree or similar as the authoritative block management structure and feed the fsblock layer from that.

There is nothing about fsblock that is tied to i_mutex, and all it's locking basically comes for free on top of the page based locking that's already required in the VM.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#36 lore raw
Quoted 6 lines · Nick Piggin
Quoted 1 line · David Chinner

Can we call it a block mapping layer or something like that? e.g. struct blkmap?

I'm not fixed on fsblock, but blkmap doesn't grab me either. It is a map from the pagecache to the block layer, but blkmap sounds like it is a map from the block to somewhere.

fsblkmap ;)

vmblock? pgblock?

Cheers,
Kyle Moffett

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#37 lore raw
In reply to David Chinner
Quoted 1 line · David Chinner

On Tue, Jun 26, 2007 at 01:55:11PM +1000, Nick Piggin wrote:

[ ... fsblocks vs extent range mapping ]

Quoted 11 lines

iomaps can double as range locks simply because iomaps are expressions of ranges within the file. Seeing as you can only access a given range exclusively to modify it, inserting an empty mapping into the tree as a range lock gives an effective method of allowing safe parallel reads, writes and allocation into the file.

The fsblocks and the vm page cache interface cannot be used to facilitate this because a radix tree is the wrong type of tree to store this information in. A sparse, range based tree (e.g. btree) is the right way to do this and it matches very well with a range based API.

I'm really not against the extent based page cache idea, but I kind of assumed it would be too big a change for this kind of generic setup. At any rate, if we'd like to do it, it may be best to ditch the idea of "attach mapping information to a page", and switch to "lookup mapping information and range locking for a page".

A btree could be used to hold the range mapping and locking, but it could just as easily be a radix tree where you do a gang lookup for the end of the range (the same way my placeholder patch did). It'll still find intersecting range locks but is much faster for random insertion/deletion than the btrees.

-chris

#38 lore raw
Quoted 17 lines · Chris Mason
Quoted 1 line · David Chinner

On Tue, Jun 26, 2007 at 01:55:11PM +1000, Nick Piggin wrote:

[ ... fsblocks vs extent range mapping ]

Quoted 11 lines

iomaps can double as range locks simply because iomaps are expressions of ranges within the file. Seeing as you can only access a given range exclusively to modify it, inserting an empty mapping into the tree as a range lock gives an effective method of allowing safe parallel reads, writes and allocation into the file.

The fsblocks and the vm page cache interface cannot be used to facilitate this because a radix tree is the wrong type of tree to store this information in. A sparse, range based tree (e.g. btree) is the right way to do this and it matches very well with a range based API.

Quoted 5 lines

I'm really not against the extent based page cache idea, but I kind of assumed it would be too big a change for this kind of generic setup. At any rate, if we'd like to do it, it may be best to ditch the idea of "attach mapping information to a page", and switch to "lookup mapping information and range locking for a page".

Well the get_block equivalent API is extent based one now, and I'll look at what is required in making map_fsblock a more generic call that could be used for an extent-based scheme.

An extent based thing IMO really isn't appropriate as the main generic layer here though. If it is really useful and popular, then it could be turned into generic code and sit along side fsblock or underneath fsblock...

It definitely isn't trivial to drive the IO directly from something like that which doesn't correspond to filesystem block size. Splitting parts of your extent tree when things go dirty or uptodate or partially under IO, etc.. joining things back up again when they are mergable. Not that it would be impossible, but it would be a lot more heavyweight than fsblock.

I think using fsblock to drive the IO and keep the pagecache flags uptodate and using a btree in the filesystem to manage extents of block allocations wouldn't be a bad idea though. Do any filesystems actually do this?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#39 lore raw
Quoted 4 lines · Nick Piggin

I think using fsblock to drive the IO and keep the pagecache flags uptodate and using a btree in the filesystem to manage extents of block allocations wouldn't be a bad idea though. Do any filesystems actually do this?

Yes. XFS. But we still need to hold state in buffer heads (BH_delay, BH_unwritten) that is needed to determine what type of allocation/extent conversion is necessary during writeback. i.e. what we originally mapped the page as during the ->prepare_write call.

Cheers,

Dave.

Signature · 9 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#40 lore raw
In reply to Nick Piggin
Quoted 24 lines · Nick Piggin
Quoted 17 lines · Chris Mason
Quoted 1 line · David Chinner

On Tue, Jun 26, 2007 at 01:55:11PM +1000, Nick Piggin wrote:

[ ... fsblocks vs extent range mapping ]

Quoted 11 lines

iomaps can double as range locks simply because iomaps are expressions of ranges within the file. Seeing as you can only access a given range exclusively to modify it, inserting an empty mapping into the tree as a range lock gives an effective method of allowing safe parallel reads, writes and allocation into the file.

The fsblocks and the vm page cache interface cannot be used to facilitate this because a radix tree is the wrong type of tree to store this information in. A sparse, range based tree (e.g. btree) is the right way to do this and it matches very well with a range based API.

Quoted 5 lines

I'm really not against the extent based page cache idea, but I kind of assumed it would be too big a change for this kind of generic setup. At any rate, if we'd like to do it, it may be best to ditch the idea of "attach mapping information to a page", and switch to "lookup mapping information and range locking for a page".

Quoted 8 lines

Well the get_block equivalent API is extent based one now, and I'll look at what is required in making map_fsblock a more generic call that could be used for an extent-based scheme.

An extent based thing IMO really isn't appropriate as the main generic layer here though. If it is really useful and popular, then it could be turned into generic code and sit along side fsblock or underneath fsblock...

Lets look at a typical example of how IO actually gets done today, starting with sys_write():

sys_write(file, buffer, 1MB)
for each page:
prepare_write()
allocate contiguous chunks of disk
attach buffers
copy_from_user()
commit_write()
dirty buffers

pdflush:
writepages()
find pages with contiguous chunks of disk
build and submit large bios

So, we replace prepare_write and commit_write with an extent based api, but we keep the dirty each buffer part. writepages has to turn that back into extents (bio sized), and the result is completely full of dark dark corner cases.

I do think fsblocks is a nice cleanup on its own, but Dave has a good point that it makes sense to look for ways generalize things even more.

-chris

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#41 lore raw
Quoted 29 lines · Chris Mason
Quoted 28 lines · Nick Piggin
Quoted 17 lines · Chris Mason
Quoted 1 line · David Chinner

On Tue, Jun 26, 2007 at 01:55:11PM +1000, Nick Piggin wrote:

[ ... fsblocks vs extent range mapping ]

Quoted 11 lines

iomaps can double as range locks simply because iomaps are expressions of ranges within the file. Seeing as you can only access a given range exclusively to modify it, inserting an empty mapping into the tree as a range lock gives an effective method of allowing safe parallel reads, writes and allocation into the file.

The fsblocks and the vm page cache interface cannot be used to facilitate this because a radix tree is the wrong type of tree to store this information in. A sparse, range based tree (e.g. btree) is the right way to do this and it matches very well with a range based API.

Quoted 5 lines

I'm really not against the extent based page cache idea, but I kind of assumed it would be too big a change for this kind of generic setup. At any rate, if we'd like to do it, it may be best to ditch the idea of "attach mapping information to a page", and switch to "lookup mapping information and range locking for a page".

Well the get_block equivalent API is extent based one now, and I'll look at what is required in making map_fsblock a more generic call that could be used for an extent-based scheme.

Quoted 7 lines
Quoted 4 lines

An extent based thing IMO really isn't appropriate as the main generic layer here though. If it is really useful and popular, then it could be turned into generic code and sit along side fsblock or underneath fsblock...

Lets look at a typical example of how IO actually gets done today, starting with sys_write():

Yes, this is very inefficient which is one of the reasons I don't use the generic file write helpers in NTFS. The other reasons are that supporting larger logical block sizes than PAGE_CACHE_SIZE becomes a pain if it is not done this way when the write targets a hole as that requires all pages in the hole to be locked simultaneously which would mean dropping the page lock to acquire the others that are of lower page index and to then re-take the page lock which is horrible - much better to lock all at once from the outset and the other reason is that in NTFS there is such a thing as the initialized size of an attribute which basically states "anything past this byte offset must be returned as 0 on read, i.e. it does not have to be read from disk at all, and on write beyond the initialized_size you have to zero on disk everything between the old initialized size and the start of the write before you begin writing and certainly before you update the initalized_size otherwise a concurrent read would see random old data from the disk.

For NTFS this effectively becomes:

Quoted 1 line

sys_write(file, buffer, 1MB)

allocate space for the entire 1MB write

if write offset past the initialized_size zero out on disk starting at initialized_size up to the start offset for the write and update the initialized size to be equal to the start offset of the write

do {
if (current position is in a hole and the NTFS logical block size is

Quoted 1 line

PAGE_CACHE_SIZE) {

		work on (NTFS logical block size / PAGE_CACHE_SIZE) pages in one go;
		do_pages = vol->cluster_size / PAGE_CACHE_SIZE;
	} else {
		work on only one page;
		do_pages = 1;
	}
	fault in for read (do_pages*PAGE_CACHE_SIZE) bytes worth of source  

pages
grab do_pages worth of pages
prepare_write - attach buffers to grabbed pages copy data from source to grabbed&prepared pages commit_write the copied pages by dirtying their buffers
} while (data left to write);

The allocation in advance is a huge win both in terms of avoiding fragmentation (NTFS still uses a very simple/stupid allocator so you get a lot of fragmentation if two processes write to different files simultaneously and do so in small chunks) and in terms of performance.

I have wondered whether I should perhaps turn on the "multi page" stuff on for all writes rather than just for ones that go into a hole and the logical size is greater than the PAGE_CACHE_SIZE as that might improve performance even further but I haven't had the time/inclination to experiment...

And I have also wondered whether to go direct to bio/wholes pages at once instead of bothering with dirtying each buffer but the buffers (which are always 512 bytes on NTFS) allow me to easily support dirtying smaller parts of the page which is desired at least on volumes with a logical block size < PAGE_CACHE_SIZE as different bits of the page could then reside on completely different locations on disk so writing out unneeded bits of the page could result in a lot of wasted disk head seek times.

Best regards,

Anton

Quoted 22 lines

for each page:
prepare_write()
allocate contiguous chunks of disk
attach buffers
copy_from_user()
commit_write()
dirty buffers

pdflush:
writepages()
find pages with contiguous chunks of disk
build and submit large bios

So, we replace prepare_write and commit_write with an extent based api, but we keep the dirty each buffer part. writepages has to turn that back into extents (bio sized), and the result is completely full of dark dark corner cases.

I do think fsblocks is a nice cleanup on its own, but Dave has a good point that it makes sense to look for ways generalize things even more.

-chris

Signature · 10 lines
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer, http://www.linux-ntfs.org/


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#42 lore raw
In reply to Chris Mason
Quoted 51 lines · Chris Mason
Quoted 24 lines · Nick Piggin
Quoted 17 lines · Chris Mason
Quoted 1 line · David Chinner

On Tue, Jun 26, 2007 at 01:55:11PM +1000, Nick Piggin wrote:

[ ... fsblocks vs extent range mapping ]

Quoted 11 lines

iomaps can double as range locks simply because iomaps are expressions of ranges within the file. Seeing as you can only access a given range exclusively to modify it, inserting an empty mapping into the tree as a range lock gives an effective method of allowing safe parallel reads, writes and allocation into the file.

The fsblocks and the vm page cache interface cannot be used to facilitate this because a radix tree is the wrong type of tree to store this information in. A sparse, range based tree (e.g. btree) is the right way to do this and it matches very well with a range based API.

Quoted 5 lines

I'm really not against the extent based page cache idea, but I kind of assumed it would be too big a change for this kind of generic setup. At any rate, if we'd like to do it, it may be best to ditch the idea of "attach mapping information to a page", and switch to "lookup mapping information and range locking for a page".

Quoted 8 lines

Well the get_block equivalent API is extent based one now, and I'll look at what is required in making map_fsblock a more generic call that could be used for an extent-based scheme.

An extent based thing IMO really isn't appropriate as the main generic layer here though. If it is really useful and popular, then it could be turned into generic code and sit along side fsblock or underneath fsblock...

Lets look at a typical example of how IO actually gets done today, starting with sys_write():

sys_write(file, buffer, 1MB)
for each page:
prepare_write()
allocate contiguous chunks of disk
attach buffers
copy_from_user()
commit_write()
dirty buffers

pdflush:
writepages()
find pages with contiguous chunks of disk
build and submit large bios

Quoted 4 lines

So, we replace prepare_write and commit_write with an extent based api, but we keep the dirty each buffer part. writepages has to turn that back into extents (bio sized), and the result is completely full of dark dark corner cases.

Yup - I've been on the painful end of those dark corner cases several times in the last few months.

It's also worth pointing out that mpage_readpages() already works on an extent basis - it overloads bufferheads to provide a "map_bh" that can point to a range of blocks in the same state. The code then iterates the map_bh range a page at a time building bios (i.e. not even using buffer heads) from that map......

Quoted 2 lines

I do think fsblocks is a nice cleanup on its own, but Dave has a good point that it makes sense to look for ways generalize things even more.

*nod*

Cheers,

Dave.

Signature · 9 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#43 lore raw
Quoted 18 lines · David Chinner
Quoted 17 lines · Chris Mason

Lets look at a typical example of how IO actually gets done today, starting with sys_write():

sys_write(file, buffer, 1MB)
for each page:
prepare_write()
allocate contiguous chunks of disk
attach buffers
copy_from_user()
commit_write()
dirty buffers

pdflush:
writepages()
find pages with contiguous chunks of disk
build and submit large bios

Quoted 4 lines
Quoted 4 lines

So, we replace prepare_write and commit_write with an extent based api, but we keep the dirty each buffer part. writepages has to turn that back into extents (bio sized), and the result is completely full of dark dark corner cases.

That's true but I don't think an extent data structure means we can become too far divorced from the pagecache or the native block size -- what will end up happening is that often we'll need "stuff" to map between all those as well, even if it is only at IO-time.

But the point is taken, and I do believe that at least for APIs, extent based seems like the best way to go. And that should allow fsblock to be replaced or augmented in future without _too_ much pain.

Quoted 8 lines

Yup - I've been on the painful end of those dark corner cases several times in the last few months.

It's also worth pointing out that mpage_readpages() already works on an extent basis - it overloads bufferheads to provide a "map_bh" that can point to a range of blocks in the same state. The code then iterates the map_bh range a page at a time building bios (i.e. not even using buffer heads) from that map......

One issue I have with the current nobh and mpage stuff is that it requires multiple calls into get_block (first to prepare write, then to writepage), it doesn't allow filesystems to attach resources required for writeout at prepare_write time, and it doesn't play nicely with buffers in general. (not to mention that nobh error handling is buggy).

I haven't done any mpage-like code for fsblocks yet, but I think they wouldn't be too much trouble, and wouldn't have any of the above problems...

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#44 lore raw
Quoted 24 lines · Nick Piggin
Quoted 18 lines · David Chinner
Quoted 17 lines · Chris Mason

Lets look at a typical example of how IO actually gets done today, starting with sys_write():

sys_write(file, buffer, 1MB)
for each page:
prepare_write()
allocate contiguous chunks of disk
attach buffers
copy_from_user()
commit_write()
dirty buffers

pdflush:
writepages()
find pages with contiguous chunks of disk
build and submit large bios

Quoted 4 lines
Quoted 4 lines

So, we replace prepare_write and commit_write with an extent based api, but we keep the dirty each buffer part. writepages has to turn that back into extents (bio sized), and the result is completely full of dark dark corner cases.

Quoted 4 lines

That's true but I don't think an extent data structure means we can become too far divorced from the pagecache or the native block size -- what will end up happening is that often we'll need "stuff" to map between all those as well, even if it is only at IO-time.

I think the fundamental difference is that fsblock still does:
mapping_info = page->something, where something is attached on a per page basis. What we really want is mapping_info = lookup_mapping(page), where that function goes and finds something stored on a per extent basis, with extra bits for tracking dirty and locked state.

Ideally, in at least some of the cases the dirty and locked state could be at an extent granularity (streaming IO) instead of the block granularity (random IO).

In my little brain, even block based filesystems should be able to take advantage of this...but such things are always easier to believe in before the coding starts.

Quoted 22 lines

But the point is taken, and I do believe that at least for APIs, extent based seems like the best way to go. And that should allow fsblock to be replaced or augmented in future without _too_ much pain.

Quoted 8 lines

Yup - I've been on the painful end of those dark corner cases several times in the last few months.

It's also worth pointing out that mpage_readpages() already works on an extent basis - it overloads bufferheads to provide a "map_bh" that can point to a range of blocks in the same state. The code then iterates the map_bh range a page at a time building bios (i.e. not even using buffer heads) from that map......

One issue I have with the current nobh and mpage stuff is that it requires multiple calls into get_block (first to prepare write, then to writepage), it doesn't allow filesystems to attach resources required for writeout at prepare_write time, and it doesn't play nicely with buffers in general. (not to mention that nobh error handling is buggy).

Quoted 3 lines

I haven't done any mpage-like code for fsblocks yet, but I think they wouldn't be too much trouble, and wouldn't have any of the above problems...

Could be, but the fundamental issue of sometimes pages have mappings attached and sometimes they don't is still there. The window is smaller, but non-zero.

-chris

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#45 lore raw
Quoted 9 lines · Chris Mason
Quoted 4 lines · Nick Piggin

That's true but I don't think an extent data structure means we can become too far divorced from the pagecache or the native block size -- what will end up happening is that often we'll need "stuff" to map between all those as well, even if it is only at IO-time.

I think the fundamental difference is that fsblock still does:
mapping_info = page->something, where something is attached on a per page basis. What we really want is mapping_info = lookup_mapping(page),

lookup_block_mapping(page).... ;)

But yes, that is the essence of what I was saying. Thanks for describing it so concisely, Chris.

Cheers,

Dave.

Signature · 9 lines
Dave Chinner
Principal Engineer
SGI Australian Software Group

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#46 lore raw
In reply to Chris Mason
Quoted 13 lines · Chris Mason
Quoted 5 lines · Nick Piggin

That's true but I don't think an extent data structure means we can become too far divorced from the pagecache or the native block size -- what will end up happening is that often we'll need "stuff" to map between all those as well, even if it is only at IO-time.

I think the fundamental difference is that fsblock still does:
mapping_info = page->something, where something is attached on a per page basis. What we really want is mapping_info = lookup_mapping(page), where that function goes and finds something stored on a per extent basis, with extra bits for tracking dirty and locked state.

Quoted 7 lines

Ideally, in at least some of the cases the dirty and locked state could be at an extent granularity (streaming IO) instead of the block granularity (random IO).

In my little brain, even block based filesystems should be able to take advantage of this...but such things are always easier to believe in before the coding starts.

Now I wouldn't for a minute deny that at least some of the block information would be well to store in extent/tree format (if XFS does it it must be good!).

And yes, I'm sure filesystems with even basic block based allocation could get a reasonable ratio of blocks to extents.

However I think it is fundamentally another layer or at least more complexity... fsblocks uses the existing pagecache mapping as (much of) the data structure and uses the existing pagecache locking for the locking. And it fundamentally just provides a block access and IO layer into the pagecache for the filesystem, which I think will often be needed anyway.

But that said, I would like to see a generic extent mapping layer sitting between fsblock and the filesystem (I might even have a crack at it myself)... and I could be proven completely wrong and it may be that fsblock isn't required at all after such a layer goes in. So I will try to keep all the APIs extent based.

The first thing I actually looked at for "get_blocks" was for the filesystem to build up a tree of mappings itself, completely unconnected from the pagecache. It just ended up being a little more work and locking but the idea isn't insane :)

Quoted 7 lines
Quoted 7 lines

One issue I have with the current nobh and mpage stuff is that it requires multiple calls into get_block (first to prepare write, then to writepage), it doesn't allow filesystems to attach resources required for writeout at prepare_write time, and it doesn't play nicely with buffers in general. (not to mention that nobh error handling is buggy).

Quoted 7 lines
Quoted 3 lines

I haven't done any mpage-like code for fsblocks yet, but I think they wouldn't be too much trouble, and wouldn't have any of the above problems...

Could be, but the fundamental issue of sometimes pages have mappings attached and sometimes they don't is still there. The window is smaller, but non-zero.

The aim for fsblocks is that any page under IO will always have fsblocks, which I hope is going to make this easy. In the fsblocks patch I sent out there is a window (with mmapped pages), however that's a bug wich can be fixed rather than a fundamental problem. So writepages will be less problem.

Readpages may indeed be more efficient and block mapping with extents than individual fsblocks (or it could be, if it were an extent based API itself).

Well I don't know. Extents are always going to have benefits, but I don't know if it means the fsblock part could go away completely. I'll keep it in mind though.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#47 lore raw
In reply to Nick Piggin

Warning ahead: I've only briefly skipped over the pages so the comments in the mail are very highlevel.

Quoted 15 lines · Nick Piggin

fsblock is a rewrite of the "buffer layer" (ding dong the witch is dead), which I have been working on, on and off and is now at the stage where some of the basics are working-ish. This email is going to be long...

Firstly, what is the buffer layer? The buffer layer isn't really a buffer layer as in the buffer cache of unix: the block device cache is unified with the pagecache (in terms of the pagecache, a blkdev file is just like any other, but with a 1:1 mapping between offset and block).

There are filesystem APIs to access the block device, but these go through the block device pagecache as well. These don't exactly define the buffer layer either.

Quoted 6 lines

The buffer layer is a layer between the pagecache and the block device for block based filesystems. It keeps a translation between logical offset and physical block number, as well as meta information such as locks, dirtyness, and IO status of each block. This information is tracked via the buffer_head structure.

Traditional unix buffer cache is always physical block indexed and used for all data/metadata/blockdevice node access. There's been a lot of variants of schemes where data or some data is in a separate inode,logial block indexed scheme. Most modern OSes including Linux now always do the inode,logial block index with some noop substitute for the metadata and block device node variants of operation.

Now what you replace is a really crappy hybrid of a traditional unix buffercache implemented ontop of the pagecache for the block device node (for metadata) and a lot of abuse of the same data structure as used in the buffercache for keeping metainformation about the actual data mapping.

Quoted 6 lines

Why rewrite the buffer layer? Lots of people have had a desire to completely rip out the buffer layer, but we can't do that[*] because it does actually serve a useful purpose. Why the bad rap? Because the code is old and crufty, and buffer_head is an awful name. It must be among the oldest code in the core fs/vm, and the main reason is because of the inertia of so many and such complex filesystems.

Actually most of the code is no older than 10 years. Just compare fs/buffer.c in 2.2 and 2.6. buffer_head is a perfectly fine name for one of it's uses in the traditional buffercache.

I also thing there is little to no reason to get rid of that use:
This buffercache is what most linux block-based filesystems (except xfs and jfs most notably) are written to, and it fits them very nicely.

What I'd really like to see is to get rid of the abuse of struct buffer_head in the data path, and the sometimes to intimate coupling of the buffer cache with page cache internals.

Quoted 6 lines

- Data / metadata separation. I have a struct fsblock and a struct fsblock_meta, so we could put more stuff into the usually less used fsblock_meta without bloating it up too much. After a few tricks, these are no longer any different in my code, and dirty up the typing quite a lot (and I'm aware it still has some warnings, thanks). So if not useful this could be taken out.

That's what I mean. And from a quick glimpse at your code they're still far too deeply coupled in fsblock. Really, we don't really want to share anything between the buffer cache and data mapping operations - they are so deeply different that this sharing is what creates the enormous complexity we have to deal with.

Quoted 6 lines

- No deadlocks (hopefully). The buffer layer is technically deadlocky by design, because it can require memory allocations at page writeout-time. It also has one path that cannot tolerate memory allocation failures. No such problems for fsblock, which keeps fsblock metadata around for as long as a page is dirty (this still has problems vs get_user_pages, but that's going to require an audit of all get_user_pages sites. Phew).

The whole concept of delayed allocation requires page allocations at writeout time, as do various network protocols or even storage drivers.

Quoted 4 lines

- In line with the above item, filesystem block allocation is performed before a page is dirtied. In the buffer layer, mmap writes can dirty a page with no backing blocks which is a problem if the filesystem is ENOSPC (patches exist for buffer.c for this).

Not really something that is the block layers fault but rather the lazyness of the filesystem maintainers.

Quoted 6 lines

- Large block support. I can mount and run an 8K block size minix3 fs on my 4K page system and it didn't require anything special in the fs. We can go up to about 32MB blocks now, and gigabyte+ blocks would only require one more bit in the fsblock flags. fsblock_superpage blocks are > PAGE_CACHE_SIZE, midpage ==, and subpage <.

Quoted 9 lines

Core pagecache code is pretty creaky with respect to this. I think it is mostly race free, but it requires stupid unlocking and relocking hacks because the vm usually passes single locked pages to the fs layers, and we need to lock all pages of a block in offset ascending order. This could be avoided by doing locking on only the first page of a block for locking in the fsblock layer, but that's a bit scary too. Probably better would be to move towards offset,length rather than page based fs APIs where everything can be batched up nicely and this sort of non-trivial locking can be more optimal.

See now why people like large order page cache so much :)

Quoted 9 lines

Large block memory access via filesystem uses vmap, but it will go back to kmap if the access doesn't cross a page. Filesystems really should do this because vmap is slow as anything. I've implemented a vmap cache which basically wouldn't work on 32-bit systems (because of limited vmap space) for performance testing (and yes it sometimes tries to unmap in interrupt context, I know, I'm using loop). We could possibly do a self limiting cache, but I'd rather build some helpers to hide the raw multi page access for things like bitmap scanning and bit setting etc. and avoid too much vmaps.

And this is a complete pain in the ass. XFS uses vmap in it's metadata buffer cache due to requirements carrier over from IRIX (in fact that's why I implemented vmap in it's current form). This works okay most of them time, but there are a lot of scenarios where you run out of vmalloc space as you mention. What's also nasy is that you can't call vunmap from irq context, and vunmap beeing rather bad for system peformance due to the tlb flushing overhead.

So as the closing comment I'd say I'd rather keep buffer_heads for metadata for now and try to decouple the data path from it. Your fsblock patches are a very nice start for this, but I'd rather skip the intermediate step towards the extent based API Dave has been outlining. Having deal with the I/O path of a high performance filesystem for a while per-page or sub-page structures are a real pain to deal with and I'd really prefer to have data structures for as much as possible blocks with the same state.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#48 lore raw
In reply to Nick Piggin
Quoted 5 lines · Nick Piggin

Firstly, what is the buffer layer? The buffer layer isn't really a buffer layer as in the buffer cache of unix: the block device cache is unified with the pagecache (in terms of the pagecache, a blkdev file is just like any other, but with a 1:1 mapping between offset and block).

I thought that the buffer layer is essentially a method to index to sub section of a page?

Quoted 6 lines

Why rewrite the buffer layer? Lots of people have had a desire to completely rip out the buffer layer, but we can't do that[*] because it does actually serve a useful purpose. Why the bad rap? Because the code is old and crufty, and buffer_head is an awful name. It must be among the oldest code in the core fs/vm, and the main reason is because of the inertia of so many and such complex filesystems.

Hmmm.... I did not notice that yet but then I have not done much work there.

Quoted 5 lines

- data structure size. struct fsblock is 20 bytes on 32-bit, and 40 on 64-bit (could easily be 32 if we can have int bitops). Compare this to around 50 and 100ish for struct buffer_head. With a 4K page and 1K blocks, IO requires 10% RAM overhead in buffer heads alone. With fsblocks you're down to around 3%.

I thought we were going to simply use the page struct instead of having buffer heads? Would that not reduce the overhead to zero?

Quoted 3 lines

- Structure packing. A page gets a number of buffer heads that are allocated in a linked list. fsblocks are allocated contiguously, so cacheline footprint is smaller in the above situation.

Good idea.

Quoted 7 lines

- A real "nobh" mode. nobh was created I think mainly to avoid problems with buffer_head memory consumption, especially on lowmem machines. It is basically a hack (sorry), which requires special code in filesystems, and duplication of quite a bit of tricky buffer layer code (and bugs). It also doesn't work so well for buffers with non-trivial private data (like most journalling ones). fsblock implements this with basically a few lines of code, and it shold work in situations like ext3.

Hmmm.... That means simply page struct are not working...

Quoted 16 lines

- Large block support. I can mount and run an 8K block size minix3 fs on my 4K page system and it didn't require anything special in the fs. We can go up to about 32MB blocks now, and gigabyte+ blocks would only require one more bit in the fsblock flags. fsblock_superpage blocks are > PAGE_CACHE_SIZE, midpage ==, and subpage <.

Core pagecache code is pretty creaky with respect to this. I think it is mostly race free, but it requires stupid unlocking and relocking hacks because the vm usually passes single locked pages to the fs layers, and we need to lock all pages of a block in offset ascending order. This could be avoided by doing locking on only the first page of a block for locking in the fsblock layer, but that's a bit scary too. Probably better would be to move towards offset,length rather than page based fs APIs where everything can be batched up nicely and this sort of non-trivial locking can be more optimal.

Quoted 4 lines

Large blocks also have a performance black spot where an 8K sized and aligned write(2) would require an RMW in the filesystem. Again because of the page based nature of the fs API, and this too would be fixed if the APIs were better.

The simple solution would be to use a compound page and make the head page represent the status of all the pages in the vm. Logic for that is already in place.

Quoted 9 lines

Large block memory access via filesystem uses vmap, but it will go back to kmap if the access doesn't cross a page. Filesystems really should do this because vmap is slow as anything. I've implemented a vmap cache which basically wouldn't work on 32-bit systems (because of limited vmap space) for performance testing (and yes it sometimes tries to unmap in interrupt context, I know, I'm using loop). We could possibly do a self limiting cache, but I'd rather build some helpers to hide the raw multi page access for things like bitmap scanning and bit setting etc. and avoid too much vmaps.

Argh. No. Too much overhead.

Quoted 2 lines

So. Comments? Is this something we want? If yes, then how would we transition from buffer.c to fsblock.c?

I think many of the ideas are great but the handling of large pages is rather strange. I would suggest to use compound pages to represent larger pages and rely on Mel Gorman's antifrag/compaction work to get you the contiguous memory locations instead of using vmap. This may significantly simplify your patchset and avoid changes to the filesytesm API. Its still pretty invasive though and I am not sure that there is enough benefit from this one.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#49 lore raw
Quoted 10 lines · Christoph Lameter
Quoted 5 lines · Nick Piggin

Firstly, what is the buffer layer? The buffer layer isn't really a buffer layer as in the buffer cache of unix: the block device cache is unified with the pagecache (in terms of the pagecache, a blkdev file is just like any other, but with a 1:1 mapping between offset and block).

I thought that the buffer layer is essentially a method to index to sub section of a page?

It converts pagecache addresses to block addresses I guess. The current implementation cannot handle blocks larger than pages, but not because use of larger pages for pagecache wsa anticipated (likely because it is more work, and the APIs aren't really set up for it).

Quoted 9 lines
Quoted 6 lines

Why rewrite the buffer layer? Lots of people have had a desire to completely rip out the buffer layer, but we can't do that[*] because it does actually serve a useful purpose. Why the bad rap? Because the code is old and crufty, and buffer_head is an awful name. It must be among the oldest code in the core fs/vm, and the main reason is because of the inertia of so many and such complex filesystems.

Hmmm.... I did not notice that yet but then I have not done much work there.

Notice what?

Quoted 8 lines
Quoted 5 lines

- data structure size. struct fsblock is 20 bytes on 32-bit, and 40 on 64-bit (could easily be 32 if we can have int bitops). Compare this to around 50 and 100ish for struct buffer_head. With a 4K page and 1K blocks, IO requires 10% RAM overhead in buffer heads alone. With fsblocks you're down to around 3%.

I thought we were going to simply use the page struct instead of having buffer heads? Would that not reduce the overhead to zero?

What do you mean by that? As I said, you couldn't use just the page struct for anything except page sized blocks, and even then it would require more fields or at least more flags in the page struct.

nobh mode actually tries to do something similar, however it requires multiple calls into the filesystem to first allocate the block, and then find its sector. It is also buggy and can't handle errors properly (although I'm trying to fix that).

Quoted 9 lines
Quoted 7 lines

- A real "nobh" mode. nobh was created I think mainly to avoid problems with buffer_head memory consumption, especially on lowmem machines. It is basically a hack (sorry), which requires special code in filesystems, and duplication of quite a bit of tricky buffer layer code (and bugs). It also doesn't work so well for buffers with non-trivial private data (like most journalling ones). fsblock implements this with basically a few lines of code, and it shold work in situations like ext3.

Hmmm.... That means simply page struct are not working...

I don't understand you. jbd needs to attach private data to each bh, and that can stay around for longer than the life of the page in the pagecache.

Quoted 16 lines
Quoted 16 lines

- Large block support. I can mount and run an 8K block size minix3 fs on my 4K page system and it didn't require anything special in the fs. We can go up to about 32MB blocks now, and gigabyte+ blocks would only require one more bit in the fsblock flags. fsblock_superpage blocks are > PAGE_CACHE_SIZE, midpage ==, and subpage <.

Core pagecache code is pretty creaky with respect to this. I think it is mostly race free, but it requires stupid unlocking and relocking hacks because the vm usually passes single locked pages to the fs layers, and we need to lock all pages of a block in offset ascending order. This could be avoided by doing locking on only the first page of a block for locking in the fsblock layer, but that's a bit scary too. Probably better would be to move towards offset,length rather than page based fs APIs where everything can be batched up nicely and this sort of non-trivial locking can be more optimal.

Quoted 8 lines
Quoted 4 lines

Large blocks also have a performance black spot where an 8K sized and aligned write(2) would require an RMW in the filesystem. Again because of the page based nature of the fs API, and this too would be fixed if the APIs were better.

The simple solution would be to use a compound page and make the head page represent the status of all the pages in the vm. Logic for that is already in place.

I do not consider that a solution because I explicitly want to allow order-0 pages here. I know about your higher order pagecache, the anti-frag and defrag work, I know about compound pages. I'm not just ignoring them because of NIH or something silly.

Anyway, I have thought about just using the first page in the block for the locking, and that might be a reasonable optimisation. However for now I'm keeping it simple.

Quoted 11 lines
Quoted 9 lines

Large block memory access via filesystem uses vmap, but it will go back to kmap if the access doesn't cross a page. Filesystems really should do this because vmap is slow as anything. I've implemented a vmap cache which basically wouldn't work on 32-bit systems (because of limited vmap space) for performance testing (and yes it sometimes tries to unmap in interrupt context, I know, I'm using loop). We could possibly do a self limiting cache, but I'd rather build some helpers to hide the raw multi page access for things like bitmap scanning and bit setting etc. and avoid too much vmaps.

Argh. No. Too much overhead.

Really? In my measurements I was able to do various things to cut the vmap overhead until it was insignificant. I haven't done any intensive IO benchmarking yet because of a few other suboptimal bits in fsblock (and no good filesystem, although ext2 is on its way so that should change soon).

Quoted 10 lines
Quoted 2 lines

So. Comments? Is this something we want? If yes, then how would we transition from buffer.c to fsblock.c?

I think many of the ideas are great but the handling of large pages is rather strange. I would suggest to use compound pages to represent larger pages and rely on Mel Gorman's antifrag/compaction work to get you the contiguous memory locations instead of using vmap. This may significantly simplify your patchset and avoid changes to the filesytesm API. Its still pretty invasive though and I am not sure that there is enough benefit from this one.

There are no changes to the filesystem API for large pages (although I am adding a couple of helpers to do page based bitmap ops). And I don't want to rely on contiguous memory. Why do you think handling of large pages (presumably you mean larger than page sized blocks) is strange? Conglomerating the constituent pages via the pagecache radix-tree seems logical to me.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#50 lore raw
Quoted 4 lines · Nick Piggin
Quoted 2 lines

Hmmm.... I did not notice that yet but then I have not done much work there.

Notice what?

The bad code for the buffer heads.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

- A real "nobh" mode. nobh was created I think mainly to avoid problems with buffer_head memory consumption, especially on lowmem machines. It is basically a hack (sorry), which requires special code in filesystems, and duplication of quite a bit of tricky buffer layer code (and bugs). It also doesn't work so well for buffers with non-trivial private data (like most journalling ones). fsblock implements this with basically a few lines of code, and it shold work in situations like ext3.

Quoted 4 lines
Quoted 1 line

Hmmm.... That means simply page struct are not working...

I don't understand you. jbd needs to attach private data to each bh, and that can stay around for longer than the life of the page in the pagecache.

Right. So just using page struct alone wont work for the filesystems.

Quoted 4 lines

There are no changes to the filesystem API for large pages (although I am adding a couple of helpers to do page based bitmap ops). And I don't want to rely on contiguous memory. Why do you think handling of large pages (presumably you mean larger than page sized blocks) is strange?

We already have a way to handle large pages: Compound pages.

Quoted 2 lines

Conglomerating the constituent pages via the pagecache radix-tree seems logical to me.

Meaning overhead to handle each page still exists? This scheme cannot handle large contiguous blocks as a single entity?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#51 lore raw
Quoted 8 lines · Christoph Lameter
Quoted 4 lines · Nick Piggin
Quoted 2 lines

Hmmm.... I did not notice that yet but then I have not done much work there.

Notice what?

The bad code for the buffer heads.

Oh. Well my first mail in this thrad listed some of the problems with them.

Quoted 13 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

- A real "nobh" mode. nobh was created I think mainly to avoid problems with buffer_head memory consumption, especially on lowmem machines. It is basically a hack (sorry), which requires special code in filesystems, and duplication of quite a bit of tricky buffer layer code (and bugs). It also doesn't work so well for buffers with non-trivial private data (like most journalling ones). fsblock implements this with basically a few lines of code, and it shold work in situations like ext3.

Quoted 4 lines
Quoted 1 line

Hmmm.... That means simply page struct are not working...

I don't understand you. jbd needs to attach private data to each bh, and that can stay around for longer than the life of the page in the pagecache.

Quoted 8 lines

Right. So just using page struct alone wont work for the filesystems.

Quoted 4 lines

There are no changes to the filesystem API for large pages (although I am adding a couple of helpers to do page based bitmap ops). And I don't want to rely on contiguous memory. Why do you think handling of large pages (presumably you mean larger than page sized blocks) is strange?

We already have a way to handle large pages: Compound pages.

Yes but I don't want to use large pages and I am not going to use them (at least, they won't be mandatory).

Quoted 5 lines
Quoted 2 lines

Conglomerating the constituent pages via the pagecache radix-tree seems logical to me.

Meaning overhead to handle each page still exists? This scheme cannot handle large contiguous blocks as a single entity?

Of course some things have to be done per-page if the pages are not contiguous. I actually haven't seen that to be a problem or have much reason to think it will suddenly become a problem (although I do like Andrea's config page sizes approach for really big systems that cannot change their HW page size).

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#52 lore raw
In reply to Christoph Lameter
Quoted 7 lines · Christoph Lameter
Quoted 4 lines · Nick Piggin

There are no changes to the filesystem API for large pages (although I am adding a couple of helpers to do page based bitmap ops). And I don't want to rely on contiguous memory. Why do you think handling of large pages (presumably you mean larger than page sized blocks) is strange?

We already have a way to handle large pages: Compound pages.

Um, no, we don't, assuming by compound pages you mean order > 0 pages.. None of the stack of changes necessary to make these pages viable has yet been accepted, ie antifrag, defrag, and variable page cache. While these changes may yet all go in and work wonderfully, I applaud Nick's alternative solution that does not include a depency on them.

Dave McCracken

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>