Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9401623imu; Wed, 5 Dec 2018 04:20:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/W7DZ4cM9vCyNXM/6vTQlt5x8e3umiHFc5qFp0CdAo4oafJZ0GN32TwIWuR44Evl9N5rCoy X-Received: by 2002:a63:b94c:: with SMTP id v12mr20200056pgo.221.1544012440220; Wed, 05 Dec 2018 04:20:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544012440; cv=none; d=google.com; s=arc-20160816; b=YP9Fi+E2rEWBNtCm9s0oyOKMb7/Z2OV+KYt1ADb5X6K58+3n4m15mh8gvvWEgNvGUJ N6ZsFAvoUc+1PZO5ueGQlQgA7BgU7UyVdCun2QJRnbqkEuRTuOfMqNvq76L1uCAcFQNy vBEBoFHwtsumowoFub5KgTfpnFxPaE/u4O1VvV7RRj3M0gemH6lEVkmVdKSSDVZw7tqU YOVzD7e7xvKmfo0uhoNOUvG8mCTpqyFxku8UmHgJN8d6EGiQ9KOoCok9A7dJY84d9KSn 8is38Q9QqIcmrfOWeK4rBjBme6VdUYfMKeSLwCdnTERafM4YSWxLQXR85au8LB7odIDq v/yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=1nyp9Tp0fXFj1m2K/gnq1GtTedm38kaXBnm3X/uB8uo=; b=CUHSRIsAlx21DH63XJjoA7MKBnQcKu6LzY4OipnRRgXJX6P6Q+wCIzQheUe1jgfOo1 IeP/n7x0lo8m11LiWIdM9ptJaYFopJyXL2XXJWBSr7rrkeKIWZ5zCB+aNjFeF2OVlxUi lQ0eR7/YnCYJHvKwllpPOTLgBOFJBJcADjIwWt3mncNoKd+00l/BDQj7N6GJd24G8fFv xs0yF0b3SXvshbHwRBPPfafvuTf8esNDOQ7TrkX5NiRp2+/0NDCNiE+0VZTKaRT9UNEP TKJ1qZvMeAIwQz7ZN//SD+h02d5B5PddMrqAAAKLwCPX82x8ndJkR8WzSoIHe4mD2YqE LL/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NelImZEC; 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 j135si17787314pgc.517.2018.12.05.04.20.24; Wed, 05 Dec 2018 04:20:40 -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=NelImZEC; 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 S1727730AbeLEMSL (ORCPT + 99 others); Wed, 5 Dec 2018 07:18:11 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:41135 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726149AbeLEMSL (ORCPT ); Wed, 5 Dec 2018 07:18:11 -0500 Received: by mail-ed1-f65.google.com with SMTP id z28so16813888edi.8 for ; Wed, 05 Dec 2018 04:18:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:reply-to:references:mime-version :content-disposition:in-reply-to:user-agent; bh=1nyp9Tp0fXFj1m2K/gnq1GtTedm38kaXBnm3X/uB8uo=; b=NelImZECs4k9/oUKjG2gsdkH0QS0FMexDO6PiWlegc6w+w36g5K0rqlmBgcGyA6vA3 AuKpJpngC2Y2V40OiewgQAnPDMtmoivXtYQ8yTRZtH5GAR657Aw4OLMck59ZGC+xs6li JeFlvQu1aRipxd1vjTgBU2+Ncm6+gwMF1dU4cEnGcnl3xnaRUzwxZ37xRZW805ykhCMb AQ90AJFeNKaJxZcQKxg9fuEJ5/B1vmQmg9xbG1jpA3PxQydsEKcCdRMu2MbyHIM0bAib bF597ELwDcEACCBxvb4Duh9np2WRUIz4B37RPPz5KYPwjeC6aaa/vkRJd8F/SRfydc15 ZU6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:reply-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=1nyp9Tp0fXFj1m2K/gnq1GtTedm38kaXBnm3X/uB8uo=; b=Sln77dZelClTaQzv2PRqEIYFjC4N1oojKYLplx2sVlhVfRJgAoznfpZayI7J/8oFGx ijbxUo7IhqLFtF011M/1r2ISNxkbpD+YnS2srP1QnebVk5Da0AAnBAW2GiT8ZvYJXBJ+ kzQowrJseQvpkLDmXiG4I0/ZLY4mJDDqtqigr2N3FaY9XCDt2I/zI9zBOoDBLHZlR3qu yaMEIhw5mS4z6MffCCONLKVPxR69nGv/jXVhQUo2ASCm10MLnTnlyLURa9a2G4toLIMt o/jzB8dXHgYgh395NGNfaS8HT0TbI8i+bHTFgoZbuSx27OR1jM3L+YN0WuSL3it8AK8n lekg== X-Gm-Message-State: AA+aEWZxOEDJnlyXpmuYlchhCD3nn/IGOLjvyVVVN0NPGoS55Yhz5Qrx XtrisC8okdjpphFXhyhAWRk= X-Received: by 2002:a17:906:2083:: with SMTP id 3-v6mr18932433ejq.145.1544012288932; Wed, 05 Dec 2018 04:18:08 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id v11sm5547817edy.49.2018.12.05.04.18.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Dec 2018 04:18:07 -0800 (PST) Date: Wed, 5 Dec 2018 12:18:07 +0000 From: Wei Yang To: Nicolas Boichat Cc: richard.weiyang@gmail.com, Will Deacon , Michal Hocko , Levin Alexander , linux-mm@kvack.org, Christoph Lameter , Huaisheng Ye , Matthew Wilcox , linux-arm Mailing List , David Rientjes , yingjoe.chen@mediatek.com, Vlastimil Babka , Tomasz Figa , Mike Rapoport , Matthias Brugger , Joonsoo Kim , Robin Murphy , lkml , Pekka Enberg , iommu@lists.linux-foundation.org, Andrew Morton , Mel Gorman Subject: Re: [PATCH v4 2/3] mm: Add support for kmem caches in DMA32 zone Message-ID: <20181205121807.evmslrimsv4pdtza@master> Reply-To: Wei Yang References: <20181205054828.183476-1-drinkcat@chromium.org> <20181205054828.183476-3-drinkcat@chromium.org> <20181205072528.l7blg6y24ggblh4m@master> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 05, 2018 at 03:39:51PM +0800, Nicolas Boichat wrote: >On Wed, Dec 5, 2018 at 3:25 PM Wei Yang wrote: >> >> On Wed, Dec 05, 2018 at 01:48:27PM +0800, 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") >> >Signed-off-by: Nicolas Boichat >> >--- >> > >> >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. >> >+ >> > 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; >> >> The original version doesn't check CONFIG_ZONE_DMA32. >> >> Do we need to add this condition here? >> Could we just decide the bug_mask based on slab_flags? > >We can. The reason I did it this way is that when we don't have >CONFIG_ZONE_DMA32, the compiler should be able to simplify to: > >bug_mask = __GFP_HIGHMEM | ~__GFP_BITS_MASK; >if (true || ..) => if (true) > bug_mask |= __GFP_DMA32; > >Then just >bug_mask = __GFP_HIGHMEM | ~__GFP_BITS_MASK | __GFP_DMA32; > >And since the function is inline, slab_flags would not even need to be >accessed at all. > Hmm, I get one confusion. This means if CONFIG_ZONE_DMA32 is not enabled, bug_mask will always contains __GFP_DMA32. This will check with cachep->flags. If cachep->flags has GFP_DMA32, this always fail? Is this possible? -- Wei Yang Help you, Help me