Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp487290imu; Tue, 20 Nov 2018 02:20:55 -0800 (PST) X-Google-Smtp-Source: AJdET5dW4g+SL0vUd+UkwnrzS2BUMa+ykWz1Ppw3Rt/tdcc8rkwT7mdA2MNhFm0jiH4esz6tH+UC X-Received: by 2002:a65:4142:: with SMTP id x2mr1330836pgp.356.1542709255203; Tue, 20 Nov 2018 02:20:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542709255; cv=none; d=google.com; s=arc-20160816; b=cJpsh/VXPDvxLIxPXSQwF0C+JNfyvvEbcQkqR6yyP9JnVDYvfpO3po6do+RrPT2nPX 9TIfzKf9Vyx/rG+F6uOoiocHjPiWyIuybNTF9QhbBp1Kdapu4oZERYIs4+yKEzFmXIZK KeV0n/1ATsWyeDMG2EGjbZUJsYsu2XMq6Psv5hlGdU6wd1AC2u/8zpCGKK4SoYou47J8 pexz4lrdwH897EvN7RRa+OKRPaKDloWMHm7kRFjtoMh+qtqU7zF4LugvvpMgRm/Xw+7v umbWPTjBPtpix5o50PoMGfTlLNDOUGYnaOY45/vDQkwrae+fmDi3khNzFO0tFw7vSVUF dlzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=Clr9ymURMPDH2XKr+VKRKbUysvHASI2dPyTkGrtXkcw=; b=tnUbrxSX0ZwmBmWIRhNV6pgkMm5QVHjPU00OYo2G3OIriEX5xdaULS+mNm9ARAE8Gd tbxmgaPwUVvsJ+si3SDuXNnaV4zhDb6bLiTEOk2czft+VEtgEy8Jfdb5oUvivHDUVyYg IR0KuZyVo3udRglmm0qtkSMi5S48JUeVw3leoB2fuZllGB1sI5rZYLFGxQlBxnC7Nfsu ZmF6z30cY4j4aQQ2DEZZTp6PNzW/ye8/EK9LQK3+g5Htnp91rva4PQaQ7c7z8/pXYmEg W16yKWwFBF9baAJcdQ3/hqnnQY4r0pmB/j/rk5KsRr4wNQ5aYm2cZbFot+tF5699PbSB X/1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z18si10208167plo.89.2018.11.20.02.20.39; Tue, 20 Nov 2018 02:20:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727882AbeKTUsD (ORCPT + 99 others); Tue, 20 Nov 2018 15:48:03 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:15121 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726177AbeKTUsD (ORCPT ); Tue, 20 Nov 2018 15:48:03 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id CD12DE74D375D; Tue, 20 Nov 2018 18:19:37 +0800 (CST) Received: from [127.0.0.1] (10.202.226.41) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.408.0; Tue, 20 Nov 2018 18:19:28 +0800 Subject: Re: [PATCH] iommu/dma: Use NUMA aware memory allocations in __iommu_dma_alloc_pages() To: Ganapatrao Kulkarni References: <1541699709-25474-1-git-send-email-john.garry@huawei.com> <1e2b8689-dc1f-3ede-4eeb-4a91d3a3f63f@huawei.com> CC: Joerg Roedel , Christoph Hellwig , "Marek Szyprowski" , Robin Murphy , , LKML , Linuxarm , Will Deacon , "Ganapatrao Kulkarni" From: John Garry Message-ID: Date: Tue, 20 Nov 2018 10:19:22 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.41] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20/11/2018 10:09, Ganapatrao Kulkarni wrote: > Hi John, > > On Tue, Nov 20, 2018 at 3:35 PM John Garry wrote: >> >> On 08/11/2018 17:55, John Garry wrote: >>> Change function __iommu_dma_alloc_pages() to allocate memory/pages >>> for DMA from respective device NUMA node. >>> >> >> Ping.... a friendly reminder on this patch. >> >> Thanks >> >>> Originally-from: Ganapatrao Kulkarni >>> Signed-off-by: John Garry >>> --- >>> >>> This patch was originally posted by Ganapatrao in [1] *. >>> >>> However, after initial review, it was never reposted (due to lack of >>> cycles, I think). In addition, the functionality in its sibling patches >>> were merged through patches, as mentioned in [2]; this also refers to a >>> discussion on device local allocations vs CPU local allocations for DMA >>> pool, and which is better [3]. >>> >>> However, as mentioned in [3], dma_alloc_coherent() uses the locality >>> information from the device - as in direct DMA - so this patch is just >>> applying this same policy. >>> >>> [1] https://lore.kernel.org/patchwork/patch/833004/ >>> [2] https://lkml.org/lkml/2018/8/22/391 >>> [3] https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1692998.html >>> >>> * Authorship on this updated patch may need to be fixed - I add not want to >>> add Ganapatrao's SOB without permission. > > thanks for taking this up. please feel free to add my SoB. OK, I will also make you the author and repost. Thanks, John >>> >>> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c >>> index d1b0475..ada00bc 100644 >>> --- a/drivers/iommu/dma-iommu.c >>> +++ b/drivers/iommu/dma-iommu.c >>> @@ -449,20 +449,17 @@ static void __iommu_dma_free_pages(struct page **pages, int count) >>> kvfree(pages); >>> } >>> >>> -static struct page **__iommu_dma_alloc_pages(unsigned int count, >>> - unsigned long order_mask, gfp_t gfp) >>> +static struct page **__iommu_dma_alloc_pages(struct device *dev, >>> + unsigned int count, unsigned long order_mask, gfp_t gfp) >>> { >>> struct page **pages; >>> - unsigned int i = 0, array_size = count * sizeof(*pages); >>> + unsigned int i = 0, nid = dev_to_node(dev); >>> >>> order_mask &= (2U << MAX_ORDER) - 1; >>> if (!order_mask) >>> return NULL; >>> >>> - if (array_size <= PAGE_SIZE) >>> - pages = kzalloc(array_size, GFP_KERNEL); >>> - else >>> - pages = vzalloc(array_size); >>> + pages = kvzalloc_node(count * sizeof(*pages), GFP_KERNEL, nid); >>> if (!pages) >>> return NULL; >>> >>> @@ -483,8 +480,10 @@ static struct page **__iommu_dma_alloc_pages(unsigned int count, >>> unsigned int order = __fls(order_mask); >>> >>> order_size = 1U << order; >>> - page = alloc_pages((order_mask - order_size) ? >>> - gfp | __GFP_NORETRY : gfp, order); >>> + page = alloc_pages_node(nid, >>> + (order_mask - order_size) ? >>> + gfp | __GFP_NORETRY : gfp, >>> + order); >>> if (!page) >>> continue; >>> if (!order) >>> @@ -569,7 +568,8 @@ struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp, >>> alloc_sizes = min_size; >>> >>> count = PAGE_ALIGN(size) >> PAGE_SHIFT; >>> - pages = __iommu_dma_alloc_pages(count, alloc_sizes >> PAGE_SHIFT, gfp); >>> + pages = __iommu_dma_alloc_pages(dev, count, alloc_sizes >> PAGE_SHIFT, >>> + gfp); >>> if (!pages) >>> return NULL; >>> >>> >> >> > > thanks > Ganapat > > . >