[PATCH] brd: decrease the number of allocated pages which discarded

long.yunjian@zte.com.cn posted 1 patch 1 year, 2 months ago
drivers/block/brd.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] brd: decrease the number of allocated pages which discarded
Posted by long.yunjian@zte.com.cn 1 year, 2 months ago
From: Zhang Xianwei <zhang.xianwei8@zte.com.cn>
The number of allocated pages which discarded will not decrease.
Fix it.

Fixes: 9ead7efc6f3f ("brd: implement discard support")

Signed-off-by: Zhang Xianwei <zhang.xianwei8@zte.com.cn>
---
 drivers/block/brd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 5a95671d8151..292f127cae0a 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -231,8 +231,10 @@ static void brd_do_discard(struct brd_device *brd, sector_t sector, u32 size)
 	xa_lock(&brd->brd_pages);
 	while (size >= PAGE_SIZE && aligned_sector < rd_size * 2) {
 		page = __xa_erase(&brd->brd_pages, aligned_sector >> PAGE_SECTORS_SHIFT);
-		if (page)
+		if (page) {
 			__free_page(page);
+			brd->brd_nr_pages--;
+		}
 		aligned_sector += PAGE_SECTORS;
 		size -= PAGE_SIZE;
 	}
-- 
2.27.0
Re: [PATCH] brd: decrease the number of allocated pages which discarded
Posted by Jens Axboe 1 year, 2 months ago
On Thu, 28 Nov 2024 17:00:56 +0800, long.yunjian@zte.com.cn wrote:
> The number of allocated pages which discarded will not decrease.
> Fix it.
> 
> Fixes: 9ead7efc6f3f ("brd: implement discard support")
> 
> 

Applied, thanks!

[1/1] brd: decrease the number of allocated pages which discarded
      commit: 82734209bedd65a8b508844bab652b464379bfdd

Best regards,
-- 
Jens Axboe
Re: [PATCH] brd: decrease the number of allocated pages which discarded
Posted by Ming Lei 1 year, 2 months ago
On Thu, Nov 28, 2024 at 5:01 PM <long.yunjian@zte.com.cn> wrote:
>
> From: Zhang Xianwei <zhang.xianwei8@zte.com.cn>
> The number of allocated pages which discarded will not decrease.
> Fix it.
>
> Fixes: 9ead7efc6f3f ("brd: implement discard support")
>
> Signed-off-by: Zhang Xianwei <zhang.xianwei8@zte.com.cn>
> ---
>  drivers/block/brd.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/block/brd.c b/drivers/block/brd.c
> index 5a95671d8151..292f127cae0a 100644
> --- a/drivers/block/brd.c
> +++ b/drivers/block/brd.c
> @@ -231,8 +231,10 @@ static void brd_do_discard(struct brd_device *brd, sector_t sector, u32 size)
>         xa_lock(&brd->brd_pages);
>         while (size >= PAGE_SIZE && aligned_sector < rd_size * 2) {
>                 page = __xa_erase(&brd->brd_pages, aligned_sector >> PAGE_SECTORS_SHIFT);
> -               if (page)
> +               if (page) {
>                         __free_page(page);
> +                       brd->brd_nr_pages--;
> +               }

Reviewed-by: Ming Lei <ming.lei@redhat.com>