From: Jens Axboe <axboe@kernel.dk>
To: linux-block@vger.kernel.org, osandov@osandov.com
Cc: Jens Axboe <axboe@kernel.dk>
Subject: [PATCH 1/3] sbitmap: ensure that sbitmap maps are properly aligned
Date: Thu, 29 Nov 2018 18:12:32 -0700 [thread overview]
Message-ID: <20181130011234.32674-2-axboe@kernel.dk> (raw)
In-Reply-To: <20181130011234.32674-1-axboe@kernel.dk>
We try to be careful with alignment for cache purposes, but all of
that is worthless if we don't actually align the maps themselves.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
include/linux/sbitmap.h | 11 ++++++++---
lib/sbitmap.c | 7 +++++--
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/include/linux/sbitmap.h b/include/linux/sbitmap.h
index 804a50983ec5..5cb1755d32da 100644
--- a/include/linux/sbitmap.h
+++ b/include/linux/sbitmap.h
@@ -63,9 +63,14 @@ struct sbitmap {
unsigned int map_nr;
/**
- * @map: Allocated bitmap.
+ * @map: Aligned allocated bitmap.
*/
struct sbitmap_word *map;
+
+ /**
+ * @map_ptr: Originally allocated map pointer
+ */
+ void *map_ptr;
};
#define SBQ_WAIT_QUEUES 8
@@ -157,8 +162,8 @@ int sbitmap_init_node(struct sbitmap *sb, unsigned int depth, int shift,
*/
static inline void sbitmap_free(struct sbitmap *sb)
{
- kfree(sb->map);
- sb->map = NULL;
+ kfree(sb->map_ptr);
+ sb->map_ptr = sb->map = NULL;
}
/**
diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index 45cab6bbc1c7..21e776e3128d 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -25,6 +25,7 @@ int sbitmap_init_node(struct sbitmap *sb, unsigned int depth, int shift,
{
unsigned int bits_per_word;
unsigned int i;
+ size_t size;
if (shift < 0) {
shift = ilog2(BITS_PER_LONG);
@@ -52,9 +53,11 @@ int sbitmap_init_node(struct sbitmap *sb, unsigned int depth, int shift,
return 0;
}
- sb->map = kcalloc_node(sb->map_nr, sizeof(*sb->map), flags, node);
- if (!sb->map)
+ size = sb->map_nr * sizeof(*sb->map) + L1_CACHE_BYTES - 1;
+ sb->map_ptr = kzalloc_node(size, flags, node);
+ if (!sb->map_ptr)
return -ENOMEM;
+ sb->map = PTR_ALIGN(sb->map_ptr, L1_CACHE_BYTES);
for (i = 0; i < sb->map_nr; i++) {
sb->map[i].depth = min(depth, bits_per_word);
--
2.17.1
next parent reply other threads:[~2018-11-30 1:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20181130011234.32674-1-axboe@kernel.dk>
2018-11-30 1:12 ` Jens Axboe [this message]
2018-11-30 1:12 ` [PATCH 2/3] sbitmap: ammortize cost of clearing bits Jens Axboe
2018-12-09 5:51 ` Guenter Roeck
2018-12-09 6:19 ` Jens Axboe
2018-11-30 1:12 ` [PATCH 3/3] sbitmap: optimize wakeup check Jens Axboe
2018-11-30 2:09 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181130011234.32674-2-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=osandov@osandov.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox