Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10251364imu; Wed, 5 Dec 2018 19:51:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/Uh51waVsejFbU5A8yLbYl/oqNYpqWUaZpx7JgcU4D/eyJVMP+sjUh29GN9YLOO/e3MBgYH X-Received: by 2002:a63:990a:: with SMTP id d10mr21704598pge.279.1544068287993; Wed, 05 Dec 2018 19:51:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544068287; cv=none; d=google.com; s=arc-20160816; b=EqeuldcK/aTmoVtnAg6gWpWN8D3fKrcm/cafqKCDVm/SKi0WiFbgc4k5k+KLQIuo0O yBe/hAkVKX6eEn26Uauw7iniaRIxbZk8oDKvJhRQm6EdJHBBEE+Q05ThK+ljybMpmerm pHKcWfJQEqyTr7qb4O1ivRR6qMJ54b2UnhyJExGFBwEmxEhQ4EcZBivRK2VEDxndbCCZ 29k4t1kXC8BoRinnh7QZwvAzCTLP/dNnHj3skme3Vp3lRpFs+ojKL2SrmS3w8qKkg8Gg K4zBE1HrFi+7xmVrd+D+zMFMWnx3k/VGKtCsTOnd8UMpe222gSzGDd2GWQf4jmLDRyVu IHBg== 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=3TanGnesUsXNVn4844W69r0sdlZW07QzX84i1mc2ruc=; b=bUQ/A8b3Ayet+biIGqsgCT1fZUE0zhaZgUA0IRbM2effTh6xpBnilS3XvvPHkm+VSU bRxHqPKeKaiWdvR/vqqBAZapq+Igs6Yyxu3jcr5aXK3IU+jVkPci6ckrEh4RrPPXK2kR xXgHaPlUltZKQZB0qAC+39fKVYbBI2w7mYWgMlFsL4za4SLszyncskJeYtW7WrY6JLRo G3ieGgJrl7lZF66Unoi+3TdEIJhBIlhaMgTBopdSxBalE7OfWwteMV9XEMvIjibxHWKQ MDlUU7WzOHzEu6XPcsorfMGlYcbIWtNpUCiyVpcjoGCDEgcwQR9+NLox2jbrcydKAXbQ 8hzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=n4iKpYFu; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m188si1515581pfb.266.2018.12.05.19.51.06; Wed, 05 Dec 2018 19:51:27 -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=@chromium.org header.s=google header.b=n4iKpYFu; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728881AbeLFDuI (ORCPT + 99 others); Wed, 5 Dec 2018 22:50:08 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:32975 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727940AbeLFDuI (ORCPT ); Wed, 5 Dec 2018 22:50:08 -0500 Received: by mail-pg1-f193.google.com with SMTP id z11so10015828pgu.0 for ; Wed, 05 Dec 2018 19:50:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3TanGnesUsXNVn4844W69r0sdlZW07QzX84i1mc2ruc=; b=n4iKpYFuCsH1xA1otB/jI2EqcwcOQmpEOIdGbvJiQNedw8Kc9IEcsfxnxcRMZH2Z8L fK1ox8RGreiHOpL4xMiS5n4U84c+hytx8pYjjBlfPwJuCSYpHtvMqw7ntPgmaR8IrknZ PQpQtULyiFL3jMILWjQd+VohMxSBVy8rBHtkY= 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=3TanGnesUsXNVn4844W69r0sdlZW07QzX84i1mc2ruc=; b=R5PdhL/VSQvQg9FoAEOvvKH/G8ndEqv7cxXCHdIwQe40qcP7+KRNppUrKS4ybJKZAb r7Q1qLaiXZ0RCGk3FnPDjxS25fgDfJira2dVd+ic0ME3GBGzzRn7iLVGGbWO6mSOjUrS 7Iy0ZqZWVaDr70LiW04RSwstSJto1JurdzEvUa5JP55az3f4AiHxAAob95vs1ZokIoM2 uHmfUaxrVtWX1DiXBlgia0N1TU/5ME+fAsSpHxLSBFQ/ZYEBhWMsg8Dc49OBGvXJm9nE 2ikX5JNJCh1rIlJ5YgxxYJNC40Du70oMpJred/elwAaiwEtiPOqQHM4a3R45+HoXzRdQ lYQg== X-Gm-Message-State: AA+aEWZdMY6HCt9YnKaO1prjn0tP0pZVXG/6ltgBiSGJIJnMvH7Kf8fC 5+teDApnU36FKN1nVCnvP4hvjrg/TzsDJ694kwGckA== X-Received: by 2002:a63:fb46:: with SMTP id w6mr22933804pgj.321.1544068206996; Wed, 05 Dec 2018 19:50:06 -0800 (PST) MIME-Version: 1.0 References: <20181205054828.183476-1-drinkcat@chromium.org> <20181205054828.183476-3-drinkcat@chromium.org> <5eddd264-5527-a98e-fc8b-31ea89f474db@suse.cz> In-Reply-To: <5eddd264-5527-a98e-fc8b-31ea89f474db@suse.cz> From: Nicolas Boichat Date: Thu, 6 Dec 2018 11:49:55 +0800 Message-ID: Subject: Re: [PATCH v4 2/3] mm: Add support for kmem caches in DMA32 zone To: Vlastimil Babka Cc: Will Deacon , Robin Murphy , Joerg Roedel , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Michal Hocko , Mel Gorman , Levin Alexander , Huaisheng Ye , Mike Rapoport , linux-arm Mailing List , iommu@lists.linux-foundation.org, lkml , linux-mm@kvack.org, Yong Wu , Matthias Brugger , Tomasz Figa , yingjoe.chen@mediatek.com, hch@infradead.org, Matthew Wilcox 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 On Wed, Dec 5, 2018 at 10:02 PM Vlastimil Babka wrote: > > On 12/5/18 6:48 AM, Nicolas Boichat wrote: > > In some cases (e.g. IOMMU ARMv7s page allocator), we need to allocate > > data structures smaller than a page with GFP_DMA32 flag. > > > > This change makes it possible to create a custom cache in DMA32 zone > > using kmem_cache_create, then allocate memory using kmem_cache_alloc. > > > > We do not create a DMA32 kmalloc cache array, as there are currently > > no users of kmalloc(..., GFP_DMA32). The new test in check_slab_flags > > ensures that such calls still fail (as they do before this change). > > > > Fixes: ad67f5a6545f ("arm64: replace ZONE_DMA with ZONE_DMA32") > > Same as my comment for 1/3. I'll drop. > > Signed-off-by: Nicolas Boichat > > In general, > Acked-by: Vlastimil Babka > > Some comments below: > > > --- > > > > Changes since v2: > > - Clarified commit message > > - Add entry in sysfs-kernel-slab to document the new sysfs file > > > > (v3 used the page_frag approach) > > > > Documentation/ABI/testing/sysfs-kernel-slab | 9 +++++++++ > > include/linux/slab.h | 2 ++ > > mm/internal.h | 8 ++++++-- > > mm/slab.c | 4 +++- > > mm/slab.h | 3 ++- > > mm/slab_common.c | 2 +- > > mm/slub.c | 18 +++++++++++++++++- > > 7 files changed, 40 insertions(+), 6 deletions(-) > > > > diff --git a/Documentation/ABI/testing/sysfs-kernel-slab b/Documentation/ABI/testing/sysfs-kernel-slab > > index 29601d93a1c2ea..d742c6cfdffbe9 100644 > > --- a/Documentation/ABI/testing/sysfs-kernel-slab > > +++ b/Documentation/ABI/testing/sysfs-kernel-slab > > @@ -106,6 +106,15 @@ Description: > > are from ZONE_DMA. > > Available when CONFIG_ZONE_DMA is enabled. > > > > +What: /sys/kernel/slab/cache/cache_dma32 > > +Date: December 2018 > > +KernelVersion: 4.21 > > +Contact: Nicolas Boichat > > +Description: > > + The cache_dma32 file is read-only and specifies whether objects > > + are from ZONE_DMA32. > > + Available when CONFIG_ZONE_DMA32 is enabled. > > I don't have a strong opinion. It's a new file, yeah, but consistent > with already existing ones. I'd leave the decision with SL*B maintainers. > > > What: /sys/kernel/slab/cache/cpu_slabs > > Date: May 2007 > > KernelVersion: 2.6.22 > > diff --git a/include/linux/slab.h b/include/linux/slab.h > > index 11b45f7ae4057c..9449b19c5f107a 100644 > > --- a/include/linux/slab.h > > +++ b/include/linux/slab.h > > @@ -32,6 +32,8 @@ > > #define SLAB_HWCACHE_ALIGN ((slab_flags_t __force)0x00002000U) > > /* Use GFP_DMA memory */ > > #define SLAB_CACHE_DMA ((slab_flags_t __force)0x00004000U) > > +/* Use GFP_DMA32 memory */ > > +#define SLAB_CACHE_DMA32 ((slab_flags_t __force)0x00008000U) > > /* DEBUG: Store the last owner for bug hunting */ > > #define SLAB_STORE_USER ((slab_flags_t __force)0x00010000U) > > /* Panic if kmem_cache_create() fails */ > > diff --git a/mm/internal.h b/mm/internal.h > > index a2ee82a0cd44ae..fd244ad716eaf8 100644 > > --- a/mm/internal.h > > +++ b/mm/internal.h > > @@ -14,6 +14,7 @@ > > #include > > #include > > #include > > +#include > > #include > > > > /* > > @@ -34,9 +35,12 @@ > > #define GFP_CONSTRAINT_MASK (__GFP_HARDWALL|__GFP_THISNODE) > > > > /* Check for flags that must not be used with a slab allocator */ > > -static inline gfp_t check_slab_flags(gfp_t flags) > > +static inline gfp_t check_slab_flags(gfp_t flags, slab_flags_t slab_flags) > > { > > - gfp_t bug_mask = __GFP_DMA32 | __GFP_HIGHMEM | ~__GFP_BITS_MASK; > > + gfp_t bug_mask = __GFP_HIGHMEM | ~__GFP_BITS_MASK; > > + > > + if (!IS_ENABLED(CONFIG_ZONE_DMA32) || !(slab_flags & SLAB_CACHE_DMA32)) > > + bug_mask |= __GFP_DMA32; > > I'll point out that this is not even strictly needed AFAICS, as only > flags passed to kmem_cache_alloc() are checked - the cache->allocflags > derived from SLAB_CACHE_DMA32 are appended only after check_slab_flags() > (in both SLAB and SLUB AFAICS). And for a cache created with > SLAB_CACHE_DMA32, the caller of kmem_cache_alloc() doesn't need to also > include __GFP_DMA32, the allocation will be from ZONE_DMA32 regardless. Yes, you're right. I also looked at existing users of SLAB_CACHE_DMA, and there is one case in drivers/scsi/scsi_lib.c where GFP_DMA is not be passed (all the other users pass it). I can drop GFP_DMA32 from my call in io-pgtable-arm-v7s.c. > So it would be fine even unchanged. The check would anyway need some > more love to catch the same with __GFP_DMA to be consistent and cover > all corner cases. Yes, the test is not complete. If we really wanted this to be accurate, we'd need to check that GFP_* exactly matches SLAB_CACHE_*. The only problem with dropping this is test that we should restore GFP_DMA32 warning/errors somewhere else (as Christopher pointed out here: https://lkml.org/lkml/2018/11/22/430), especially for kmalloc case. Maybe this can be done in kmalloc_slab. > > > > if (unlikely(flags & bug_mask)) { > > gfp_t invalid_mask = flags & bug_mask;