NVDIMM Device and Persistent Memory development
 help / color / Atom feed
* [PATCH v2] libnvdimm, badrange: replace div_u64_rem with DIV_ROUND_UP
@ 2021-06-26  3:53 Kemeng Shi
  2021-07-08 13:11 ` Kemeng Shi
  0 siblings, 1 reply; 2+ messages in thread
From: Kemeng Shi @ 2021-06-26  3:53 UTC (permalink / raw)
  To: dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny, nvdimm,
	linux-kernel

__add_badblock_range use div_u64_rem to round up end_sector and it
will introduces unnecessary rem define and costly '%' operation.
So clean it with DIV_ROUND_UP.

Signed-off-by: Kemeng Shi <shikemeng@huawei.com>
---
V1->V2:
-- fix that end_sector is assigned twice, sorry for that.

 drivers/nvdimm/badrange.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/nvdimm/badrange.c b/drivers/nvdimm/badrange.c
index aaf6e215a8c6..af622ae511aa 100644
--- a/drivers/nvdimm/badrange.c
+++ b/drivers/nvdimm/badrange.c
@@ -187,12 +187,9 @@ static void __add_badblock_range(struct badblocks *bb, u64 ns_offset, u64 len)
 	const unsigned int sector_size = 512;
 	sector_t start_sector, end_sector;
 	u64 num_sectors;
-	u32 rem;

 	start_sector = div_u64(ns_offset, sector_size);
-	end_sector = div_u64_rem(ns_offset + len, sector_size, &rem);
-	if (rem)
-		end_sector++;
+	end_sector = DIV_ROUND_UP(ns_offset + len, sector_size);
 	num_sectors = end_sector - start_sector;

 	if (unlikely(num_sectors > (u64)INT_MAX)) {
-- 
2.23.0

-- 
Best wishes
Kemeng Shi

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] libnvdimm, badrange: replace div_u64_rem with DIV_ROUND_UP
  2021-06-26  3:53 [PATCH v2] libnvdimm, badrange: replace div_u64_rem with DIV_ROUND_UP Kemeng Shi
@ 2021-07-08 13:11 ` Kemeng Shi
  0 siblings, 0 replies; 2+ messages in thread
From: Kemeng Shi @ 2021-07-08 13:11 UTC (permalink / raw)
  To: dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny, nvdimm,
	linux-kernel


A gentle ping

on 2021/6/26 11:53, Kemeng Shi wrote:
> __add_badblock_range use div_u64_rem to round up end_sector and it
> will introduces unnecessary rem define and costly '%' operation.
> So clean it with DIV_ROUND_UP.
> 
> Signed-off-by: Kemeng Shi <shikemeng@huawei.com>
> ---
> V1->V2:
> -- fix that end_sector is assigned twice, sorry for that.
> 
>  drivers/nvdimm/badrange.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/nvdimm/badrange.c b/drivers/nvdimm/badrange.c
> index aaf6e215a8c6..af622ae511aa 100644
> --- a/drivers/nvdimm/badrange.c
> +++ b/drivers/nvdimm/badrange.c
> @@ -187,12 +187,9 @@ static void __add_badblock_range(struct badblocks *bb, u64 ns_offset, u64 len)
>  	const unsigned int sector_size = 512;
>  	sector_t start_sector, end_sector;
>  	u64 num_sectors;
> -	u32 rem;
> 
>  	start_sector = div_u64(ns_offset, sector_size);
> -	end_sector = div_u64_rem(ns_offset + len, sector_size, &rem);
> -	if (rem)
> -		end_sector++;
> +	end_sector = DIV_ROUND_UP(ns_offset + len, sector_size);
>  	num_sectors = end_sector - start_sector;
> 
>  	if (unlikely(num_sectors > (u64)INT_MAX)) {
> 

-- 
Best wishes
Kemeng Shi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-26  3:53 [PATCH v2] libnvdimm, badrange: replace div_u64_rem with DIV_ROUND_UP Kemeng Shi
2021-07-08 13:11 ` Kemeng Shi

NVDIMM Device and Persistent Memory development

Archives are clonable:
	git clone --mirror https://lore.kernel.org/nvdimm/0 nvdimm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 nvdimm nvdimm/ https://lore.kernel.org/nvdimm \
		nvdimm@lists.linux.dev
	public-inbox-index nvdimm

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/dev.linux.lists.nvdimm


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git