From: Yasunori Goto <y-goto@jp.fujitsu.com>
To: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: tony.luck@intel.com, linux-ia64@vger.kernel.org,
linux-kernel@vger.kernel.org, joerg.roedel@amd.com
Subject: Re: [Q] Why does dma_alloc_coherent() of ia64 GFP_DMA?
Date: Tue, 11 Nov 2008 06:21:47 +0000 [thread overview]
Message-ID: <20081111151827.D5D3.E1E9C6FF@jp.fujitsu.com> (raw)
In-Reply-To: <20081111144212F.fujita.tomonori@lab.ntt.co.jp>
> On Mon, 10 Nov 2008 13:47:51 +0900
> Yasunori Goto <y-goto@jp.fujitsu.com> wrote:
>
> > I have a (may be dumb) question about dma_alloc_coherent() for ia64.
> >
> >
> > Why does dma_alloc_coherent() of ia64 force GFP_DMA yet?
> > And why is swiotlb_dma_alloc_coherent() default routine of
> > platform_dma_alloc_coherent()?
> >
> > -------
> > #define dma_alloc_coherent(dev, size, handle, gfp) \
> > platform_dma_alloc_coherent(dev, size, handle, (gfp) | GFP_DMA)
> > --------
> >
> > Even if a device allows over 4G access and the driver doesn't specify
> > GFP_DMA, dma_alloc_coherent() returns under 4G area.
> > I guess many people think this is not so big issue because drivers require
> > very small memory generally.
> >
> > However, I think this has the possibility of a finishing blow of OOM.
> > For example,
> >
> > 1) Page caches occupy normal zone, and DMA zone is free.
> > 2) A user's application requires a few GB memory and mlock it.
> > All DMA zone is occupied by it.
> > 3) A device which allows over 4GB is hot-added.
> > But dma_alloc_coherent() try to allocate DMA zone.
> > Then OOM occurs because there is no freeable pages.
> >
> > I heard there are some users who require a few GB mlock.
> > There are similar trouble in past.
> >
> >
> > If GFP_DMA is removed from above definition of dma_alloc_coherent(),
> > what will happen?
>
> Probably, it breaks swiotlb with devices that don't have
> DMA_64BIT_MASK coherent_dma_mask.
>
>
> > If it is not allowed, how is followings?
> >
> > dma_alloc_coherent()
> > -> platform_dma_alloc_coherent()
> > -> normal_alloc_coherent()
> > {
> > if (dma_mask allow over 4G)
> > ret = __get_free_pages();
> > :
> > (check validation of returned address)
> > :
> > else
> > swiotlb_alloc_coherent();
> > }
> > }
> >
> > If I'm something misunderstanding, please let me know.
>
> Hmm, platform_dma_alloc_coherent is supposed to handle multiple dma
> ops, swiotlb, hardware IOMMUs like VT-d and sba, etc?
>
> In IA64, the gfp zone flag matters for only swiotlb, I think.
>
>
> > From: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
> Subject: [PATCH] IA64: use GFP_DMA in dma_alloc_coherent only when necessary
>
> For swiotlb, we need to set GFP_DMA if a device doesn't have
> DMA_64BIT_MASK coherent_dma_mask. hardware IOMMUs like VT-d and sba
> should ignore gfp zone flag.
>
> diff --git a/arch/ia64/include/asm/dma-mapping.h b/arch/ia64/include/asm/dma-mapping.h
> index bbab7e2..d4de41b 100644
> --- a/arch/ia64/include/asm/dma-mapping.h
> +++ b/arch/ia64/include/asm/dma-mapping.h
> @@ -52,7 +52,9 @@ extern struct ia64_machine_vector ia64_mv;
> extern void set_iommu_machvec(void);
>
> #define dma_alloc_coherent(dev, size, handle, gfp) \
> - platform_dma_alloc_coherent(dev, size, handle, (gfp) | GFP_DMA)
> + platform_dma_alloc_coherent(dev, size, handle, \
> + (dev)->coherent_dma_mask != DMA_64BIT_MASK ? \
> + (gfp) | GFP_DMA : gfp)
>
> /* coherent mem. is cheap */
> static inline void *
Wao! Seems reasonable! Ack Ack!
Acked-by: Yasunori Goto <y-goto@jp.fujitsu.com>
Thanks a lot!
--
Yasunori Goto
prev parent reply other threads:[~2008-11-11 6:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-10 4:47 [Q] Why does dma_alloc_coherent() of ia64 GFP_DMA? Yasunori Goto
2008-11-10 12:59 ` Andi Kleen
2008-11-10 19:07 ` Robin Holt
2008-11-10 21:57 ` Christoph Lameter
2008-11-11 5:14 ` Yasunori Goto
2008-11-11 5:48 ` FUJITA Tomonori
2008-11-10 22:06 ` Christoph Lameter
2008-11-11 5:39 ` Yasunori Goto
2008-11-11 20:34 ` Christoph Lameter
2008-11-11 5:53 ` FUJITA Tomonori
2008-11-11 20:32 ` Christoph Lameter
2008-11-12 1:40 ` FUJITA Tomonori
2008-11-11 5:41 ` FUJITA Tomonori
2008-11-11 6:21 ` Yasunori Goto [this message]
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=20081111151827.D5D3.E1E9C6FF@jp.fujitsu.com \
--to=y-goto@jp.fujitsu.com \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=joerg.roedel@amd.com \
--cc=linux-ia64@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tony.luck@intel.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