Skip to contentSkip to conversation

buffer head read/write

DISCUSSION David Chow 4 participants 7 messages Dec 9, 2002 – Dec 11, 2002 VFS

lore
Share & tools
lore

David Chow

author
#0 lore raw

Hi all,

Is there a way to make sure I submit a buffer head read/write and make sure it is commited immediately? (sychronized) . Please give direction on examples in the kernel code? Thanks.

regards,
David Chow

#1 lore raw
Quoted 6 lines

Is there a way to make sure I submit a buffer head read/write and make sure it is commited immediately? (sychronized)

ll_rw_block() to submit it, followed by wait_on_buffer() to wait for the I/O to complete.

Quoted 1 line

Please give direction on examples in the kernel code? Thanks.

I can't think of an example of where those are called together, but if you search the fs/ directory for those, you should find plenty of examples of using them individually.

#2 lore raw
In reply to David Chow
Quoted 5 lines · On Tuesday December 10, [email protected] wrote:

Hi all,

Is there a way to make sure I submit a buffer head read/write and make sure it is commited immediately? (sychronized) . Please give direction on examples in the kernel code? Thanks.

md does (or will) read/write it's super-blocks that way. In 2.5, see drivers/md/md.c:sync_page_io
In 2.4, see

    http://cgi.cse.unsw.edu.au/~neilb/patches/linux-stable/2.4.leading/2002-12-09:01/005MDSyncIo

... I haven't submitted it yet.

NeilBrown

author
#3 lore raw
Quoted 9 lines · Neil Brown
Quoted 5 lines · On Tuesday December 10, [email protected] wrote:

Hi all,

Is there a way to make sure I submit a buffer head read/write and make sure it is commited immediately? (sychronized) . Please give direction on examples in the kernel code? Thanks.

Quoted 10 lines

md does (or will) read/write it's super-blocks that way. In 2.5, see drivers/md/md.c:sync_page_io
In 2.4, see
http://cgi.cse.unsw.edu.au/~neilb/patches/linux-stable/2.4.leading/2002-12-09:01/005MDSyncIo

... I haven't submitted it yet.

NeilBrown

Thanks to all who give suggestions. I know how to make a call to general_make_request() but wait for the buffer to complete which is too slow. If I am doing a continuous sychronous read/write (which I already have my own way of buffer management), can I put those "dirty buffers"/"non-up-to-date buffers" in the head of the buffer queue so that they get written by their respective handler immediately? I am not familiar with buffer cache so would like to seek advice on doing this. Is there anyway to lock a buffer and get its buffer_head request handler and call end_io() immediately? Thanks for advice.

regards,
David Chow

#4 lore raw
Quoted 7 lines

I know how to make a call to general_make_request() but wait for the buffer to complete which is too slow.
If I am doing a continuous sychronous read/write ..., can I put those

"dirty

Quoted 2 lines

buffers"/"non-up-to-date buffers" in the head of the buffer queue so that they get written by their respective handler immediately?

"immediately" in computer systems normally means "while I wait" rather than "before doing anything else." That's why you got a bunch of answers that weren't what you were looking for.

What you want is a way to assign priority to a block I/O request, so that a particular one gets executed first regardless of other factors, like that it's a mile away from where the head is now or 100 other requests came in before it. There's no way to do priority in today's block I/O layer.

Incidentally, this has nothing to do with the buffer cache. The queue in question is for all I/O to a block device; it is below the buffer cache.

author
#5 lore raw

OK, I think you know what I want, and you've just told me this is
impossible, then the best I could do is try to execute the task as best as the CPU can. This is stolen from Neils md super block writing routing that he just gave me a few days ago and merged with wait_for_complettion. Does this code make sense?

static int sync_buffer_io(kdev_t dev, unsigned long sector, int size,

			struct page *page, int rw)


	struct buffer_head bh;
	struct completion event;

	init_completion(&event);
	init_buffer(&bh, bh_complete, &event);
	bh.b_rdev = dev;
	bh.b_rsector = sector;
	bh.b_state	= (1 << BH_Req) | (1 << BH_Mapped);
	bh.b_size = size;
	bh.b_page = page;
	bh.b_reqnext = NULL;
	bh.b_data = page_address(page);
	generic_make_request(rw, &bh);

	run_task_queue(&tq_disk);

	spin_lock_irq(even.wait.lock);

	if (!event.done) {
		DECLARE_WAITQUEUE(wait, current);

		wait.flags |= WQ_FLAG_EXCLUSIVE;
		__add_wait_queue_tail(event.wait, &wait);
		do {
			__set_current_state(TASK_UNINTERRUPTIBLE);
			spin_unlock_irq(event.wait.lock);
			run_task_queue(&tq_disk);
			spin_lock_irq(event.wait.lock);
		} while (!x->done);
		__remove_wait_queue(event.wait, &wait);
	}
	event.done--;
	spin_unlock_irq(&x->wait.lock);

	return test_bit(BH_Uptodate, &bh.b_state);
}

This is dedicate to run the task of tq_disk instead of just schedule() which doesn't know which task is going to run. Please comment. Thanks.

regards,
David

Quoted 31 lines · Bryan Henderson
Quoted 9 lines

I know how to make a call to general_make_request() but wait for the buffer to complete which is too slow.
If I am doing a continuous sychronous read/write ..., can I put those

"dirty

Quoted 4 lines

buffers"/"non-up-to-date buffers" in the head of the buffer queue so that they get written by their respective handler immediately?

"immediately" in computer systems normally means "while I wait" rather than "before doing anything else." That's why you got a bunch of answers that weren't what you were looking for.

What you want is a way to assign priority to a block I/O request, so that a particular one gets executed first regardless of other factors, like that it's a mile away from where the head is now or 100 other requests came in before it. There's no way to do priority in today's block I/O layer.

Incidentally, this has nothing to do with the buffer cache. The queue in question is for all I/O to a block device; it is below the buffer cache.

Signature · 5 lines
-----------------------------------------------------------------------------
David Chow	 | Managing Director
http://www.shaolinmicro.com
ShaoLin Microsystems - Multiply Efficiency
-----------------------------------------------------------------------------
#6 lore raw
In reply to David Chow
Quoted 6 lines · David Chow

Hi all,

Is there a way to make sure I submit a buffer head read/write and make sure it is commited immediately? (sychronized) . Please give direction on examples in the kernel code? Thanks.

grep wait_on_buffer fs/ext2/*.c - you'll see lots of examples. eg:

        mark_buffer_dirty(bh);
        if (sb->s_flags & MS_SYNCHRONOUS) {
                ll_rw_block (WRITE, 1, &bh);
                wait_on_buffer (bh);
        }