From patchwork Tue Mar 19 21:11:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 10860369 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D01414DE for ; Tue, 19 Mar 2019 21:11:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C000298C9 for ; Tue, 19 Mar 2019 21:11:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 005DA298CB; Tue, 19 Mar 2019 21:11:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B34B2298C9 for ; Tue, 19 Mar 2019 21:11:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727574AbfCSVL3 (ORCPT ); Tue, 19 Mar 2019 17:11:29 -0400 Received: from mx2.suse.de ([195.135.220.15]:41356 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726740AbfCSVL3 (ORCPT ); Tue, 19 Mar 2019 17:11:29 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9655EB606; Tue, 19 Mar 2019 21:11:27 +0000 (UTC) From: Vlastimil Babka To: linux-mm@kvack.org Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Ming Lei , Dave Chinner , Matthew Wilcox , "Darrick J . Wong" , Christoph Hellwig , Michal Hocko , linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Vlastimil Babka Subject: [RFC 2/2] mm, sl[aou]b: test whether kmalloc() alignment works as expected Date: Tue, 19 Mar 2019 22:11:08 +0100 Message-Id: <20190319211108.15495-3-vbabka@suse.cz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190319211108.15495-1-vbabka@suse.cz> References: <20190319211108.15495-1-vbabka@suse.cz> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Quick and dirty init test that kmalloc() alignment works as expected for power-of-two sizes after the previous patch. Signed-off-by: Vlastimil Babka --- mm/slab_common.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mm/slab_common.c b/mm/slab_common.c index e591d5688558..de10ca9640e0 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1621,3 +1621,22 @@ int should_failslab(struct kmem_cache *s, gfp_t gfpflags) return 0; } ALLOW_ERROR_INJECTION(should_failslab, ERRNO); + +static int __init slab_kmalloc_test(void) +{ + int i; + + for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) { + unsigned int size = 1 << i; + void * obj = kmalloc(size, GFP_KERNEL); + unsigned long objaddr = (unsigned long) obj; + + printk("Size %u obj %px alignment: %s", size, obj, + (((objaddr & (size - 1)) == 0) ? "OK" : "WRONG")); + kfree(obj); + } + + return 0; +} + +__initcall(slab_kmalloc_test);