only irq-safe atomic ops
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 8 lines · Andrew Morton
Quoted 5 lines
Quoted 1 line
I can tell you that Irix has just such a global counter for the amount of delayed allocate pages - and it gets to be a major point of cache contention once you get to larger cpu counts. So avoiding that from the start would be good.
Ah, good info. Thanks. I'll fix it with a big "FIXME" comment for now, fix it for real when Rusty's per-CPU infrastructure appears.
Just curious -- how do you want to fix it for real?
As far as I can see a delalloc counter needs to be exact to avoid OOM deadlocks, but making it per CPU would require doing the accounting inexact.
The only way I can imagine is to use the 'cookie jar' trick by grabbing some amount per CPU and only going back to the global counter when the local jar is used up, but that seems to have some drawbacks too, like keeping a lot of pages free with higher CPU counts.
-Andi
Quoted 8 lines · Andi Kleen
Quoted 6 lines · Andrew Morton
Quoted 5 lines
Quoted 1 line
I can tell you that Irix has just such a global counter for the amount of delayed allocate pages - and it gets to be a major point of cache contention once you get to larger cpu counts. So avoiding that from the start would be good.
Quoted 6 lines
Quoted 2 lines
Ah, good info. Thanks. I'll fix it with a big "FIXME" comment for now, fix it for real when Rusty's per-CPU infrastructure appears.
Just curious -- how do you want to fix it for real?
As far as I can see a delalloc counter needs to be exact to avoid OOM deadlocks, but making it per CPU would require doing the accounting inexact.
The counter is used only for making writeback decisions. It is completely analogous to nr_buffers_type[BUF_DIRTY], except it counts
pages. So it does not need to be exact for readers.
If we needed exact reader-accounting for the number of dirty pages in the machine then we'd need a ton of new locking in fun places like __free_pte(), and that still doesn't account for pages which are only pte-dirty, and it's not obvious what we'd do with reader-exact dirty page info anyway?
-
Quoted 17 lines · Andrew Morton
Quoted 7 lines · Andi Kleen
Quoted 5 lines · Andrew Morton
Quoted 5 lines
I can tell you that Irix has just such a global counter for the amount of delayed allocate pages - and it gets to be a major point of cache contention once you get to larger cpu counts. So avoiding that from the start would be good.
Quoted 7 lines
Quoted 3 lines
Ah, good info. Thanks. I'll fix it with a big "FIXME" comment for now, fix it for real when Rusty's per-CPU infrastructure appears.
Just curious -- how do you want to fix it for real?
As far as I can see a delalloc counter needs to be exact to avoid OOM deadlocks, but making it per CPU would require doing the accounting inexact.
Quoted 10 lines
The counter is used only for making writeback decisions. It is completely analogous to nr_buffers_type[BUF_DIRTY], except it counts
pages. So it does not need to be exact for readers.If we needed exact reader-accounting for the number of dirty pages in the machine then we'd need a ton of new locking in fun places like
__free_pte(), and that still doesn't account for pages which are only pte-dirty, and it's not obvious what we'd do with reader-exact dirty page info anyway?
You do want to avoid a leak in one direction or the other, the os would start to think it had lots of dirty pages, but not be able to find them, or think there is no shortage when in fact there was.
Steve
Quoted 8 lines · Stephen Lord
...
Quoted 6 lines
If we needed exact reader-accounting for the number of dirty pages in the machine then we'd need a ton of new locking in fun places like
__free_pte(), and that still doesn't account for pages which are only pte-dirty, and it's not obvious what we'd do with reader-exact dirty page info anyway?
Quoted 5 lines
You do want to avoid a leak in one direction or the other, the os would start to think it
had lots of dirty pages, but not be able to find them, or think there is no shortage
when in fact there was.
Oh absolutely. Even a one-page-per-hour leak would be catastrophic.
But there is a problem. If CPUA is always setting pages dirty, and CPUB is always setting them clean, CPUA's counter will eventually overflow, and CPUB's will underflow. Drat.
One fix for this would be special-case over- and under-flow handling:
if (TestSetPageDirty(page)) {
preempt_disable();
nr_dirty_pages[smp_processor_id()]++;
if (nr_dirty_pages[smp_processor_id()] > 2,000,000) {
fit_it_up();
}
preempt_enable();
}
void fix_it_up()
{
spin_lock(&global_counter_lock);
global_counter += 1,000,000;
nr_dirty_pages[smp_processor_id()] -= 1,000,000;
spin_unlock(&global_counter_lock);
}
int approx_total_dirty_pages()
{
int ret;
spin_lock(&global_counter_lock);
ret = global_counter;
for (all cpus) {
ret += nr_dirty_pages[cpu];
}
spin_unlock(&global_counter_lock);
return ret;
}Or something like that.
Then again, maybe the underflows and overflows don't matter, because the
sum of all counters is always correct. Unless there's a counter roll-over
during the summation. No. Even then it's OK.
hmmm.
-
Quoted 49 lines · Andrew Morton
Quoted 6 lines · Stephen Lord
You do want to avoid a leak in one direction or the other, the os would start to think it
had lots of dirty pages, but not be able to find them, or think there is no shortage
when in fact there was.Oh absolutely. Even a one-page-per-hour leak would be catastrophic.
But there is a problem. If CPUA is always setting pages dirty, and CPUB is always setting them clean, CPUA's counter will eventually overflow, and CPUB's will underflow. Drat.
One fix for this would be special-case over- and under-flow handling:
if (TestSetPageDirty(page)) { preempt_disable(); nr_dirty_pages[smp_processor_id()]++; if (nr_dirty_pages[smp_processor_id()] > 2,000,000) { fit_it_up(); } preempt_enable(); } void fix_it_up() { spin_lock(&global_counter_lock); global_counter += 1,000,000; nr_dirty_pages[smp_processor_id()] -= 1,000,000; spin_unlock(&global_counter_lock); } int approx_total_dirty_pages() { int ret; spin_lock(&global_counter_lock); ret = global_counter; for (all cpus) { ret += nr_dirty_pages[cpu]; } spin_unlock(&global_counter_lock); return ret; }Or something like that.
Quoted 8 lines
Then again, maybe the underflows and overflows don't matter, because the
sum of all counters is always correct. Unless there's a counter roll-over
during the summation. No. Even then it's OK.hmmm.
-
As I was plumbing in a sink ;-) the thought also occurred that you could have allocate and free counters per cpu. The fix up code could do leveling between them. Are you sure you only want to look at the actual value infrequently though? Every time you put a page into delalloc state you need to do something similar to balance_dirty(), if you only poll the value periodically then it could get way out of balance before you noticed. It is very easy to dirty memory this way, cat /dev/zero > xxxx runs very quickly.
I would almost say you need to get a 'reservation' of a delalloc page before you grab the memory. There are extra memory costs associated with getting the page out of this state, and if you do not hold threads back from dirtying pages you can end up in a situation where you cannot clean up again.
Steve
Quoted 5 lines · Stephen Lord
...
As I was plumbing in a sink ;-) the thought also occurred that you could have allocate and free counters per cpu. The fix up code could do leveling between them.
yup. If fixup code is needed.
Quoted 3 lines
Are you sure you only want to look at the actual value infrequently though? Every time you put a page into delalloc state you need to do something similar to
balance_dirty(),
balance_dirty_pages() :)
Quoted 3 lines
if you only poll the value periodically then it could get way out of balance before you noticed. It is very easy to dirty memory this way, cat
/dev/zero> xxxx runs very quickly.
At present, I'm calling balance_dirty_pages() once per 32 pages within generic_file_write(). And also once on the way out of generic_file_write(). Even if a zillion threads were writing at the same time, someone will do an allocation and the VM will then send a pdflush thread off to perform
some writeback. I think this is all OK.
One possible wart with delayed allocate is that we need to go off and instantiate disk mappings at writepage() time, which may cause extra memory squeezes. I'm not particularly fussed about that at this time. It's a VM problem...
balance_dirty_pages does:
if (dirty_pages > sync_threshold) sync_writeback(); else if (dirty_pages > async_threshold) async_writeback(); else if (dirty_pages > background_threshold) tell_a_pdflush_thread_to_do_some_writeback();
Current code is at http://www.zip.com.au/~akpm/linux/patches/2.5/2.5.5/,
but I haven't released it yet :)
That code is presently shoving half-megabyte BIOs direct from pagecache into the block layer. There are no buffer_heads used at all in the write(2) path. One such BIO saves 128 buffer_head allocations, 128 bio_allocs and a ton of request merging.
Unfortunately I seem to have found a bug in existing ext2, a bug in existing block_write_full_page, a probable bug in the aic7xxx driver, and an oops in the aic7xxx driver. So progress has slowed down a bit :(
Quoted 8 lines
I would almost say you need to get a 'reservation' of a delalloc page before you
grab the memory. There are extra memory costs associated with getting the page out of this state, and if you do not hold threads back from dirtying pages
you can end up in a situation where you cannot clean up again.
I reserve the space in the filesystem at ->prepare_write() time. If there's no space, I force a writeback to cause all the outstanding worst-case reservations to be collapsed into real disk mappings. If there's still no space, prepare_write returns -ENOSPC.
I terms of memory use, I think balance_dirty_pages takes care of everything. If there are too many dirty pages, the caller of write(2) performs synchronous writeout, just as happens with the legacy buffer_head-based writeout.
Early days yet.
-
Quoted 4 lines · Andrew Morton
Unfortunately I seem to have found a bug in existing ext2, a bug in existing
block_write_full_page, a probable bug in the aic7xxx driver, and an oops in the aic7xxx driver. So progress has slowed down a bit :(
Are these bugs in 2.4 also?
Quoted 8 lines · Mike Fedyk
Quoted 4 lines · Andrew Morton
Unfortunately I seem to have found a bug in existing ext2, a bug in existing
block_write_full_page, a probable bug in the aic7xxx driver, and an oops in the aic7xxx driver. So progress has slowed down a bit :(Are these bugs in 2.4 also?
The test case is:
- 120 megabyte filesystem, 1k blocksize ext2. SMP.
- run `dbench 64 2>/dev/null >/dev/null', as root (dunno if rootness matters, but it affects ext2 allocation policy).
This really hammers the out-of-space handling.
We get a stream of `__block_prepare_write: zeroing uptodate buffer' messages. I added that message. I shall work out whether there's a bug, or if the message just gets killed. This happens in 2.4 also.
We get a handful of `VFS: brelse: Trying to free free buffer' messages, coming from this code:
/* Next simple case - plain lookup or failed read of indirect block */
if (!create || err == -EIO) {
cleanup:
while (partial > chain) {
brelse(partial->bh);
partial--;
}in ext2_get_block(). This only happens in 2.5. It happens on uniprocessor. Possibly a bug introduced by the changed ext2 locking in 2.5. I have not investigated further.
With my I/O scheduling changes the SCSI driver gets all upset about data overruns or such. This may be my fault. It's a 2.5 issue.
During recovery from the data overrun, the SCSI driver oopses over manipulation of a dodgy-looking timer struct.
-
Quoted 7 lines · Andrew Morton
Unfortunately I seem to have found a bug in existing ext2, a bug in existing
block_write_full_page, a probable bug in the aic7xxx driver, and an oops in the aic7xxx driver. So progress has slowed down a bit :(
Try this for the aic driver:
--- /export/xfs1/snapshots-2.5/linus-tree/linux/drivers/scsi/aic7xxx/aic7xxx_linux.c Sun Feb 10 19:50:15 2002
+++ linux/drivers/scsi/aic7xxx/aic7xxx_linux.c Sun Jan 27 21:08:28 2002 @@ -1646,6 +1646,7 @@
scb->platform_data->xfer_len = 0;
ahc_set_residual(scb, 0);
ahc_set_sense_residual(scb, 0);
+ scb->sg_count = 0;
if (cmd->use_sg != 0) {
struct ahc_dma_seg *sg;
struct scatterlist *cur_seg;You will need to use ignore white space on this, I had to use cut and paste to get it into email.
We hit this once bio got introduced and we maxed out the request size for the driver. Justin has the code in his next aic version.
Steve