From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <tom.leiming@gmail.com>,
linux-block <linux-block@vger.kernel.org>,
linux-mm <linux-mm@kvack.org>,
Linux FS Devel <linux-fsdevel@vger.kernel.org>,
"open list\:XFS FILESYSTEM" <linux-xfs@vger.kernel.org>,
Dave Chinner <dchinner@redhat.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Jens Axboe <axboe@kernel.dk>, Ming Lei <ming.lei@redhat.com>,
Christoph Lameter <cl@linux.com>
Subject: Re: block: DMA alignment of IO buffer allocated from slab
Date: Fri, 21 Sep 2018 15:04:18 +0200 [thread overview]
Message-ID: <87h8ij0zot.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <20180920063129.GB12913@lst.de> (Christoph Hellwig's message of "Thu, 20 Sep 2018 08:31:29 +0200")
Christoph Hellwig <hch@lst.de> writes:
> On Wed, Sep 19, 2018 at 05:15:43PM +0800, Ming Lei wrote:
>> 1) does kmalloc-N slab guarantee to return N-byte aligned buffer? If
>> yes, is it a stable rule?
>
> This is the assumption in a lot of the kernel, so I think if somethings
> breaks this we are in a lot of pain.
It seems that SLUB debug breaks this assumption. Kernel built with
CONFIG_SLUB_DEBUG=y
CONFIG_SLUB=y
CONFIG_SLUB_DEBUG_ON=y
And the following patch:
diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index 3b20607d581b..56713b201921 100644
--- a/arch/x86/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
@@ -1771,3 +1771,28 @@ void __init arch_reserve_mem_area(acpi_physical_address addr, size_t size)
e820__range_add(addr, size, E820_TYPE_ACPI);
e820__update_table_print();
}
+
+#define KMALLOCS 16
+
+static __init int kmalloc_check_512(void)
+{
+ void *buf[KMALLOCS];
+ int i;
+
+ pr_info("kmalloc_check_512: start\n");
+
+ for (i = 0; i < KMALLOCS; i++) {
+ buf[i] = kmalloc(512, GFP_KERNEL);
+ }
+
+ for (i = 0; i < KMALLOCS; i++) {
+ pr_info("%lx %x\n", (unsigned long)buf[i], ((unsigned long)buf[i]) % 512);
+ kfree(buf[i]);
+ }
+
+ pr_info("kmalloc_check_512: done\n");
+
+ return 0;
+}
+
+late_initcall(kmalloc_check_512);
gives me the following output:
[ 8.417468] kmalloc_check_512: start
[ 8.429572] ffff9a3258bb09f8 1f8
[ 8.435513] ffff9a3258bb70a8 a8
[ 8.441352] ffff9a3258bb0d48 148
[ 8.447139] ffff9a3258bb6d58 158
[ 8.452864] ffff9a3258bb1098 98
[ 8.458536] ffff9a3258bb6a08 8
[ 8.464103] ffff9a3258bb13e8 1e8
[ 8.469534] ffff9a3258bb66b8 b8
[ 8.474907] ffff9a3258bb1738 138
[ 8.480214] ffff9a3258bb6368 168
[ 8.480217] ffff9a3258bb1a88 88
[ 8.496178] ffff9a3258bb6018 18
[ 8.501218] ffff9a3258bb1dd8 1d8
[ 8.506138] ffff9a3258bb5cc8 c8
[ 8.511010] ffff9a3258bb2128 128
[ 8.515795] ffff9a3258bb5978 178
[ 8.520517] kmalloc_check_512: done
(without SLUB_DEBUG_ON all addresses are 512b aligned).
--
Vitaly
next prev parent reply other threads:[~2018-09-21 13:04 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-19 9:15 block: DMA alignment of IO buffer allocated from slab Ming Lei
2018-09-19 9:41 ` Vitaly Kuznetsov
2018-09-19 10:02 ` Ming Lei
2018-09-19 11:15 ` Vitaly Kuznetsov
2018-09-20 1:28 ` Ming Lei
2018-09-20 3:59 ` Yang Shi
2018-09-20 6:32 ` Christoph Hellwig
2018-09-20 6:31 ` Christoph Hellwig
2018-09-21 13:04 ` Vitaly Kuznetsov [this message]
2018-09-21 13:05 ` Christoph Hellwig
2018-09-21 15:00 ` Jens Axboe
2018-09-24 16:06 ` Christopher Lameter
2018-09-24 17:49 ` Jens Axboe
2018-09-24 18:00 ` Christopher Lameter
2018-09-24 18:09 ` Jens Axboe
2018-09-25 7:49 ` Dave Chinner
2018-09-25 15:44 ` Jens Axboe
2018-09-25 21:04 ` Matthew Wilcox
2018-09-23 22:42 ` Ming Lei
2018-09-24 9:46 ` Andrey Ryabinin
2018-09-24 14:19 ` Bart Van Assche
2018-09-24 14:43 ` Andrey Ryabinin
2018-09-24 15:08 ` Bart Van Assche
2018-09-24 15:52 ` Andrey Ryabinin
2018-09-24 15:58 ` Bart Van Assche
2018-09-24 16:07 ` Andrey Ryabinin
2018-09-24 16:19 ` Bart Van Assche
2018-09-24 16:47 ` Christopher Lameter
2018-09-24 18:57 ` Matthew Wilcox
2018-09-24 19:56 ` Bart Van Assche
2018-09-24 20:41 ` Matthew Wilcox
2018-09-24 20:54 ` Bart Van Assche
2018-09-24 21:09 ` Matthew Wilcox
2018-09-25 0:16 ` Ming Lei
2018-09-25 3:28 ` Matthew Wilcox
2018-09-25 4:10 ` Bart Van Assche
2018-09-25 4:44 ` Matthew Wilcox
2018-09-25 6:55 ` Ming Lei
2018-09-24 15:17 ` Christopher Lameter
2018-09-25 0:20 ` Ming Lei
2018-09-20 14:07 ` Bart Van Assche
2018-09-21 1:56 ` Dave Chinner
2018-09-21 7:08 ` Christoph Hellwig
2018-09-21 7:25 ` Ming Lei
2018-09-21 14:59 ` 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=87h8ij0zot.fsf@vitty.brq.redhat.com \
--to=vkuznets@redhat.com \
--cc=axboe@kernel.dk \
--cc=cl@linux.com \
--cc=dchinner@redhat.com \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=tom.leiming@gmail.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;
as well as URLs for NNTP newsgroup(s).