From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qg0-f43.google.com (mail-qg0-f43.google.com [209.85.192.43]) by kanga.kvack.org (Postfix) with ESMTP id 0F7556B0073 for ; Tue, 4 Nov 2014 16:03:54 -0500 (EST) Received: by mail-qg0-f43.google.com with SMTP id f51so11073017qge.2 for ; Tue, 04 Nov 2014 13:03:53 -0800 (PST) Received: from mail-qg0-x235.google.com (mail-qg0-x235.google.com. [2607:f8b0:400d:c04::235]) by mx.google.com with ESMTPS id 35si2633236qgl.127.2014.11.04.13.03.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Nov 2014 13:03:53 -0800 (PST) Received: by mail-qg0-f53.google.com with SMTP id z107so11009480qgd.26 for ; Tue, 04 Nov 2014 13:03:52 -0800 (PST) MIME-Version: 1.0 From: Gregory Fong Date: Tue, 4 Nov 2014 13:03:22 -0800 Message-ID: Subject: CMA alignment question Content-Type: text/plain; charset=UTF-8 Sender: owner-linux-mm@kvack.org List-ID: To: linux-mm@kvack.org Cc: lauraa@codeaurora.org, iamjoonsoo.kim@lge.com, mina86@mina86.com, Marek Szyprowski , "linux-kernel@vger.kernel.org" , Florian Fainelli , Brian Norris Hi all, The alignment in cma_alloc() is done w.r.t. the bitmap. This is a problem when, for example: - a device requires 16M (order 12) alignment - the CMA region is not 16 M aligned In such a case, can result with the CMA region starting at, say, 0x2f800000 but any allocation you make from there will be aligned from there. Requesting an allocation of 32 M with 16 M alignment, will result in an allocation from 0x2f800000 to 0x31800000, which doesn't work very well if your strange device requires 16M alignment. This doesn't have the behavior I would expect, which would be for the allocation to be aligned w.r.t. the start of memory. I realize that aligning the CMA region is an option, but don't see why cma_alloc() aligns to the start of the CMA region. Is there a good reason for having cma_alloc() alignment work this way? Thanks and regards, Gregory -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com [209.85.217.173]) by kanga.kvack.org (Postfix) with ESMTP id 8362D6B00BC for ; Tue, 4 Nov 2014 17:27:34 -0500 (EST) Received: by mail-lb0-f173.google.com with SMTP id n15so1781353lbi.32 for ; Tue, 04 Nov 2014 14:27:33 -0800 (PST) Received: from mail-la0-x231.google.com (mail-la0-x231.google.com. [2a00:1450:4010:c03::231]) by mx.google.com with ESMTPS id oc10si2829585lbb.99.2014.11.04.14.27.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Nov 2014 14:27:33 -0800 (PST) Received: by mail-la0-f49.google.com with SMTP id ge10so1715048lab.22 for ; Tue, 04 Nov 2014 14:27:32 -0800 (PST) From: Michal Nazarewicz Subject: Re: CMA alignment question In-Reply-To: References: Date: Tue, 04 Nov 2014 23:27:28 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: owner-linux-mm@kvack.org List-ID: To: Gregory Fong , linux-mm@kvack.org Cc: lauraa@codeaurora.org, iamjoonsoo.kim@lge.com, Marek Szyprowski , "linux-kernel@vger.kernel.org" , Florian Fainelli , Brian Norris On Tue, Nov 04 2014, Gregory Fong wrote: > The alignment in cma_alloc() is done w.r.t. the bitmap. This is a > problem when, for example: > > - a device requires 16M (order 12) alignment > - the CMA region is not 16 M aligned > > In such a case, can result with the CMA region starting at, say, > 0x2f800000 but any allocation you make from there will be aligned from > there. Requesting an allocation of 32 M with 16 M alignment, will > result in an allocation from 0x2f800000 to 0x31800000, which doesn't > work very well if your strange device requires 16M alignment. > > This doesn't have the behavior I would expect, which would be for the > allocation to be aligned w.r.t. the start of memory. I realize that > aligning the CMA region is an option, but don't see why cma_alloc() > aligns to the start of the CMA region. Is there a good reason for > having cma_alloc() alignment work this way? No, it's a bug. The alignment should indicate alignment of physical address not position in CMA region. --=20 Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=3D./ `o ..o | Computer Science, Micha=C5=82 =E2=80=9Cmina86=E2=80=9D Nazarewicz = (o o) ooo +------ooO--(_)--Ooo-- -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qg0-f48.google.com (mail-qg0-f48.google.com [209.85.192.48]) by kanga.kvack.org (Postfix) with ESMTP id D4A686B00AF for ; Tue, 4 Nov 2014 23:19:29 -0500 (EST) Received: by mail-qg0-f48.google.com with SMTP id q108so11724681qgd.35 for ; Tue, 04 Nov 2014 20:19:29 -0800 (PST) Received: from mail-qc0-x22d.google.com (mail-qc0-x22d.google.com. [2607:f8b0:400d:c01::22d]) by mx.google.com with ESMTPS id l9si4252572qae.53.2014.11.04.20.19.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Nov 2014 20:19:29 -0800 (PST) Received: by mail-qc0-f173.google.com with SMTP id x3so12109031qcv.18 for ; Tue, 04 Nov 2014 20:19:28 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: From: Gregory Fong Date: Tue, 4 Nov 2014 20:18:58 -0800 Message-ID: Subject: Re: CMA alignment question Content-Type: text/plain; charset=UTF-8 Sender: owner-linux-mm@kvack.org List-ID: To: Michal Nazarewicz Cc: linux-mm@kvack.org, Laura Abbott , iamjoonsoo.kim@lge.com, Marek Szyprowski , "linux-kernel@vger.kernel.org" , Florian Fainelli , Brian Norris On Tue, Nov 4, 2014 at 2:27 PM, Michal Nazarewicz wrote: > On Tue, Nov 04 2014, Gregory Fong wrote: >> The alignment in cma_alloc() is done w.r.t. the bitmap. This is a >> problem when, for example: >> >> - a device requires 16M (order 12) alignment >> - the CMA region is not 16 M aligned >> >> In such a case, can result with the CMA region starting at, say, >> 0x2f800000 but any allocation you make from there will be aligned from >> there. Requesting an allocation of 32 M with 16 M alignment, will >> result in an allocation from 0x2f800000 to 0x31800000, which doesn't >> work very well if your strange device requires 16M alignment. >> >> This doesn't have the behavior I would expect, which would be for the >> allocation to be aligned w.r.t. the start of memory. I realize that >> aligning the CMA region is an option, but don't see why cma_alloc() >> aligns to the start of the CMA region. Is there a good reason for >> having cma_alloc() alignment work this way? > > No, it's a bug. The alignment should indicate alignment of physical > address not position in CMA region. > Ah, now I see that Marek submitted this patch from you back in 2011 that would have allowed the bitmap lib to support an alignment offset: http://thread.gmane.org/gmane.linux.kernel/1121103/focus=1121100 Any idea why this didn't make it into the later changesets? If not, I'll resubmit it and to use it to fix this bug. Thanks, Gregory -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ie0-f182.google.com (mail-ie0-f182.google.com [209.85.223.182]) by kanga.kvack.org (Postfix) with ESMTP id A679D6B0083 for ; Wed, 5 Nov 2014 02:20:09 -0500 (EST) Received: by mail-ie0-f182.google.com with SMTP id rd18so134799iec.41 for ; Tue, 04 Nov 2014 23:20:09 -0800 (PST) Received: from mail-ie0-x22e.google.com (mail-ie0-x22e.google.com. [2607:f8b0:4001:c03::22e]) by mx.google.com with ESMTPS id ii1si4318629igb.19.2014.11.04.23.20.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Nov 2014 23:20:08 -0800 (PST) Received: by mail-ie0-f174.google.com with SMTP id x19so149473ier.5 for ; Tue, 04 Nov 2014 23:20:08 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: Date: Wed, 5 Nov 2014 15:20:07 +0800 Message-ID: Subject: Re: CMA alignment question From: Weijie Yang Content-Type: text/plain; charset=UTF-8 Sender: owner-linux-mm@kvack.org List-ID: To: Gregory Fong Cc: Michal Nazarewicz , linux-mm@kvack.org, Laura Abbott , iamjoonsoo.kim@lge.com, Marek Szyprowski , "linux-kernel@vger.kernel.org" , Florian Fainelli , Brian Norris On Wed, Nov 5, 2014 at 12:18 PM, Gregory Fong wrote: > On Tue, Nov 4, 2014 at 2:27 PM, Michal Nazarewicz wrote: >> On Tue, Nov 04 2014, Gregory Fong wrote: >>> The alignment in cma_alloc() is done w.r.t. the bitmap. This is a >>> problem when, for example: >>> >>> - a device requires 16M (order 12) alignment >>> - the CMA region is not 16 M aligned I think the device driver should ensure that situation could not occur, by assign suitable alignment parameter in cma_declare_contiguous(). >>> In such a case, can result with the CMA region starting at, say, >>> 0x2f800000 but any allocation you make from there will be aligned from >>> there. Requesting an allocation of 32 M with 16 M alignment, will >>> result in an allocation from 0x2f800000 to 0x31800000, which doesn't >>> work very well if your strange device requires 16M alignment. >>> >>> This doesn't have the behavior I would expect, which would be for the >>> allocation to be aligned w.r.t. the start of memory. I realize that >>> aligning the CMA region is an option, but don't see why cma_alloc() >>> aligns to the start of the CMA region. Is there a good reason for >>> having cma_alloc() alignment work this way? >> >> No, it's a bug. The alignment should indicate alignment of physical >> address not position in CMA region. >> > > Ah, now I see that Marek submitted this patch from you back in 2011 > that would have allowed the bitmap lib to support an alignment offset: > http://thread.gmane.org/gmane.linux.kernel/1121103/focus=1121100 > > Any idea why this didn't make it into the later changesets? If not, > I'll resubmit it and to use it to fix this bug. > > Thanks, > Gregory > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-la0-f47.google.com (mail-la0-f47.google.com [209.85.215.47]) by kanga.kvack.org (Postfix) with ESMTP id 19E436B0075 for ; Wed, 5 Nov 2014 17:01:53 -0500 (EST) Received: by mail-la0-f47.google.com with SMTP id gd6so1526396lab.6 for ; Wed, 05 Nov 2014 14:01:52 -0800 (PST) Received: from mail-la0-x229.google.com (mail-la0-x229.google.com. [2a00:1450:4010:c03::229]) by mx.google.com with ESMTPS id um10si8346694lbb.117.2014.11.05.14.01.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 05 Nov 2014 14:01:52 -0800 (PST) Received: by mail-la0-f41.google.com with SMTP id s18so1548132lam.28 for ; Wed, 05 Nov 2014 14:01:51 -0800 (PST) From: Michal Nazarewicz Subject: Re: CMA alignment question In-Reply-To: References: Date: Wed, 05 Nov 2014 23:01:48 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: owner-linux-mm@kvack.org List-ID: To: Weijie Yang , Gregory Fong Cc: linux-mm@kvack.org, Laura Abbott , iamjoonsoo.kim@lge.com, Marek Szyprowski , "linux-kernel@vger.kernel.org" , Florian Fainelli , Brian Norris > On Tue, Nov 04 2014, Gregory Fong wrote: >> The alignment in cma_alloc() is done w.r.t. the bitmap. This is a >> problem when, for example: >> >> - a device requires 16M (order 12) alignment >> - the CMA region is not 16 M aligned On Wed, Nov 05 2014, Weijie Yang wrote: > I think the device driver should ensure that situation could not occur, > by assign suitable alignment parameter in cma_declare_contiguous(). What about default CMA area? Besides, I think principle of least surprise applies here and alignment should be physical. --=20 Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=3D./ `o ..o | Computer Science, Micha=C5=82 =E2=80=9Cmina86=E2=80=9D Nazarewicz = (o o) ooo +------ooO--(_)--Ooo-- -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ie0-f176.google.com (mail-ie0-f176.google.com [209.85.223.176]) by kanga.kvack.org (Postfix) with ESMTP id D306E6B0071 for ; Wed, 5 Nov 2014 20:00:34 -0500 (EST) Received: by mail-ie0-f176.google.com with SMTP id rd18so1988182iec.35 for ; Wed, 05 Nov 2014 17:00:34 -0800 (PST) Received: from mail-ig0-x22d.google.com (mail-ig0-x22d.google.com. [2607:f8b0:4001:c05::22d]) by mx.google.com with ESMTPS id o8si7548206ioe.0.2014.11.05.17.00.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 05 Nov 2014 17:00:33 -0800 (PST) Received: by mail-ig0-f173.google.com with SMTP id r10so9862874igi.12 for ; Wed, 05 Nov 2014 17:00:33 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: Date: Thu, 6 Nov 2014 09:00:33 +0800 Message-ID: Subject: Re: CMA alignment question From: Weijie Yang Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: owner-linux-mm@kvack.org List-ID: To: Michal Nazarewicz Cc: Gregory Fong , linux-mm@kvack.org, Laura Abbott , iamjoonsoo.kim@lge.com, Marek Szyprowski , "linux-kernel@vger.kernel.org" , Florian Fainelli , Brian Norris On Thu, Nov 6, 2014 at 6:01 AM, Michal Nazarewicz wrote= : >> On Tue, Nov 04 2014, Gregory Fong wrote: >>> The alignment in cma_alloc() is done w.r.t. the bitmap. This is a >>> problem when, for example: >>> >>> - a device requires 16M (order 12) alignment >>> - the CMA region is not 16 M aligned > > On Wed, Nov 05 2014, Weijie Yang wrote: >> I think the device driver should ensure that situation could not occur, >> by assign suitable alignment parameter in cma_declare_contiguous(). > > What about default CMA area? Besides, I think principle of least > surprise applies here and alignment should be physical. I agree the current code doesn't handle this issue properly. However, I prefer to add specific usage to CMA interface rather than modify the cma code, Because the latter hide the issue and could waste memory. > -- > Best regards, _ _ > .o. | Liege of Serenely Enlightened Majesty of o' \,=3D./ `o > ..o | Computer Science, Micha=C5=82 =E2=80=9Cmina86=E2=80=9D Nazarewicz = (o o) > ooo +------ooO--(_)--Ooo-- -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com [209.85.212.180]) by kanga.kvack.org (Postfix) with ESMTP id E4FBD900015 for ; Thu, 6 Nov 2014 07:29:47 -0500 (EST) Received: by mail-wi0-f180.google.com with SMTP id hi2so1324737wib.1 for ; Thu, 06 Nov 2014 04:29:47 -0800 (PST) Received: from mail-wi0-x22e.google.com (mail-wi0-x22e.google.com. [2a00:1450:400c:c05::22e]) by mx.google.com with ESMTPS id s7si9653360wix.49.2014.11.06.04.29.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Nov 2014 04:29:46 -0800 (PST) Received: by mail-wi0-f174.google.com with SMTP id d1so1322627wiv.1 for ; Thu, 06 Nov 2014 04:29:46 -0800 (PST) From: Michal Nazarewicz Subject: Re: CMA alignment question In-Reply-To: References: Date: Thu, 06 Nov 2014 13:29:42 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: owner-linux-mm@kvack.org List-ID: To: Weijie Yang Cc: Gregory Fong , linux-mm@kvack.org, Laura Abbott , iamjoonsoo.kim@lge.com, Marek Szyprowski , "linux-kernel@vger.kernel.org" , Florian Fainelli , Brian Norris On Thu, Nov 06 2014, Weijie Yang wrote: > I agree the current code doesn't handle this issue properly. > However, I prefer to add specific usage to CMA interface rather than > modify the cma code, Because the latter hide the issue and could waste > memory. cma_alloc should handle whatever alignment caller uses. Sure, if CMA area has smaller alignment this may lead to wasted memory, but so can allocation with small alignment followed by allocation with big alignment. If you're saying that platform should try to get the CMA area aligned such that no alignment offset happens I agree. If you're saying that cma_alloc should fail (to properly align) an allocation request, I disagree. --=20 Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=3D./ `o ..o | Computer Science, Micha=C5=82 =E2=80=9Cmina86=E2=80=9D Nazarewicz = (o o) ooo +------ooO--(_)--Ooo-- -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org