Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp804907pxb; Tue, 12 Apr 2022 13:57:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBGyswCKYgmKi9qgH5FERzH+b6K4oHf/re+UVFFZMa+PQRspdC1bM1tlXh8avO+6K3HCHn X-Received: by 2002:a17:90b:1e4e:b0:1c7:3507:30db with SMTP id pi14-20020a17090b1e4e00b001c7350730dbmr7011021pjb.39.1649797053757; Tue, 12 Apr 2022 13:57:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649797053; cv=none; d=google.com; s=arc-20160816; b=TonCm66nUvBWX1CUGOz68gDi3lQeDnPQjmblk2PtuQEJaonbO7Ge+aUh64CTj8QBFC W2U10IYgeuHJ95tEaWwWjl/G686gVeoMpoCCXDkTLeGCQsHaOh95x8NJ4WZK7+0zOIHZ iI+bSwjnU+rGZ+gIW9ySUC5vMuCEQvliUedDOofqRRQXU/cb45dm/cntOghFAxAg9NrA O1uELKDFsGJBe8J/RjRylXZZ/gMg3+u6BHHwZzaMbifFbr0QXUOi395aZqhbvCiEvd1u ZMITlheU+MOxjpTbfKiDdjA8qTMsB9oX6V8WCELPhLto1isnT1v2+h1JiNYBb1bhOlCO 5QtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=vgYau9yYdCljtzTr6MtTaLrwj9ih04H5dgCFTrcTCP8=; b=cylmRurBk9m1Nj+P634GOf+Bf5UZBvOgRq9VCcxo1z/4WSbP7pGOhfSUjGGjw+IR0x 28wjObiXbfc/Ts6pPt1OQ487ldMy1X3J3plZAPaktDj+o6OX5VLDwshDqKLKK1mgrFPM +9XOyUW9R9IGTtKJCqrJKWjh7J1TADFmw7uRfUF3ZJZwvj91GqLLeUnq4j0vLqbbqR5O 8mHe9RGJdwXMdm3Y81nuHNwMWfvk7DTdg0W5uRIU9xJTpe6T2pIv9DfOqtJuH/hqcQ9N lxmwGMRqFDBPdZwRvkYK2DYF2loW5ruJoGL4OyGQOE1E5lqMsd43jn56B7wP98kJ1bcO ot0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fX1sS2gn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u137-20020a63798f000000b00399574f25a4si3747365pgc.651.2022.04.12.13.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 13:57:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fX1sS2gn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 97C938F99E; Tue, 12 Apr 2022 13:20:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243590AbiDJQ1d (ORCPT + 99 others); Sun, 10 Apr 2022 12:27:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243582AbiDJQ1b (ORCPT ); Sun, 10 Apr 2022 12:27:31 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D46B3703D for ; Sun, 10 Apr 2022 09:25:20 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id j17so11086948pfi.9 for ; Sun, 10 Apr 2022 09:25:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vgYau9yYdCljtzTr6MtTaLrwj9ih04H5dgCFTrcTCP8=; b=fX1sS2gnm4hZVr3Zi9jdGyuK9CNudj1DjNK9yC6AZfhipZ1VR/Bug89B/knheOPpDW RpPj3tBxndzn+vXz4WYx/gkXCAFvaCv9u58Ze1f0r2QV+tnw4vPGfBNlA0OnKxUP+r2p qFwaPxbnKy1+UNG20+h8M9a72TinACBrFadtamkkuKzko3d25F0pHaOWmWLOOqtR0mMG +Am4TSO1a/pTJR9ODfxMZIwjPzmwWcZwHc7vP1lR/ALCAraOLYiu+UPOgItfaJxKl+K/ MlKcNEEzoQuann4OT8f+GffsS+KEqxyOK3AAWrl4QwNA408txVvrtt6kFNpZHstatv/i x4Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vgYau9yYdCljtzTr6MtTaLrwj9ih04H5dgCFTrcTCP8=; b=pbnubqycT5vsbnvmImkCzfMlH4WyoaKJYmSSzbitn7kZFW8pZI/0iIQtzMSaJ0bm3k cyIjkBHVL5+Lo3ojE8DFTP10coHuisnnWnmqoa1IzeGlQ2GLy9FLupVlw36QXks9R7ls HT96eQKpMmIw+ZFnojB3ko+iJKr1d9ClH7ILgPgBksBsmv7EtTG/YLoYq+JRmLLYICQd uEwZqsEqJ8DjMKZHXglJHJaUYSsf8C3q+GyKwLe9QMqJiEAwhlmqxB7QkCqL79qHruCq gIOITYzLTNBmvMso6ZYu/O66hO1WPHuEI/S51tfz0j7Wz7KqnOLvC/TXNS07JZzQPCXB GEYw== X-Gm-Message-State: AOAM5303NvJPrcDtDkiB1YTLlVjH7AdnIDqvZRyF+vLeYlQCisCfxEvy jyP1g9qusUBpj2ViOTtr+KQ= X-Received: by 2002:a63:2266:0:b0:39c:f643:ee69 with SMTP id t38-20020a632266000000b0039cf643ee69mr10466052pgm.288.1649607919633; Sun, 10 Apr 2022 09:25:19 -0700 (PDT) Received: from localhost.localdomain ([210.100.217.177]) by smtp.gmail.com with ESMTPSA id n19-20020a62e513000000b005048eef5827sm13386553pff.142.2022.04.10.09.25.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Apr 2022 09:25:19 -0700 (PDT) From: Ohhoon Kwon To: Hyeonggon Yoo <42.hyeyoo@gmail.com>, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin Cc: Ohhoon Kwon , JaeSang Yoo , Wonhyuk Yang , Jiyoup Kim , Donghyeok Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mm/slab_common: move dma-kmalloc caches creation into new_kmalloc_cache() Date: Mon, 11 Apr 2022 01:25:11 +0900 Message-Id: <20220410162511.656541-1-ohkwon1043@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are four types of kmalloc_caches: KMALLOC_NORMAL, KMALLOC_CGROUP, KMALLOC_RECLAIM, and KMALLOC_DMA. While the first three types are created using new_kmalloc_cache(), KMALLOC_DMA caches are created in a separate logic. Let KMALLOC_DMA caches be also created using new_kmalloc_cache(), to enhance readability. Historically, there were only KMALLOC_NORMAL caches and KMALLOC_DMA caches in the first place, and they were initialized in two separate logics. However, when KMALLOC_RECLAIM was introduced in v4.20 via commit 1291523f2c1d ("mm, slab/slub: introduce kmalloc-reclaimable caches") and KMALLOC_CGROUP was introduced in v5.14 via commit 494c1dfe855e ("mm: memcg/slab: create a new set of kmalloc-cg- caches"), their creations were merged with KMALLOC_NORMAL's only. KMALLOC_DMA creation logic should be merged with them, too. By merging KMALLOC_DMA initialization with other types, the following two changes might occur: 1. The order dma-kmalloc- caches added in slab_cache list may be sorted by size. i.e. the order they appear in /proc/slabinfo may change as well. 2. slab_state will be set to UP after KMALLOC_DMA is created. In case of slub, freelist randomization is dependent on slab_state>=UP, and therefore KMALLOC_DMA cache's freelist will not be randomized in creation, but will be deferred to init_freelist_randomization(). Co-developed-by: JaeSang Yoo Signed-off-by: JaeSang Yoo Signed-off-by: Ohhoon Kwon --- mm/slab_common.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 6ee64d6208b3..a959d247c27b 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -849,6 +849,8 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type, slab_flags_t flags) return; } flags |= SLAB_ACCOUNT; + } else if (IS_ENABLED(CONFIG_ZONE_DMA) && (type == KMALLOC_DMA)) { + flags |= SLAB_CACHE_DMA; } kmalloc_caches[type][idx] = create_kmalloc_cache( @@ -877,7 +879,7 @@ void __init create_kmalloc_caches(slab_flags_t flags) /* * Including KMALLOC_CGROUP if CONFIG_MEMCG_KMEM defined */ - for (type = KMALLOC_NORMAL; type <= KMALLOC_RECLAIM; type++) { + for (type = KMALLOC_NORMAL; type < NR_KMALLOC_TYPES; type++) { for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) { if (!kmalloc_caches[type][i]) new_kmalloc_cache(i, type, flags); @@ -898,20 +900,6 @@ void __init create_kmalloc_caches(slab_flags_t flags) /* Kmalloc array is now usable */ slab_state = UP; - -#ifdef CONFIG_ZONE_DMA - for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) { - struct kmem_cache *s = kmalloc_caches[KMALLOC_NORMAL][i]; - - if (s) { - kmalloc_caches[KMALLOC_DMA][i] = create_kmalloc_cache( - kmalloc_info[i].name[KMALLOC_DMA], - kmalloc_info[i].size, - SLAB_CACHE_DMA | flags, 0, - kmalloc_info[i].size); - } - } -#endif } #endif /* !CONFIG_SLOB */ -- 2.25.1