Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp478068imu; Tue, 20 Nov 2018 02:10:42 -0800 (PST) X-Google-Smtp-Source: AFSGD/X1rgTsUxdDYrnsM/Mkj3X7M8PRSOdVdU9tH7szUEu4PqKAUECGmFdFPd3b0Iky+fFiWpQB X-Received: by 2002:a63:fd0a:: with SMTP id d10mr1380744pgh.164.1542708642381; Tue, 20 Nov 2018 02:10:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542708642; cv=none; d=google.com; s=arc-20160816; b=K++DoDvFbV06EGSOHd0PMTngmp+F9jB1VVgeHjTv1aQQyST90/NGa2ia7IEIKQpPPt +OcVnyFCFPQecKSO1eIFHQlLp3bHI4BPS5SojEVAGztHJNAFqU69B4XciMsHA0gA2jL3 W6xDZlVjiBqNrjGoEIcMysQptjfya4+fetDsK3teVFeTi24bUfIUQYID0QI6NyYD8FNW H8SFxY8QGZ9qSrhXP9+AophD+mmvxU2rOZEULIKPCpkSi/8Uv3biI1CsdQHLKWK1I3Gm +vcfnfgZHrun3EqpZmauAHXtxk74nIu6KuI8kBegC7CYB/GJwfWP4FV1mO3mUIgdZtQk cJHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=MuTXG+7hWhellvogEp5h0I0J+YO+uaVkNlq69jSlRMg=; b=PxbNUFX23AKxAavnbXKvrd+lDXKiSQqtxW0+sJo0UR7+THyGeKZs5adWOy5SqS72po 5b/z5p4pebPHdM9QEs55vWLxcuGwfhuThAHdF7vaSchj6GEbIxgLzaN82f5h5oNBWo2y iPunBQ7WKC4vGNYc08oEpiPvPB+OZJQXOdonIRP4TvJ66Z/+FrWNORxBKzVeaEpDhd7q /N6PLjSReVfAeqDf5CmaB/o3wN10nwrI2ygy0+6/PJVxUfDE8ZOayqBlAHCPm7wPbxJ3 fG+qQp7E5wRV1WbAglQRVNsqZG/F4SJto9Qe/d7GO+vKn9jN+s9uruyrsgHHsBYc489E rA2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PlDXtypS; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d127si14205825pfg.255.2018.11.20.02.10.26; Tue, 20 Nov 2018 02:10:42 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PlDXtypS; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727867AbeKTUiD (ORCPT + 99 others); Tue, 20 Nov 2018 15:38:03 -0500 Received: from mail-ot1-f67.google.com ([209.85.210.67]:43531 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725949AbeKTUiC (ORCPT ); Tue, 20 Nov 2018 15:38:02 -0500 Received: by mail-ot1-f67.google.com with SMTP id a11so1135663otr.10 for ; Tue, 20 Nov 2018 02:09:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MuTXG+7hWhellvogEp5h0I0J+YO+uaVkNlq69jSlRMg=; b=PlDXtypSJe+IKYah9c9AeKrHH3umMaj4aT8vtt6vJIEt9KxFnor4JKwAVGheEAw1h1 HHfL0UpA51DMJo77/A27KKui1ven3LXFE5b/4R5/2jYBZIChgcOBsvljctlxuA9Kv+qk 9p8HEkOXXocep7ylFH8PL3WWBEninjubJqFspI2SSLJVOzXeR/k1J2mwNZ1AYoc11WPT poTNNF/gElrwoWcZ+CWFGeFGkqouhvZhnEkoYrBGsWp5Kd1C1zT1ubvFKYxZbgg6ffia /+GOr/7ZN2RAoBjp7DT0RHn+sG0v1JprukZi4gZLtAbi3BKCHQYCBmp3pkmGtlenlGHL wMVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MuTXG+7hWhellvogEp5h0I0J+YO+uaVkNlq69jSlRMg=; b=IlRSxZ4tlGJKDp8PDei6fH9h8HPn18S+MW/Y8Vrk/DcNuAmnEaF1Gb4vBnjvMjf7dU wP7JBNHyD7E5EGblrQDHyULq7B3hnreg4U9kzHzOBQDiUH4ImAw/aiVn8UNIIWLjQ3Si SM8gJ6KjTiD6eLY1+l+xqfi3CeUTq7Tls9LzUhpCLYIXWb4Z6FR0F1yT/ag2gHQQrZuM Y0oiw9qQgrnIZUzr3jgAKHuffKZSVc4EA0YBwsLFUdJVNmOpsgTDpgLrEpr/UetK+9lY hduIv5Y39W2jHCIrC+jPLzGjzmYXqoZHrK1acsxTVuf0D2b1SyCGeF7p+JRiVSMduak8 hayw== X-Gm-Message-State: AA+aEWYwfBQHMeRzpS98wXf+QoXpenCA4MEi5HsfPDyvghMjvApJdLMC Jbha9IiI7UBQ+6Dd+JlDqdF9H/1Edc9qsWKdTsDpzQ== X-Received: by 2002:a9d:2841:: with SMTP id h1mr737637otd.215.1542708581925; Tue, 20 Nov 2018 02:09:41 -0800 (PST) MIME-Version: 1.0 References: <1541699709-25474-1-git-send-email-john.garry@huawei.com> <1e2b8689-dc1f-3ede-4eeb-4a91d3a3f63f@huawei.com> In-Reply-To: <1e2b8689-dc1f-3ede-4eeb-4a91d3a3f63f@huawei.com> From: Ganapatrao Kulkarni Date: Tue, 20 Nov 2018 15:39:30 +0530 Message-ID: Subject: Re: [PATCH] iommu/dma: Use NUMA aware memory allocations in __iommu_dma_alloc_pages() To: John Garry Cc: Joerg Roedel , Christoph Hellwig , Marek Szyprowski , Robin Murphy , iommu@lists.linux-foundation.org, LKML , Linuxarm , Will Deacon , Ganapatrao Kulkarni Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > > > 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