From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by kanga.kvack.org (Postfix) with ESMTP id BBB716B2F69 for ; Fri, 23 Nov 2018 00:37:24 -0500 (EST) Received: by mail-pl1-f200.google.com with SMTP id w19-v6so14968658plq.1 for ; Thu, 22 Nov 2018 21:37:24 -0800 (PST) Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id v13sor61025074pgn.66.2018.11.22.21.37.23 for (Google Transport Security); Thu, 22 Nov 2018 21:37:23 -0800 (PST) MIME-Version: 1.0 References: <20181111090341.120786-1-drinkcat@chromium.org> <0100016737801f14-84f1265d-4577-4dcf-ad57-90dbc8e0a78f-000000@email.amazonses.com> <20181121213853.GL3065@bombadil.infradead.org> <20181122082336.GA2049@infradead.org> In-Reply-To: From: Nicolas Boichat Date: Fri, 23 Nov 2018 13:37:11 +0800 Message-ID: Subject: Re: [PATCH v2 0/3] iommu/io-pgtable-arm-v7s: Use DMA32 zone for page tables Content-Type: text/plain; charset="UTF-8" Sender: owner-linux-mm@kvack.org List-ID: To: hch@infradead.org Cc: Robin Murphy , willy@infradead.org, Christoph Lameter , Levin Alexander , Mike Rapoport , Huaisheng Ye , Tomasz Figa , Will Deacon , lkml , Pekka Enberg , linux-mm@kvack.org, iommu@lists.linux-foundation.org, Michal Hocko , linux-arm Mailing List , David Rientjes , Matthias Brugger , yingjoe.chen@mediatek.com, Joonsoo Kim , Mel Gorman , Andrew Morton , Vlastimil Babka On Fri, Nov 23, 2018 at 11:04 AM Nicolas Boichat wrote: > > On Thu, Nov 22, 2018 at 4:23 PM Christoph Hellwig wrote: > > > > On Wed, Nov 21, 2018 at 10:26:26PM +0000, Robin Murphy wrote: > > > TBH, if this DMA32 stuff is going to be contentious we could possibly just > > > rip out the offending kmem_cache - it seemed like good practice for the > > > use-case, but provided kzalloc(SZ_1K, gfp | GFP_DMA32) can be relied upon to > > > give the same 1KB alignment and chance of succeeding as the equivalent > > > kmem_cache_alloc(), then we could quite easily make do with that instead. > > > > Neither is the slab support for kmalloc, not do kmalloc allocations > > have useful alignment apparently (at least if you use slub debug). > > > > But I do agree with the sentiment of not wanting to spread GFP_DMA32 > > futher into the slab allocator. > > > > I think you want a simple genalloc allocator for this rather special > > use case. > > So I had a look at genalloc, we'd need to add pre-allocated memory > using gen_pool_add [1]. There can be up to 4096 L2 page tables, so we > may need to pre-allocate 4MB of memory (1KB per L2 page table). We > could add chunks on demand, but then it'd be difficult to free them up > (genalloc does not have a "gen_pool_remove" call). So basically if the > full 4MB end up being requested, we'd be stuck with that until the > iommu domain is freed (on the arm64 Mediatek platforms I looked at, > there is only one iommu domain, and it never gets freed). I tried out genalloc with pre-allocated 4MB, and that seems to work fine. Allocating in chunks would require genalloc changes as gen_pool_add calls kmalloc with just GFP_KERNEL [2], and we are in atomic context in __arm_v7s_alloc_table... [2] https://elixir.bootlin.com/linux/latest/source/lib/genalloc.c#L190 > page_frag would at least have a chance to reclaim those pages (if I > understand Christoph's statement correctly) > > Robin: Do you have some ideas of the lifetime/usage of L2 tables? If > they are usually few of them, or if they don't get reclaimed easily, > some on demand genalloc allocation would be ok (or even 4MB allocation > on init, if we're willing to take that hit). If they get allocated and > freed together, maybe page_frag is a better option? > > Thanks, > > [1] https://www.kernel.org/doc/html/v4.19/core-api/genalloc.html