All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: avoid opencoded 64-bit div/mod operation
@ 2024-12-16  8:32 Arnd Bergmann
  2024-12-16  8:37 ` Qu Wenruo
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2024-12-16  8:32 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba, Anand Jain
  Cc: Arnd Bergmann, Qu Wenruo, Johannes Thumshirn, Boris Burkov,
	Naohiro Aota, linux-btrfs, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

Dividing 64-bit numbers causes a link failure on 32-bit builds:

arm-linux-gnueabi-ld: fs/btrfs/sysfs.o: in function `btrfs_read_policy_store':
sysfs.c:(.text+0x3ce0): undefined reference to `__aeabi_ldivmod'

Use an explicit call to div_u64_rem() here to work around this. It would
be possible to optimize this further, but this is not a performance
critical operation.

Fixes: 185fa5c7ac5a ("btrfs: introduce RAID1 round-robin read balancing")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 fs/btrfs/sysfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 50bc4b6cb821..67bc8fa4d6ab 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1433,7 +1433,9 @@ static ssize_t btrfs_read_policy_store(struct kobject *kobj,
 #ifdef CONFIG_BTRFS_EXPERIMENTAL
 	if (index == BTRFS_READ_POLICY_RR) {
 		if (value != -1) {
-			if ((value % fs_devices->fs_info->sectorsize) != 0) {
+			u32 rem;
+			div_u64_rem(value, fs_devices->fs_info->sectorsize, &rem);
+			if (rem) {
 				btrfs_err(fs_devices->fs_info,
 "read_policy: min_contiguous_read %lld should be multiples of the sectorsize %u",
 					  value, fs_devices->fs_info->sectorsize);
-- 
2.39.5


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

* Re: [PATCH] btrfs: avoid opencoded 64-bit div/mod operation
  2024-12-16  8:32 [PATCH] btrfs: avoid opencoded 64-bit div/mod operation Arnd Bergmann
@ 2024-12-16  8:37 ` Qu Wenruo
  2024-12-16  9:22   ` Anand Jain
  0 siblings, 1 reply; 3+ messages in thread
From: Qu Wenruo @ 2024-12-16  8:37 UTC (permalink / raw)
  To: Arnd Bergmann, Chris Mason, Josef Bacik, David Sterba, Anand Jain
  Cc: Arnd Bergmann, Qu Wenruo, Johannes Thumshirn, Boris Burkov,
	Naohiro Aota, linux-btrfs, linux-kernel



在 2024/12/16 19:02, Arnd Bergmann 写道:
> From: Arnd Bergmann <arnd@arndb.de>
>
> Dividing 64-bit numbers causes a link failure on 32-bit builds:
>
> arm-linux-gnueabi-ld: fs/btrfs/sysfs.o: in function `btrfs_read_policy_store':
> sysfs.c:(.text+0x3ce0): undefined reference to `__aeabi_ldivmod'
>
> Use an explicit call to div_u64_rem() here to work around this. It would
> be possible to optimize this further, but this is not a performance
> critical operation.
>
> Fixes: 185fa5c7ac5a ("btrfs: introduce RAID1 round-robin read balancing")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>   fs/btrfs/sysfs.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index 50bc4b6cb821..67bc8fa4d6ab 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -1433,7 +1433,9 @@ static ssize_t btrfs_read_policy_store(struct kobject *kobj,
>   #ifdef CONFIG_BTRFS_EXPERIMENTAL
>   	if (index == BTRFS_READ_POLICY_RR) {
>   		if (value != -1) {
> -			if ((value % fs_devices->fs_info->sectorsize) != 0) {
> +			u32 rem;
> +			div_u64_rem(value, fs_devices->fs_info->sectorsize, &rem);

The original check is already bad, it's just a IS_ALIGNED().

So a much simpler solution is:

+			if (!IS_ALIGNED(value, fs_info->sectorsize)) {

Thanks,
Qu

> +			if (rem) {
>   				btrfs_err(fs_devices->fs_info,
>   "read_policy: min_contiguous_read %lld should be multiples of the sectorsize %u",
>   					  value, fs_devices->fs_info->sectorsize);


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

* Re: [PATCH] btrfs: avoid opencoded 64-bit div/mod operation
  2024-12-16  8:37 ` Qu Wenruo
@ 2024-12-16  9:22   ` Anand Jain
  0 siblings, 0 replies; 3+ messages in thread
From: Anand Jain @ 2024-12-16  9:22 UTC (permalink / raw)
  To: Qu Wenruo, Arnd Bergmann, Chris Mason, Josef Bacik, David Sterba
  Cc: Arnd Bergmann, Qu Wenruo, Johannes Thumshirn, Boris Burkov,
	Naohiro Aota, linux-btrfs, linux-kernel




>> @@ -1433,7 +1433,9 @@ static ssize_t btrfs_read_policy_store(struct 
>> kobject *kobj,
>>   #ifdef CONFIG_BTRFS_EXPERIMENTAL
>>       if (index == BTRFS_READ_POLICY_RR) {
>>           if (value != -1) {
>> -            if ((value % fs_devices->fs_info->sectorsize) != 0) {
>> +            u32 rem;
>> +            div_u64_rem(value, fs_devices->fs_info->sectorsize, &rem);
> 
> The original check is already bad, it's just a IS_ALIGNED().
> 
> So a much simpler solution is:
> 
> +            if (!IS_ALIGNED(value, fs_info->sectorsize)) {

Right, this was also in the review comment by David, and the change
is already in the local work-space. I will be sending v4 out.
Currently dealing with some rebase issues.

Thanks,   Anand


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

end of thread, other threads:[~2024-12-16  9:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-16  8:32 [PATCH] btrfs: avoid opencoded 64-bit div/mod operation Arnd Bergmann
2024-12-16  8:37 ` Qu Wenruo
2024-12-16  9:22   ` Anand Jain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.