* Buffer head async write
@ 2006-08-30 16:35 Gorka Guardiola
2006-08-30 23:59 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Gorka Guardiola @ 2006-08-30 16:35 UTC (permalink / raw)
To: linux-kernel
I am trying to mark a buffer for async write, but I am having a race condition
to unlock the buffer. I am doing.
bh = getbmapst(bdev, nsect); //this function calls bread
if (!bh) {
printk(KERN_ALERT "I/O error, bitmap cannot be trusted\n");
return -1;
}
lock_buffer(bh);
byte = bh->b_data + byteoffset;
*byte |= 1 << bitoffset;
lock_page(bh->b_page);
mark_page_accessed(bh->b_page);
__set_page_dirty_nobuffers(bh->b_page);
unlock_page(bh->b_page);
set_buffer_uptodate(bh);
mark_buffer_dirty(bh);
mark_buffer_async_write(bh);
unlock_buffer(bh);
brelse(bh);
What I want is the buffer head not to write synchronously when I do
the brelse, to
coalesce writes on it. It works normally, but this code has some form
of race condition.
The problem is that (in some circumstances, for example while using a
loop device against a file) this makes the fs/buffer.c:603
BUG_ON break. I am using the latest version of the kernel with SMP on a machine
with 4 processors.
Can anybody tell me what am I doing wrong?. I tried some other schemes, like
bit_spin_locking the BH_Uptodate_Lock, but it didn't work either.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Buffer head async write
2006-08-30 16:35 Buffer head async write Gorka Guardiola
@ 2006-08-30 23:59 ` Andrew Morton
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2006-08-30 23:59 UTC (permalink / raw)
To: Gorka Guardiola; +Cc: linux-kernel
On Wed, 30 Aug 2006 11:35:44 -0500
"Gorka Guardiola" <paurealkml@gmail.com> wrote:
> I am trying to mark a buffer for async write, but I am having a race condition
> to unlock the buffer. I am doing.
>
> bh = getbmapst(bdev, nsect); //this function calls bread
> if (!bh) {
> printk(KERN_ALERT "I/O error, bitmap cannot be trusted\n");
> return -1;
> }
>
> lock_buffer(bh);
>
> byte = bh->b_data + byteoffset;
> *byte |= 1 << bitoffset;
> lock_page(bh->b_page);
> mark_page_accessed(bh->b_page);
> __set_page_dirty_nobuffers(bh->b_page);
> unlock_page(bh->b_page);
> set_buffer_uptodate(bh);
> mark_buffer_dirty(bh);
> mark_buffer_async_write(bh);
> unlock_buffer(bh);
> brelse(bh);
There are rather a lot of mistakes in there.
More like this:
lock_page(bh->b_page);
lock_buffer(bh);
byte = bh->b_data + byteoffset;
*byte |= 1 << bitoffset;
mark_buffer_dirty(bh);
unlock_buffer(bh);
flush_dcache_page(page);
unlock_page(page);
put_bh(bh);
now, the buffer is dirty and will be written back by pdflush, sync, etc.
If you really want to start async IO against that buffer now, do
ll_rw_block(WRITE, 1, &bh);
just before the final put_bh().
^ permalink raw reply [flat|nested] 3+ messages in thread
* Buffer head async write
@ 2006-08-30 18:54 Gorka Guardiola
0 siblings, 0 replies; 3+ messages in thread
From: Gorka Guardiola @ 2006-08-30 18:54 UTC (permalink / raw)
To: linux-kernel
I am trying to mark a buffer for async write, but I am having a race condition
to unlock the buffer. I am doing.
bh = getbmapst(bdev, nsect); //this function calls bread
if (!bh) {
printk(KERN_ALERT "I/O error, bitmap cannot be trusted\n");
return -1;
}
lock_buffer(bh);
byte = bh->b_data + byteoffset;
*byte |= 1 << bitoffset;
lock_page(bh->b_page);
mark_page_accessed(bh->b_page);
__set_page_dirty_nobuffers(bh->b_page);
unlock_page(bh->b_page);
set_buffer_uptodate(bh);
mark_buffer_dirty(bh);
mark_buffer_async_write(bh);
unlock_buffer(bh);
brelse(bh);
What I want is the buffer head not to write synchronously when I do
the brelse, to
coalesce writes on it. It works normally, but this code has some form
of race condition.
The problem is that (in some circumstances, for example while using a
loop device against a file) this makes the fs/buffer.c:603
BUG_ON break. I am using the latest version of the kernel with SMP on a machine
with 4 processors.
Can anybody tell me what am I doing wrong?. I tried some other schemes, like
bit_spin_locking the BH_Uptodate_Lock, but they didn't work either.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-08-30 23:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-30 16:35 Buffer head async write Gorka Guardiola
2006-08-30 23:59 ` Andrew Morton
2006-08-30 18:54 Gorka Guardiola
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®