fix /dev/sg allocation failures register
Subsystems (3)
Hi all,
Shin'ichiro reported trivially triggerable allocation failures when using SG_IO on the sg driver. This turn out to be caused by the bio allocation rework, which makes non-blocking allocation fail much easier.
This series has two independent patches to fix this from different angles. The first one changes the completely pointless GFP_ATOMIC to use GFP_ATOMIC in sg. The other drops the reduction of the gfp mask in the bio allocator, so that atomic allocations of bios work as expected, even if they are a pretty bad idea as the bio submission actually needs a user context anyway. The only other uses of this seems to be the ocfs2 cluster managed.
PATCH 1/2 sg: don't use GFP_ATOMIC in sg_start_req
sg_start_req is called from normal user context and can sleep when waiting for memory. Switch it to use GFP_KERNEL, which fixes allocation failures seend with the bio_alloc rework.
--- drivers/scsi/sg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/sg.c +1 -1
@@ -1811,7 +1811,7 @@ sg_start_req(Sg_request *srp, unsigned char *cmd) } res =blk_rq_map_user_io (rq, md, hp->dxferp, hp->dxfer_len, -GFP_ATOMIC , iov_count, iov_count,1 , rw); +GFP_KERNEL , iov_count, iov_count,1 , rw);if (!res) { srp->bio = rq->bio;
Signature · 1 line
2.53.0
Re: [PATCH 1/2] sg: don't use GFP_ATOMIC in sg_start_req
Quoted 8 lines · Christoph Hellwig
sg_start_reqis called from normal user context and can sleep when waiting for memory. Switch it to useGFP_KERNEL, which fixes allocation failures seend with thebio_allocrework.Fixes b520c4eef83d ("block: split bio_alloc_bioset more clearly into a fast and slowpath")Reported-by Shin'ichiro Kawasaki <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>Tested-by Shin'ichiro Kawasaki <[email protected]>
FWIW:
Re: [PATCH 1/2] sg: don't use GFP_ATOMIC in sg_start_req
In reply to Christoph HellwigQuoted 17 lines · Christoph Hellwig
sg_start_reqis called from normal user context and can sleep when waiting for memory. Switch it to useGFP_KERNEL, which fixes allocation failures seend with thebio_allocrework.Fixes b520c4eef83d ("block: split bio_alloc_bioset more clearly into a fast and slowpath")Reported-by Shin'ichiro Kawasaki <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>Tested-by Shin'ichiro Kawasaki <[email protected]>--- drivers/scsi/sg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/sg.c +0
-0
drivers/scsi/sg.c sg_start_req(Sg_request *srp, unsigned char *cmd) · line 1817
Quoted 8 lines
drivers/scsi/sg.c +1
-1@@ -1811,7 +1811,7 @@ sg_start_req(Sg_request *srp, unsigned char *cmd) } res =blk_rq_map_user_io (rq, md, hp->dxferp, hp->dxfer_len, -GFP_ATOMIC , iov_count, iov_count,1 , rw); +GFP_KERNEL , iov_count, iov_count,1 , rw);if (!res) { srp->bio = rq->bio;
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Re: [PATCH 1/2] sg: don't use GFP_ATOMIC in sg_start_req
In reply to Christoph HellwigQuoted 3 lines · Christoph Hellwig
sg_start_reqis called from normal user context and can sleep when waiting for memory. Switch it to useGFP_KERNEL, which fixes allocation failures seend with thebio_allocrework.
seend -> seen
Anyway:
Re: (subset) [PATCH 1/2] sg: don't use GFP_ATOMIC in sg_start_req
In reply to Christoph HellwigQuoted 3 lines · Christoph Hellwig
sg_start_reqis called from normal user context and can sleep when waiting for memory. Switch it to useGFP_KERNEL, which fixes allocation failures seend with thebio_allocrework.
Applied, thanks!
[2/2] block: only restrict bio allocation gfp mask asked to block
commit: b5129bda5bbcceea5b2589c8248d39f77660aa19
Best regards,
Signature · 1 line
Jens Axboe
PATCH 2/2 block: only restrict bio allocation gfp mask asked to block
In reply to Christoph HellwigIf the caller is asking for a non-blocking allocation, we should not further restrict the gfp mask, which just increases the likelihood of failures.
--- block/bio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/bio.c +2 -1
@@ -544,7 +544,8 @@ struct bio *bio_alloc_bioset(struct block_device *bdev, unsigned short nr_vecs,if (WARN_ON_ONCE (!mempool_initialized (&bs->bvec_pool) && nr_vecs >0 ))return NULL ; - gfp =try_alloc_gfp (gfp); +if (saved_gfp & __GFP_DIRECT_RECLAIM) + gfp =try_alloc_gfp (gfp);if (bs->cache && nr_vecs <=BIO_INLINE_VECS ) {/* * Set REQ_ALLOC_CACHE even if no cached bio is available to
Signature · 1 line
2.53.0
Re: [PATCH 2/2] block: only restrict bio allocation gfp mask asked to block
Quoted 16 lines · Christoph Hellwig
If the caller is asking for a non-blocking allocation, we should not further restrict the gfp mask, which just increases the likelihood of failures.
Fixes b520c4eef83d ("block: split bio_alloc_bioset more clearly into a fast and slowpath")Reported-by Shin'ichiro Kawasaki <[email protected]>Signed-off-by Christoph Hellwig <[email protected]>--- block/bio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)block/bio.c +0
-0
block/bio.c struct bio *bio_alloc_bioset(struct block_device *bdev, unsigned short nr_vecs, · line 551
Quoted 9 lines
block/bio.c +2
-1@@ -544,7 +544,8 @@ struct bio *bio_alloc_bioset(struct block_device *bdev, unsigned short nr_vecs,if (WARN_ON_ONCE (!mempool_initialized (&bs->bvec_pool) && nr_vecs >0 ))return NULL ; - gfp =try_alloc_gfp (gfp); +if (saved_gfp & __GFP_DIRECT_RECLAIM) + gfp =try_alloc_gfp (gfp);if (bs->cache && nr_vecs <=BIO_INLINE_VECS ) {/* * Set REQ_ALLOC_CACHE even if no cached bio is available to
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Kernel Storage Architect [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
Re: [PATCH 2/2] block: only restrict bio allocation gfp mask asked to block
In reply to Christoph HellwigQuoted 3 lines · Christoph Hellwig
If the caller is asking for a non-blocking allocation, we should not further restrict the gfp mask, which just increases the likelihood of failures.
Christoph,
Quoted 7 lines
This series has two independent patches to fix this from different angles. The first one changes the completely pointless
GFP_ATOMICto useGFP_ATOMICin sg. The other drops the reduction of the gfp mask in the bio allocator, so that atomic allocations of bios work as expected, even if they are a pretty bad idea as the bio submission actually needs a user context anyway. The only other uses of this seems to be the ocfs2 cluster managed.
Applied #1 to 7.1/scsi-staging, thanks!
#2 needs to go through block.
Signature · 1 line
Martin K. Petersen