From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5408DC38A2D for ; Wed, 26 Oct 2022 09:49:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CDE668E0003; Wed, 26 Oct 2022 05:49:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C8F7B8E0001; Wed, 26 Oct 2022 05:49:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7D828E0003; Wed, 26 Oct 2022 05:49:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id AA8A88E0001 for ; Wed, 26 Oct 2022 05:49:09 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6E9B614098C for ; Wed, 26 Oct 2022 09:49:09 +0000 (UTC) X-FDA: 80062627218.13.FA31741 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 17F4640015 for ; Wed, 26 Oct 2022 09:49:08 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4264F61C61; Wed, 26 Oct 2022 09:49:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26D3BC433D7; Wed, 26 Oct 2022 09:49:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666777747; bh=/mj9MGnrhb4BjRg3nA6I+0sJzC81p1gjL0sqLFdS7dw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eSW008dgH0Avl7yNgertPWqFjujth1wHDtlq3KnvP5giZf1V/TwjhlbGIRDvaD+rY IS3ulyRQkpq3jKW5U2wx9KJbI7b9cIfUsM0TkUZU4WmIy9/IpdQ0YTZ9ad0TJRPFiv 8EAlAsVZMC5lq4pp/Vwd2v6Kuk9H5EErkN/y9/TQ= Date: Wed, 26 Oct 2022 11:49:05 +0200 From: Greg Kroah-Hartman To: Catalin Marinas Cc: Linus Torvalds , Arnd Bergmann , Will Deacon , Marc Zyngier , Andrew Morton , Herbert Xu , Ard Biesheuvel , Christoph Hellwig , Isaac Manjarres , Saravana Kannan , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2 1/2] mm: slab: Introduce __GFP_PACKED for smaller kmalloc() alignments Message-ID: References: <20221025205247.3264568-1-catalin.marinas@arm.com> <20221025205247.3264568-2-catalin.marinas@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666777749; a=rsa-sha256; cv=none; b=SF8EAUax/ns+ylgKBJGELzmbnarfgNO2KWDV87guAxALbZP8kBwZKKCJb1fEt/NpI4p/dB TNUMUf53mEInMNY1OC/2GYHhT2NGfMT/4b8hjGw6Autl4AE/jkIPXzH3R28RyEGEay1/x6 /9btgcECtuDprfetSVY37TYPkcmyymw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=eSW008dg; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf07.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666777749; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xd2Br3INy+GkcJ7K7SUBeeVQPE9H/aj5bjk/be9ufas=; b=JYhlClLUqRZ8zg0AkUOY1NhHpqj9qtCc39aX4cEUkDH+oYVW9n2dTjvsYG/WTxEzk8+8A2 5q6/ac9jINNtYB6tpBZcdlsAy1taqwLtvO8RERx/njkaThLDZ7d36ovoV6T+6MMRzcqSOb LUsIdFfBDLyOoNUyGJxgtCt8PSEV9EQ= X-Stat-Signature: d6tmz6htpqp883pcmutsj9j7eceeexpj X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 17F4640015 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=eSW008dg; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf07.hostedemail.com: domain of gregkh@linuxfoundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org X-HE-Tag: 1666777748-279475 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Oct 26, 2022 at 09:39:32AM +0100, Catalin Marinas wrote: > On Wed, Oct 26, 2022 at 08:39:04AM +0200, Greg Kroah-Hartman wrote: > > On Tue, Oct 25, 2022 at 09:52:46PM +0100, Catalin Marinas wrote: > > > By default kmalloc() returns objects aligned to ARCH_KMALLOC_MINALIGN. > > > This can be somewhat large on architectures defining ARCH_DMA_MINALIGN > > > (e.g. 128 on arm64) and significant memory is wasted through small > > > kmalloc() allocations. > > > > > > Reduce the minimum alignment for kmalloc() to the default > > > KMALLOC_MIN_SIZE (8 for slub, 32 for slab) but align the > > > requested size to the bigger ARCH_KMALLOC_MINALIGN unless a newly added > > > __GFP_PACKED flag is passed. With this gfp flag, the alignment is > > > reduced to KMALLOC_PACKED_ALIGN, at least sizeof(unsigned long long). > > > > Can memory allocated with __GFP_PACKED be sent to DMA controllers? > > > > If not, you should say that somewhere here or I'm going to get a bunch > > of patches trying to add this flag to tiny USB urb allocations (where we > > allocate 8 or 16 bytes) that is then going to fail on some hardware. > > Good point, I'll add a comment. > > We can also add a check to the DMA API when debugging is enabled, > something like WARN_ON_ONCE(ksize(ptr) < cache_line_size()) for > non-coherent devices. It's not the size of the object that matters, it's the alignment, right? So shouldn't the check be simpler to just look at the alignment of the pointer which should be almost "free"? thanks, greg k-h