From: Akinobu Mita <akinobu.mita@gmail.com> Date: 2012-06-09 00:50:55
memweight() is the function that counts the total number of bits set
in memory area. Unlike bitmap_weight(), memweight() takes pointer
and size in bytes to specify a memory area which does not need to be
aligned to long-word boundary.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Anders Larsen <al@alarsen.net>
Cc: Alasdair Kergon <agk@redhat.com>
Cc: dm-devel@redhat.com
Cc: linux-fsdevel@vger.kernel.org
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: linux-media@vger.kernel.org
Cc: Mark Fasheh <redacted>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: ocfs2-devel@oss.oracle.com
Cc: Jan Kara <jack@suse.cz>
Cc: linux-ext4@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Matthew Wilcox <redacted>
---
v3: add comment for the last loop, adviced by Jan Kara
v2: simplify memweight(), adviced by Jan Kara
include/linux/string.h | 3 +++
lib/string.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 0 deletions(-)
From: Akinobu Mita <akinobu.mita@gmail.com> Date: 2012-06-09 00:52:15
Convert ext2_count_free() to use memweight() instead of table lookup
based counting clear bits implementation. This change only affects
the code segments enabled by EXT2FS_DEBUG.
Note that this memweight() call can't be replaced with a single
bitmap_weight() call, although the pointer to the memory area is
aligned to long-word boundary. Because the size of the memory area
may not be a multiple of BITS_PER_LONG, then it returns wrong value on
big-endian architecture.
This also includes the following changes.
- Remove unnecessary map == NULL check in ext2_count_free() which
always takes non-null pointer as the memory area.
- Fix printk format warning that only reveals with EXT2FS_DEBUG.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Jan Kara <jack@suse.cz>
Cc: linux-ext4@vger.kernel.org
---
v3: rewrite to keep ext2_count_free() as a wrapper for memweight()
fs/ext2/balloc.c | 14 ++------------
fs/ext2/ialloc.c | 1 +
2 files changed, 3 insertions(+), 12 deletions(-)
From: Jan Kara <jack@suse.cz> Date: 2012-06-12 09:14:23
On Sat 09-06-12 09:50:36, Akinobu Mita wrote:
Convert ext2_count_free() to use memweight() instead of table lookup
based counting clear bits implementation. This change only affects
the code segments enabled by EXT2FS_DEBUG.
Note that this memweight() call can't be replaced with a single
bitmap_weight() call, although the pointer to the memory area is
aligned to long-word boundary. Because the size of the memory area
may not be a multiple of BITS_PER_LONG, then it returns wrong value on
big-endian architecture.
This also includes the following changes.
- Remove unnecessary map == NULL check in ext2_count_free() which
always takes non-null pointer as the memory area.
- Fix printk format warning that only reveals with EXT2FS_DEBUG.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Jan Kara <jack@suse.cz>
Acked-by: Jan Kara [off-list ref]
Honza
quoted hunk
Cc: linux-ext4@vger.kernel.org
---
v3: rewrite to keep ext2_count_free() as a wrapper for memweight()
fs/ext2/balloc.c | 14 ++------------
fs/ext2/ialloc.c | 1 +
2 files changed, 3 insertions(+), 12 deletions(-)
From: Akinobu Mita <akinobu.mita@gmail.com> Date: 2012-06-09 00:52:21
Convert ext3_count_free() to use memweight() instead of table lookup
based counting clear bits implementation. This change only affects
the code segments enabled by EXT3FS_DEBUG.
Note that this memweight() call can't be replaced with a single
bitmap_weight() call, although the pointer to the memory area is
aligned to long-word boundary. Because the size of the memory area
may not be a multiple of BITS_PER_LONG, then it returns wrong value on
big-endian architecture.
This also includes the following changes.
- Remove unnecessary map == NULL check in ext3_count_free() which
always takes non-null pointer as the memory area.
- Fix printk format warning that only reveals with EXT3FS_DEBUG.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: linux-ext4@vger.kernel.org
---
v3: rewrite to keep ext3_count_free() as a wrapper for memweight()
fs/ext3/balloc.c | 2 +-
fs/ext3/bitmap.c | 12 +-----------
2 files changed, 2 insertions(+), 12 deletions(-)
From: Jan Kara <jack@suse.cz> Date: 2012-06-12 09:14:43
On Sat 09-06-12 09:50:37, Akinobu Mita wrote:
Convert ext3_count_free() to use memweight() instead of table lookup
based counting clear bits implementation. This change only affects
the code segments enabled by EXT3FS_DEBUG.
Note that this memweight() call can't be replaced with a single
bitmap_weight() call, although the pointer to the memory area is
aligned to long-word boundary. Because the size of the memory area
may not be a multiple of BITS_PER_LONG, then it returns wrong value on
big-endian architecture.
This also includes the following changes.
- Remove unnecessary map == NULL check in ext3_count_free() which
always takes non-null pointer as the memory area.
- Fix printk format warning that only reveals with EXT3FS_DEBUG.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Jan Kara <jack@suse.cz>
Acked-by: Jan Kara [off-list ref]
Honza
quoted hunk
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: linux-ext4@vger.kernel.org
---
v3: rewrite to keep ext3_count_free() as a wrapper for memweight()
fs/ext3/balloc.c | 2 +-
fs/ext3/bitmap.c | 12 +-----------
2 files changed, 2 insertions(+), 12 deletions(-)
From: Akinobu Mita <akinobu.mita@gmail.com> Date: 2012-06-09 00:52:25
Convert ext4_count_free() to use memweight() instead of table lookup
based counting clear bits implementation. This change only affects
the code segments enabled by EXT4FS_DEBUG.
Note that this memweight() call can't be replaced with a single
bitmap_weight() call, although the pointer to the memory area is
aligned to long-word boundary. Because the size of the memory area
may not be a multiple of BITS_PER_LONG, then it returns wrong value on
big-endian architecture.
This also includes the following change.
- Remove unnecessary map == NULL check in ext4_count_free() which
always takes non-null pointer as the memory area.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>
Cc: linux-ext4@vger.kernel.org
---
v3: rewrite to keep ext4_count_free() as a wrapper for memweight()
v2: don't remove bitmap.c which now has other than ext4_count_free()
fs/ext4/bitmap.c | 11 +----------
1 files changed, 1 insertions(+), 10 deletions(-)
From: Andrew Morton <akpm@linux-foundation.org> Date: 2012-06-11 23:17:25
On Sat, 9 Jun 2012 09:50:30 +0900
Akinobu Mita [off-list ref] wrote:
memweight() is the function that counts the total number of bits set
in memory area. Unlike bitmap_weight(), memweight() takes pointer
and size in bytes to specify a memory area which does not need to be
aligned to long-word boundary.
...
+/**
+ * memweight - count the total number of bits set in memory area
+ * @ptr: pointer to the start of the area
+ * @bytes: the size of the area
+ */
+size_t memweight(const void *ptr, size_t bytes)
+{
+ size_t w = 0;
Calling the return value "ret" is a useful convention and fits well here.
+ size_t longs;
+ const unsigned char *bitmap = ptr;
+
+ for (; bytes > 0 && ((unsigned long)bitmap) % sizeof(long);
+ bytes--, bitmap++)
+ w += hweight8(*bitmap);
+
+ longs = bytes / sizeof(long);
+ if (longs) {
+ BUG_ON(longs >= INT_MAX / BITS_PER_LONG);
+ w += bitmap_weight((unsigned long *)bitmap,
+ longs * BITS_PER_LONG);
+ bytes -= longs * sizeof(long);
+ bitmap += longs * sizeof(long);
+ }
+ /*
+ * The reason that this last loop is distinct from the preceding
+ * bitmap_weight() call is to compute 1-bits in the last region smaller
+ * than sizeof(long) properly on big-endian systems.
+ */
+ for (; bytes > 0; bytes--, bitmap++)
+ w += hweight8(*bitmap);
+
+ return w;
+}
+EXPORT_SYMBOL(memweight);
Is lib/string.c the right place for this? I get a build error on the
ia64 sim_defconfig:
LD arch/ia64/hp/sim/boot/bootloader
It fails because it pulls in lib/lib.a(string.o) to get some
innocuous function like strcpy() ... but it also gets
given memweight() which relies on __bitmap_weight()
which it doesn't have, because it doesn't include lib/built-in.o
(which is where bitmap.o, the definer of __bitmap_weight(), has
been linked).
Moving memweight() to lib/bitmap.c fixes the problem. But it
isn't really clear that it belongs there either. Perhaps it should
be its own file lib/memweight.c that gets included in lib/lib.a?
-Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Is lib/string.c the right place for this? I get a build error on the
ia64 sim_defconfig:
LD arch/ia64/hp/sim/boot/bootloader
It fails because it pulls in lib/lib.a(string.o) to get some
innocuous function like strcpy() ... but it also gets
given memweight() which relies on __bitmap_weight()
which it doesn't have, because it doesn't include lib/built-in.o
(which is where bitmap.o, the definer of __bitmap_weight(), has
been linked).
Moving memweight() to lib/bitmap.c fixes the problem. But it
isn't really clear that it belongs there either. Perhaps it should
be its own file lib/memweight.c that gets included in lib/lib.a?
I'll fix it by making lib/memweight.c as you suggested.
Thanks for your report and suggestion.
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html