Skip to contentSkip to conversation

block: set the bounce_pfn to the actual DMA limit rather than to max memory

PATCH In review Malahal Naineni 2 participants 9 messages Sep 21, 2010 – Oct 1, 2010

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

PATCH 1/1 block: set the bounce_pfn to the actual DMA limit rather than to max memory

The bounce_pfn of the request queue in 64 bit systems is set to the current max_low_pfn. Adding more memory later makes this incorrect. Memory allocated beyond this boot time max_low_pfn appear to require bounce buffers (bounce buffers are actually not allocated but used in calculating segments that may result in "over max segments limit" errors).

block/blk-settings.c +1 -3
diff -r 09daf852c1c5 -r c9516154fabc block/blk-settings.c
@@ -214,16 +214,14 @@ void blk_queue_bounce_limit(struct reque
 	 */
 	if (b_pfn < (min_t(u64, 0xffffffffUL, BLK_BOUNCE_HIGH) >> PAGE_SHIFT))
 		dma = 1;
-	q->limits.bounce_pfn = max_low_pfn;
 #else
 	if (b_pfn < blk_max_low_pfn)
 		dma = 1;
+#endif
 	q->limits.bounce_pfn = b_pfn;
-#endif
 	if (dma) {
 		init_emergency_isa_pool();
 		q->limits.bounce_gfp = GFP_NOIO | GFP_DMA;
-		q->limits.bounce_pfn = b_pfn;
 	}
 }
 EXPORT_SYMBOL(blk_queue_bounce_limit);
#1 lore raw

Jens, any comments on this patch?

Thanks, Malahal.

Quoted 34 lines · Malahal Naineni [[email protected]] wrote:

The bounce_pfn of the request queue in 64 bit systems is set to the current max_low_pfn. Adding more memory later makes this incorrect. Memory allocated beyond this boot time max_low_pfn appear to require bounce buffers (bounce buffers are actually not allocated but used in calculating segments that may result in "over max segments limit" errors).

diff -r 09daf852c1c5 -r c9516154fabc block/blk-settings.c

block/blk-settings.c +1 -4
@@ -214,16 +214,14 @@ void blk_queue_bounce_limit(struct reque
 	 */
 	if (b_pfn < (min_t(u64, 0xffffffffUL, BLK_BOUNCE_HIGH) >> PAGE_SHIFT))
 		dma = 1;
-	q->limits.bounce_pfn = max_low_pfn;
 #else
 	if (b_pfn < blk_max_low_pfn)
 		dma = 1;
+#endif
 	q->limits.bounce_pfn = b_pfn;
-#endif
 	if (dma) {
 		init_emergency_isa_pool();
 		q->limits.bounce_gfp = GFP_NOIO | GFP_DMA;
-		q->limits.bounce_pfn = b_pfn;
 	}
 }
 EXPORT_SYMBOL(blk_queue_bounce_limit);
--

To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to Malahal Naineni
Quoted 2 lines · Malahal Naineni

The bounce_pfn of the request queue in 64 bit systems is set to the current max_low_pfn. Adding more memory later makes this incorrect.

Clearly correct.

Quoted 4 lines

Memory allocated beyond this boot time max_low_pfn appear to require bounce buffers (bounce buffers are actually not allocated but used in calculating segments that may result in "over max segments limit" errors).

But I can't quite convince myself that the change is fully correct. You don't really explain in your own words what the patch does, just what it fixes.

Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 6 lines · Jens Axboe [[email protected]] wrote:
Quoted 2 lines · Malahal Naineni

The bounce_pfn of the request queue in 64 bit systems is set to the current max_low_pfn. Adding more memory later makes this incorrect.

Clearly correct.

Quoted 8 lines
Quoted 4 lines

Memory allocated beyond this boot time max_low_pfn appear to require bounce buffers (bounce buffers are actually not allocated but used in calculating segments that may result in "over max segments limit" errors).

But I can't quite convince myself that the change is fully correct. You don't really explain in your own words what the patch does, just what it fixes.

OK, the problem is we get "over max segments limit" errors from blk_rq_check_limits() after adding memory. The actual bug is in blk_phys_contig_segment() where it doesn't check for possibility of bounce buffers. This results in merging more requests in ll_merge_requests_fn(). Later, blk_recalc_rq_segments() call from blk_rq_check_limits() actually uses the possibility of bounce buffers, so the calculated number of segments exceed q's max_segments resulting in the above error.

Fix for the actual problem is posted here:
http://permalink.gmane.org/gmane.linux.kernel.device-mapper.devel/12426

So clearly the bug should manifest only when 'bounce buffers' are involved! Applying the above patch indeed_fixed_ the problem, but I know there shouldn't be any need for bounce buffers on our system, and further investigation revealed that DMA limit is not set correctly.

This patch also _fixed_ our problem. So we are fine with either patch, but this patch is preferred as it enables more request merges. Also, both patches maybe needed for some configurations.

Thanks, Malahal.

#4 lore raw
Quoted 28 lines · Malahal Naineni
Quoted 6 lines · Jens Axboe [[email protected]] wrote:
Quoted 2 lines · Malahal Naineni

The bounce_pfn of the request queue in 64 bit systems is set to the current max_low_pfn. Adding more memory later makes this incorrect.

Clearly correct.

Quoted 8 lines
Quoted 4 lines

Memory allocated beyond this boot time max_low_pfn appear to require bounce buffers (bounce buffers are actually not allocated but used in calculating segments that may result in "over max segments limit" errors).

But I can't quite convince myself that the change is fully correct. You don't really explain in your own words what the patch does, just what it fixes.

OK, the problem is we get "over max segments limit" errors from blk_rq_check_limits() after adding memory. The actual bug is in blk_phys_contig_segment() where it doesn't check for possibility of bounce buffers. This results in merging more requests in ll_merge_requests_fn(). Later, blk_recalc_rq_segments() call from blk_rq_check_limits() actually uses the possibility of bounce buffers, so the calculated number of segments exceed q's max_segments resulting in the above error.

Fix for the actual problem is posted here:
http://permalink.gmane.org/gmane.linux.kernel.device-mapper.devel/12426

Quoted 8 lines

So clearly the bug should manifest only when 'bounce buffers' are involved! Applying the above patch indeed_fixed_ the problem, but I know there shouldn't be any need for bounce buffers on our system, and further investigation revealed that DMA limit is not set correctly.

This patch also _fixed_ our problem. So we are fine with either patch, but this patch is preferred as it enables more request merges. Also, both patches maybe needed for some configurations.

Plus it doesn't needlessly bounce, that's the real problem you want to fix. I have applied this thread patch to for-2.6.37/core, thanks.

Signature · 1 line
Jens Axboe
#5 lore raw
Quoted 6 lines · Jens Axboe [[email protected]] wrote:
Quoted 3 lines

This patch also _fixed_ our problem. So we are fine with either patch, but this patch is preferred as it enables more request merges. Also, both patches maybe needed for some configurations.

Plus it doesn't needlessly bounce, that's the real problem you want to fix. I have applied this thread patch to for-2.6.37/core, thanks.

There is a shortcut check in blk_queue_bounce() that uses blk_max_pfn to return without doing anything. blk_max_pfn is not updated when we do hot-plug memory add, so bounce buffers are NOT really used in our case (thankfully)!

Here is the code that may need some fix in future:

        if (!(q->limits.bounce_gfp & GFP_DMA)) {
		if (queue_bounce_pfn(q) >= blk_max_pfn)
			return;

Thank you so much for applying this patch.

Thanks, Malahal.

#6 lore raw
Quoted 5 lines · Malahal Naineni
Quoted 4 lines · Jens Axboe [[email protected]] wrote:
Quoted 3 lines

This patch also _fixed_ our problem. So we are fine with either patch, but this patch is preferred as it enables more request merges. Also, both patches maybe needed for some configurations.

Quoted 7 lines
Quoted 2 lines

Plus it doesn't needlessly bounce, that's the real problem you want to fix. I have applied this thread patch to for-2.6.37/core, thanks.

There is a shortcut check in blk_queue_bounce() that uses blk_max_pfn to return without doing anything. blk_max_pfn is not updated when we do hot-plug memory add, so bounce buffers are NOT really used in our case (thankfully)!

Any reason we can't just add a hot mem add notifier and update the block copies when we need to?

Signature · 1 line
Jens Axboe
#7 lore raw
Quoted 9 lines · Jens Axboe [[email protected]] wrote:
Quoted 8 lines · Malahal Naineni
Quoted 6 lines · Jens Axboe [[email protected]] wrote:
Quoted 3 lines

This patch also _fixed_ our problem. So we are fine with either patch, but this patch is preferred as it enables more request merges. Also, both patches maybe needed for some configurations.

Plus it doesn't needlessly bounce, that's the real problem you want to fix. I have applied this thread patch to for-2.6.37/core, thanks.

Quoted 7 lines
Quoted 4 lines

There is a shortcut check in blk_queue_bounce() that uses blk_max_pfn to return without doing anything. blk_max_pfn is not updated when we do hot-plug memory add, so bounce buffers are NOT really used in our case (thankfully)!

Any reason we can't just add a hot mem add notifier and update the block copies when we need to?

Actually it is quite simple, but power arch guys decided not to update max_pfn and max_low_pfn when someone adds or removes memory. They do seem to indicate that it is not an over sight! On the other hand, x86 arch does update those.

Another approach would be defining max_possible_pfn (maximum allowable memory) which would be constant (based on architecture) and hopefully adapters that we care still take the short-cut.

Also, this patch broke some USB hosts. Can you please back out this patch and apply the one below instead:

http://thread.gmane.org/gmane.linux.kernel.next/14158

Thank you very much,
Malahal.

#8 lore raw
Quoted 23 lines · Malahal Naineni
Quoted 9 lines · Jens Axboe [[email protected]] wrote:
Quoted 8 lines · Malahal Naineni
Quoted 6 lines · Jens Axboe [[email protected]] wrote:
Quoted 3 lines

This patch also _fixed_ our problem. So we are fine with either patch, but this patch is preferred as it enables more request merges. Also, both patches maybe needed for some configurations.

Plus it doesn't needlessly bounce, that's the real problem you want to fix. I have applied this thread patch to for-2.6.37/core, thanks.

Quoted 7 lines
Quoted 4 lines

There is a shortcut check in blk_queue_bounce() that uses blk_max_pfn to return without doing anything. blk_max_pfn is not updated when we do hot-plug memory add, so bounce buffers are NOT really used in our case (thankfully)!

Any reason we can't just add a hot mem add notifier and update the block copies when we need to?

Actually it is quite simple, but power arch guys decided not to update max_pfn and max_low_pfn when someone adds or removes memory. They do seem to indicate that it is not an over sight! On the other hand, x86 arch does update those.

Quoted 8 lines

Another approach would be defining max_possible_pfn (maximum allowable memory) which would be constant (based on architecture) and hopefully adapters that we care still take the short-cut.

Also, this patch broke some USB hosts. Can you please back out this patch and apply the one below instead:

http://thread.gmane.org/gmane.linux.kernel.next/14158

Done, thanks.

Signature · 1 line
Jens Axboe