mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 20:51:03 +02:00
block: factor out a bvec_alloc_gfp helper
Clean up bvec_alloc a little by factoring out a helper for the gfp_t manipulations. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
committed by
Jens Axboe
parent
6ac0b71537
commit
f2c3eb9bb0
20
block/bio.c
20
block/bio.c
@@ -159,6 +159,16 @@ void bvec_free(mempool_t *pool, struct bio_vec *bv, unsigned int idx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Make the first allocation restricted and don't dump info on allocation
|
||||||
|
* failures, since we'll fall back to the mempool in case of failure.
|
||||||
|
*/
|
||||||
|
static inline gfp_t bvec_alloc_gfp(gfp_t gfp)
|
||||||
|
{
|
||||||
|
return (gfp & ~(__GFP_DIRECT_RECLAIM | __GFP_IO)) |
|
||||||
|
__GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN;
|
||||||
|
}
|
||||||
|
|
||||||
struct bio_vec *bvec_alloc(gfp_t gfp_mask, int nr, unsigned long *idx,
|
struct bio_vec *bvec_alloc(gfp_t gfp_mask, int nr, unsigned long *idx,
|
||||||
mempool_t *pool)
|
mempool_t *pool)
|
||||||
{
|
{
|
||||||
@@ -199,20 +209,12 @@ fallback:
|
|||||||
bvl = mempool_alloc(pool, gfp_mask);
|
bvl = mempool_alloc(pool, gfp_mask);
|
||||||
} else {
|
} else {
|
||||||
struct biovec_slab *bvs = bvec_slabs + *idx;
|
struct biovec_slab *bvs = bvec_slabs + *idx;
|
||||||
gfp_t __gfp_mask = gfp_mask & ~(__GFP_DIRECT_RECLAIM | __GFP_IO);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Make this allocation restricted and don't dump info on
|
|
||||||
* allocation failures, since we'll fallback to the mempool
|
|
||||||
* in case of failure.
|
|
||||||
*/
|
|
||||||
__gfp_mask |= __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try a slab allocation. If this fails and __GFP_DIRECT_RECLAIM
|
* Try a slab allocation. If this fails and __GFP_DIRECT_RECLAIM
|
||||||
* is set, retry with the 1-entry mempool
|
* is set, retry with the 1-entry mempool
|
||||||
*/
|
*/
|
||||||
bvl = kmem_cache_alloc(bvs->slab, __gfp_mask);
|
bvl = kmem_cache_alloc(bvs->slab, bvec_alloc_gfp(gfp_mask));
|
||||||
if (unlikely(!bvl && (gfp_mask & __GFP_DIRECT_RECLAIM))) {
|
if (unlikely(!bvl && (gfp_mask & __GFP_DIRECT_RECLAIM))) {
|
||||||
*idx = BVEC_POOL_MAX;
|
*idx = BVEC_POOL_MAX;
|
||||||
goto fallback;
|
goto fallback;
|
||||||
|
Reference in New Issue
Block a user