From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx148.postini.com [74.125.245.148]) by kanga.kvack.org (Postfix) with SMTP id 725288D0001 for ; Fri, 11 May 2012 09:27:55 -0400 (EDT) Received: from euspt2 (mailout1.w1.samsung.com [210.118.77.11]) by mailout1.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTP id <0M3V008L91B6HG@mailout1.w1.samsung.com> for linux-mm@kvack.org; Fri, 11 May 2012 14:25:54 +0100 (BST) Received: from linux.samsung.com ([106.116.38.10]) by spt2.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0M3V00JCZ1EEC8@spt2.w1.samsung.com> for linux-mm@kvack.org; Fri, 11 May 2012 14:27:50 +0100 (BST) Date: Fri, 11 May 2012 15:27:49 +0200 From: Marek Szyprowski Subject: RE: how to avoid allocating or freeze MOVABLE memory in userspace In-reply-to: Message-id: <035501cd2f79$dbfde410$93f9ac30$%szyprowski@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-language: pl Content-transfer-encoding: 7BIT References: Sender: owner-linux-mm@kvack.org List-ID: To: 'Haojian Zhuang' , 'Christoph Lameter' Cc: linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org Hello, On Wednesday, April 18, 2012 9:37 AM Haojian Zhuang wrote: > On Mon, Apr 16, 2012 at 9:55 PM, Christoph Lameter wrote: > > On Sat, 14 Apr 2012, Haojian Zhuang wrote: > > > >> On Sat, Apr 14, 2012 at 2:27 AM, Christoph Lameter wrote: > >> > On Fri, 13 Apr 2012, Haojian Zhuang wrote: > >> > > >> >> I have one question on memory migration. As we know, malloc() from > >> >> user app will allocate MIGRATE_MOVABLE pages. But if we want to use > >> >> this memory as DMA usage, we can't accept MIGRATE_MOVABLE type. Could > >> >> we change its behavior before DMA working? > >> > > >> > MIGRATE_MOVABLE works fine for DMA. If you keep a reference from a device > >> > driver to user pages then you will have to increase the page refcount > >> > which will in turn pin the page and make it non movable for as long as you > >> > keep the refcount. > >> > >> Hi Christoph, > >> > >> Thanks for your illustration. But it's a little abstract. Could you > >> give me a simple example > >> or show me the code? > > > > Run get_user_pages() on the memory you are interest in pinning. See how > > other drivers do that by looking up other use cases. F.e. ib_umem_get() > > does a similar thing. > > > > > Got it. And I think there's conflict in CMA. > > For example, user process A malloc() memory, page->_count is 1. After > using get_user_pages() > in device driver for DMA usage, page->_count becomes 2. > > If the page is in CMA region, it results migrate_pages() returns > -EAGAIN. But error handling in CMA is in below. > > ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA); > if (ret == 0) { > bitmap_set(cma->bitmap, pageno, count); > break; > } else if (ret != -EBUSY) { > goto error; > } > > Since EAGAIN doesn't equal to EBUSY, dma_alloc_from_contiguous() > aborts. Should dma_alloc_from_contiguous() handle EAGAIN? > I've checked again and it is really not possible for migrate_pages() to return -EAGAIN, so the CMA code is correct. The only special case which needs retry is -EBUSY. Best regards -- Marek Szyprowski Samsung Poland R&D Center -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: email@kvack.org