[PATCH 2/2] mtd: ubi: use GFP_NOIO for lock tree entry allocation
Zhihao Cheng
chengzhihao1 at huawei.com
Thu Oct 15 04:03:47 PDT 2026
在 2026/10/15 15:33, Yelin Fei 写道:
> From: Ye Linfei <yelinfei at ruijie.com.cn>
>
> The per-LEB lock tree entry can be allocated while UBI is executing on
> behalf of a synchronous block-layer consumer (ubiblock), where issuing
> further block I/O from direct reclaim would deadlock; see the
> preceding commit "mtd: ubi: block: forbid direct reclaim I/O during
> synchronous read" for the full analysis.
>
> Make the allocation self-contained: GFP_NOIO restricts direct reclaim
> to dropping clean page cache and shrinking slabs, page (swap) reclaim
> is left to kswapd, and the worst case is -ENOMEM, which callers
> already propagate as an ordinary recoverable I/O error.
>
> memalloc_noio_save()/memalloc_noio_restore() in ubiblock_read()
> already enforce this for the whole read scope; keeping the allocation
> here self-contained as well means the safety property does not depend
> on every future caller remembering to set up that scope.
The ltree_add_entry() has many callers that not need GFP_NOIO, I think
'mtd: ubi: block: forbid direct reclaim I/O during
> synchronous read' is enough.
>
> Signed-off-by: Ye Linfei <yelinfei at ruijie.com.cn>
> ---
> drivers/mtd/ubi/eba.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
> index f0c549e62c55..8fe68e7fff58 100644
> --- a/drivers/mtd/ubi/eba.c
> +++ b/drivers/mtd/ubi/eba.c
> @@ -247,7 +247,7 @@ static struct ubi_ltree_entry *ltree_add_entry(struct ubi_device *ubi,
> {
> struct ubi_ltree_entry *le, *le1, *le_free;
>
> - le = kmalloc_obj(struct ubi_ltree_entry, GFP_NOFS);
> + le = kmalloc_obj(struct ubi_ltree_entry, GFP_NOIO); /* see ubiblock_read() */
> if (!le)
> return ERR_PTR(-ENOMEM);
>
>
More information about the linux-mtd
mailing list