From mboxrd@z Thu Jan 1 00:00:00 1970 From: mina86@mina86.com (Michal Nazarewicz) Date: Fri, 19 Feb 2016 14:46:08 +0100 Subject: [PATCH 1/2] mm: cma: split out in_cma check to separate function In-Reply-To: <1455869524-13874-1-git-send-email-rabin.vincent@axis.com> References: <1455869524-13874-1-git-send-email-rabin.vincent@axis.com> Message-ID: To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Fri, Feb 19 2016, Rabin Vincent wrote: > Split out the logic in cma_release() which checks if the page is in the > contiguous area to a new function which can be called separately. ARM > will use this. > > Signed-off-by: Rabin Vincent > --- > include/linux/cma.h | 12 ++++++++++++ > mm/cma.c | 27 +++++++++++++++++++-------- > 2 files changed, 31 insertions(+), 8 deletions(-) > > diff --git a/include/linux/cma.h b/include/linux/cma.h > index 29f9e77..6e7fd2d 100644 > --- a/include/linux/cma.h > +++ b/include/linux/cma.h > @@ -27,5 +27,17 @@ extern int cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, > unsigned int order_per_bit, > struct cma **res_cma); > extern struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align); > + > extern bool cma_release(struct cma *cma, const struct page *pages, unsigned int count); > +#ifdef CONFIG_CMA > +extern bool in_cma(struct cma *cma, const struct page *pages, > + unsigned int count); > +#else > +static inline bool in_cma(struct cma *cma, const struct page *pages, > + unsigned int count) > +{ > + return false; > +} > +#endif > + > #endif > diff --git a/mm/cma.c b/mm/cma.c > index ea506eb..55cda16 100644 > --- a/mm/cma.c > +++ b/mm/cma.c > @@ -426,6 +426,23 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align) > return page; > } > > +bool in_cma(struct cma *cma, const struct page *pages, unsigned int count) Should it instead take pfn as an argument instead of a page? IIRC page_to_pfn may be expensive on some architectures and with this patch, cma_release will call it twice. Or maybe in_cma could return a pfn, something like (error checking stripped): unsigned long pfn in_cma(struct cma *cma, const struct page *page, unsgined count) { unsigned long pfn = page_to_pfn(page); if (pfn < cma->base_pfn || pfn >= cma->base_pfn + cma->count) return 0; VM_BUG_ON(pfn + count > cma->base_pfn + cma->count); return pfn; } Is pfn == 0 guaranteed to be invalid? > +{ > + unsigned long pfn; > + > + if (!cma || !pages) > + return false; > + > + pfn = page_to_pfn(pages); > + > + if (pfn < cma->base_pfn || pfn >= cma->base_pfn + cma->count) > + return false; > + > + VM_BUG_ON(pfn + count > cma->base_pfn + cma->count); > + > + return true; > +} > + > /** > * cma_release() - release allocated pages > * @cma: Contiguous memory region for which the allocation is performed. > @@ -440,18 +457,12 @@ bool cma_release(struct cma *cma, const struct page *pages, unsigned int count) > { > unsigned long pfn; > > - if (!cma || !pages) > - return false; > - > pr_debug("%s(page %p)\n", __func__, (void *)pages); > > - pfn = page_to_pfn(pages); > - > - if (pfn < cma->base_pfn || pfn >= cma->base_pfn + cma->count) > + if (!in_cma(cma, pages, count)) > return false; > > - VM_BUG_ON(pfn + count > cma->base_pfn + cma->count); > - > + pfn = page_to_pfn(pages); > free_contig_range(pfn, count); > cma_clear_bitmap(cma, pfn, count); > trace_cma_release(pfn, pages, count); > -- > 2.7.0 > -- Best regards Liege of Serenely Enlightened Majesty of Computer Science, ??? ?mina86? ?????? From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by kanga.kvack.org (Postfix) with ESMTP id C6EFD6B0005 for ; Fri, 19 Feb 2016 08:46:12 -0500 (EST) Received: by mail-wm0-f43.google.com with SMTP id g62so71716861wme.0 for ; Fri, 19 Feb 2016 05:46:12 -0800 (PST) Received: from mail-wm0-x231.google.com (mail-wm0-x231.google.com. [2a00:1450:400c:c09::231]) by mx.google.com with ESMTPS id es11si17961734wjb.139.2016.02.19.05.46.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Feb 2016 05:46:10 -0800 (PST) Received: by mail-wm0-x231.google.com with SMTP id a4so71411376wme.1 for ; Fri, 19 Feb 2016 05:46:10 -0800 (PST) From: Michal Nazarewicz Subject: Re: [PATCH 1/2] mm: cma: split out in_cma check to separate function In-Reply-To: <1455869524-13874-1-git-send-email-rabin.vincent@axis.com> References: <1455869524-13874-1-git-send-email-rabin.vincent@axis.com> Date: Fri, 19 Feb 2016 14:46:08 +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: Rabin Vincent , linux@arm.linux.org.uk Cc: akpm@linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Rabin Vincent On Fri, Feb 19 2016, Rabin Vincent wrote: > Split out the logic in cma_release() which checks if the page is in the > contiguous area to a new function which can be called separately. ARM > will use this. > > Signed-off-by: Rabin Vincent > --- > include/linux/cma.h | 12 ++++++++++++ > mm/cma.c | 27 +++++++++++++++++++-------- > 2 files changed, 31 insertions(+), 8 deletions(-) > > diff --git a/include/linux/cma.h b/include/linux/cma.h > index 29f9e77..6e7fd2d 100644 > --- a/include/linux/cma.h > +++ b/include/linux/cma.h > @@ -27,5 +27,17 @@ extern int cma_init_reserved_mem(phys_addr_t base, phy= s_addr_t size, > unsigned int order_per_bit, > struct cma **res_cma); > extern struct page *cma_alloc(struct cma *cma, size_t count, unsigned in= t align); > + > extern bool cma_release(struct cma *cma, const struct page *pages, unsig= ned int count); > +#ifdef CONFIG_CMA > +extern bool in_cma(struct cma *cma, const struct page *pages, > + unsigned int count); > +#else > +static inline bool in_cma(struct cma *cma, const struct page *pages, > + unsigned int count) > +{ > + return false; > +} > +#endif > + > #endif > diff --git a/mm/cma.c b/mm/cma.c > index ea506eb..55cda16 100644 > --- a/mm/cma.c > +++ b/mm/cma.c > @@ -426,6 +426,23 @@ struct page *cma_alloc(struct cma *cma, size_t count= , unsigned int align) > return page; > } >=20=20 > +bool in_cma(struct cma *cma, const struct page *pages, unsigned int coun= t) Should it instead take pfn as an argument instead of a page? IIRC page_to_pfn may be expensive on some architectures and with this patch, cma_release will call it twice. Or maybe in_cma could return a pfn, something like (error checking stripped): unsigned long pfn in_cma(struct cma *cma, const struct page *page, unsgined count) { unsigned long pfn =3D page_to_pfn(page); if (pfn < cma->base_pfn || pfn >=3D cma->base_pfn + cma->count) return 0; VM_BUG_ON(pfn + count > cma->base_pfn + cma->count); return pfn; } Is pfn =3D=3D 0 guaranteed to be invalid? > +{ > + unsigned long pfn; > + > + if (!cma || !pages) > + return false; > + > + pfn =3D page_to_pfn(pages); > + > + if (pfn < cma->base_pfn || pfn >=3D cma->base_pfn + cma->count) > + return false; > + > + VM_BUG_ON(pfn + count > cma->base_pfn + cma->count); > + > + return true; > +} > + > /** > * cma_release() - release allocated pages > * @cma: Contiguous memory region for which the allocation is performe= d. > @@ -440,18 +457,12 @@ bool cma_release(struct cma *cma, const struct page= *pages, unsigned int count) > { > unsigned long pfn; >=20=20 > - if (!cma || !pages) > - return false; > - > pr_debug("%s(page %p)\n", __func__, (void *)pages); >=20=20 > - pfn =3D page_to_pfn(pages); > - > - if (pfn < cma->base_pfn || pfn >=3D cma->base_pfn + cma->count) > + if (!in_cma(cma, pages, count)) > return false; >=20=20 > - VM_BUG_ON(pfn + count > cma->base_pfn + cma->count); > - > + pfn =3D page_to_pfn(pages); > free_contig_range(pfn, count); > cma_clear_bitmap(cma, pfn, count); > trace_cma_release(pfn, pages, count); > --=20 > 2.7.0 > --=20 Best regards Liege of Serenely Enlightened Majesty of Computer Science, =E3=83=9F=E3=83=8F=E3=82=A6 =E2=80=9Cmina86=E2=80=9D =E3=83=8A=E3=82=B6=E3= =83=AC=E3=83=B4=E3=82=A4=E3=83=84 -- 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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1426703AbcBSNqo (ORCPT ); Fri, 19 Feb 2016 08:46:44 -0500 Received: from mail-wm0-f53.google.com ([74.125.82.53]:35484 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423502AbcBSNqL convert rfc822-to-8bit (ORCPT ); Fri, 19 Feb 2016 08:46:11 -0500 From: Michal Nazarewicz To: Rabin Vincent , linux@arm.linux.org.uk Cc: akpm@linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Rabin Vincent Subject: Re: [PATCH 1/2] mm: cma: split out in_cma check to separate function In-Reply-To: <1455869524-13874-1-git-send-email-rabin.vincent@axis.com> Organization: http://mina86.com/ References: <1455869524-13874-1-git-send-email-rabin.vincent@axis.com> User-Agent: Notmuch/0.19+53~g2e63a09 (http://notmuchmail.org) Emacs/25.1.50.1 (x86_64-unknown-linux-gnu) Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACP0lEQVQ4T23Sv2vbQBQHcBk1xE6WyALX107VUEgmn6+ouUwpEQQ6uRjttkWP4CkBg2M0BQLBdPFZYPsyFYo7qEtKDQ7on+t7+nF2Ux8ahD587717OmNYrOvycHsZ+o2r051wHTHysAvGb8ygvgu4QWT0sCmkgZCIEnlV2X8BtyraazFGDuxhmKSQJMlwHQ7v5MHSNxmz78rfElwAa3ieVD9e+hBhjaPDDG6NgFo2f4wBMNIo5YmRtF0RyDgFjJjlMIWbnuM4x9MMfABGTlN4qgIQB4A1DEyA1BHWtfeWNUMwiVJKoqh97KrkOO+qzgluVYLvFCUKAX73nONeBr7BGMdM6Sg0kuep03VywLaIzRiVr+GAzKlpQIsAFnWAG2e6DT5WmWDiudZMIc6hYrMOmeMQK9WX0B+/RfjzL9DI7Y9/Iayn29Ci0r2i4f9gMimMSZLCDMalgQGU5hnUtqAN0OGvEmO1Wnl0C0wWSCEHnuHBqmygxdxA8oWXwbipoc1EoNR9DqOpBpOJrnr0criQab9ZT4LL+wI+K7GBQH30CrhUruilgP9DRTrhVWZCiAyILP+wiuLeCKGTD6r/nc8LOJcAwR6IBTUs+7CASw3QFZ0MdA2PI3zNziH4ZKVhXCRMBjeZ1DWMekKwDCASwExy+NQ86TaykaDAFHO4aP48y4fIcDM5yOG8GcTLbOyp8A8azjJI93JFd1EA6yN8sSxMQJWoABqniRZVykYgRXErzrdqExAoUrRb0xfRp8p2A/4XmfilTtkDZ4cAAAAASUVORK5CYII= X-Face: -TR8(rDTHy/(xl?SfWd1|3:TTgDIatE^t'vop%*gVg[kn$t{EpK(P"VQ=~T2#ysNmJKN$"yTRLB4YQs$4{[.]Fc1)*O]3+XO^oXM>Q#b^ix,O)Zbn)q[y06$`e3?C)`CwR9y5riE=fv^X@x$y?D:XO6L&x4f-}}I4=VRNwiA^t1-ZrVK^07.Pi/57c_du'& X-PGP: 50751FF4 X-PGP-FP: AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 X-Hashcash: 1:20:160219:linux-mm@kvack.org::Gure0oJ6dGySyv2L:00000000000000000000000000000000000000000000Uwg X-Hashcash: 1:20:160219:linux@arm.linux.org.uk::d3CwwNoYDUbrFA8+:000000000000000000000000000000000000000084Z X-Hashcash: 1:20:160219:linux-arm-kernel@lists.infradead.org::2qKKYxOAXJ0aeAyy:00000000000000000000000002L9U X-Hashcash: 1:20:160219:akpm@linux-foundation.org::1foqG39JwwasS77H:0000000000000000000000000000000000000mQ4 X-Hashcash: 1:20:160219:linux-kernel@vger.kernel.org::B9ZGiAYeWJpJJwN0:0000000000000000000000000000000003YWv X-Hashcash: 1:20:160219:rabin.vincent@axis.com::Yx1huhQ4TRS0NNKa:0000000000000000000000000000000000000003TQ2 X-Hashcash: 1:20:160219:rabinv@axis.com::RCt/cKdoVzrpdhJI:00Dta4 Date: Fri, 19 Feb 2016 14:46:08 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 19 2016, Rabin Vincent wrote: > Split out the logic in cma_release() which checks if the page is in the > contiguous area to a new function which can be called separately. ARM > will use this. > > Signed-off-by: Rabin Vincent > --- > include/linux/cma.h | 12 ++++++++++++ > mm/cma.c | 27 +++++++++++++++++++-------- > 2 files changed, 31 insertions(+), 8 deletions(-) > > diff --git a/include/linux/cma.h b/include/linux/cma.h > index 29f9e77..6e7fd2d 100644 > --- a/include/linux/cma.h > +++ b/include/linux/cma.h > @@ -27,5 +27,17 @@ extern int cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, > unsigned int order_per_bit, > struct cma **res_cma); > extern struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align); > + > extern bool cma_release(struct cma *cma, const struct page *pages, unsigned int count); > +#ifdef CONFIG_CMA > +extern bool in_cma(struct cma *cma, const struct page *pages, > + unsigned int count); > +#else > +static inline bool in_cma(struct cma *cma, const struct page *pages, > + unsigned int count) > +{ > + return false; > +} > +#endif > + > #endif > diff --git a/mm/cma.c b/mm/cma.c > index ea506eb..55cda16 100644 > --- a/mm/cma.c > +++ b/mm/cma.c > @@ -426,6 +426,23 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align) > return page; > } > > +bool in_cma(struct cma *cma, const struct page *pages, unsigned int count) Should it instead take pfn as an argument instead of a page? IIRC page_to_pfn may be expensive on some architectures and with this patch, cma_release will call it twice. Or maybe in_cma could return a pfn, something like (error checking stripped): unsigned long pfn in_cma(struct cma *cma, const struct page *page, unsgined count) { unsigned long pfn = page_to_pfn(page); if (pfn < cma->base_pfn || pfn >= cma->base_pfn + cma->count) return 0; VM_BUG_ON(pfn + count > cma->base_pfn + cma->count); return pfn; } Is pfn == 0 guaranteed to be invalid? > +{ > + unsigned long pfn; > + > + if (!cma || !pages) > + return false; > + > + pfn = page_to_pfn(pages); > + > + if (pfn < cma->base_pfn || pfn >= cma->base_pfn + cma->count) > + return false; > + > + VM_BUG_ON(pfn + count > cma->base_pfn + cma->count); > + > + return true; > +} > + > /** > * cma_release() - release allocated pages > * @cma: Contiguous memory region for which the allocation is performed. > @@ -440,18 +457,12 @@ bool cma_release(struct cma *cma, const struct page *pages, unsigned int count) > { > unsigned long pfn; > > - if (!cma || !pages) > - return false; > - > pr_debug("%s(page %p)\n", __func__, (void *)pages); > > - pfn = page_to_pfn(pages); > - > - if (pfn < cma->base_pfn || pfn >= cma->base_pfn + cma->count) > + if (!in_cma(cma, pages, count)) > return false; > > - VM_BUG_ON(pfn + count > cma->base_pfn + cma->count); > - > + pfn = page_to_pfn(pages); > free_contig_range(pfn, count); > cma_clear_bitmap(cma, pfn, count); > trace_cma_release(pfn, pages, count); > -- > 2.7.0 > -- Best regards Liege of Serenely Enlightened Majesty of Computer Science, ミハウ “mina86” ナザレヴイツ