Received: by 2002:a05:6a10:144:0:0:0:0 with SMTP id 4csp963605pxw; Sat, 9 Apr 2022 06:42:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw614NVreVpNrRR+PwitZvDjqEXVKUT3VMaR71f72+mtzkkuKOf0te03PyQXXGEiPxNlByP X-Received: by 2002:a05:6402:2794:b0:419:2ed8:f36e with SMTP id b20-20020a056402279400b004192ed8f36emr24263666ede.44.1649511731087; Sat, 09 Apr 2022 06:42:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649511731; cv=none; d=google.com; s=arc-20160816; b=x9BhYO677AgSwJXO3MuEli1ecdDI3MQh3iD2WV78qwYLgmHt40GNQq+jw6XZggbJUl QWRQtSPU6hilUNOAzIaifvsQWE6xibmi6D9ezRQYvx9USdPX8PTRRm/tKTW/u96O+tsV tKKxj/+iNBZzUsZNW4eoVxKvgI4L5+9FT5kjAsj25ofv7JGD8HJmOEfckev9xzPtHPdx 7huFImEcyaP3gqZyYa3vBbOfpNQArabF9QvenPU84d1piQcSCKsht/VUXFGI4Oaf/BAi 6iG4AjEH6eZcE8fe8PXGfx+ogdWNVjC2exlhrcA1Lq+8q4+ySPCE5VC5iYA7Avv3R1Ca lv2A== 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=LiEuvQ5837dDmV9cuDnpaWOy1YwYONvco8pKO+KyVCQ=; b=a5hcbu6e/vewhnsMDSl97CLOZ4LGm9aJlNNvX1w0LFVgvhcBJBcHVEB6sPzMWJ5qS+ LnJA5JhubCRSbzH1LTvL3M1GUcg796Rgpf48ULayKJjXommwiYoEE7KGi0jyjIscaNZp Mv2eog1ivOtme6iVIBY6me/o1odrUR2ePxgwPl4ay4ih5QgcIfkOf66+gtI/QHzy0VcF WEqfGWe12Yj5w4pWSKCvG7zjuBGIajxGYo7/FBuTCAvnbPdvDZgBsXHAYlMjgmfIE/Ul lE+HGfFWfW1/RfxCWHdsR7E9FzalsOy44dMHfUUzlv1PATkR71LTpJMRtKrB3Ho23mtY 53zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=isJJzeLp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ay15-20020a170906d28f00b006e87b73b8ffsi333785ejb.131.2022.04.09.06.41.46; Sat, 09 Apr 2022 06:42:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=isJJzeLp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S241334AbiDIJzX (ORCPT + 99 others); Sat, 9 Apr 2022 05:55:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241309AbiDIJzU (ORCPT ); Sat, 9 Apr 2022 05:55:20 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD2FE3BF93 for ; Sat, 9 Apr 2022 02:53:13 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id b2-20020a17090a010200b001cb0c78db57so8702591pjb.2 for ; Sat, 09 Apr 2022 02:53:13 -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=LiEuvQ5837dDmV9cuDnpaWOy1YwYONvco8pKO+KyVCQ=; b=isJJzeLplSA+L7hyoKEBdm+ep2qRvqauWtx77pn/yqE45M/5afiG7DdAfeE1wXvkP0 bqrXC4Sz27Kyn90kCkEPvfAaHjfkf6rF6RofPrjnAE83r9vryvcro6m7EJeZb0q8Ib5B E+peQkyTLCyrxiNYTPyy0Aj5Zd3wQBE1aSt6ckMAe605OvUrV7MEcZW2HncYJF7EsK5e E8HEpKFsBfGqRgxyPaxQm0LCo3S2+Mm1GmVeOtFrmxUxFtpaeIyvjeKCzBxIGgXwQk1A Q3LEQ/FSyxr/i9Dru/Qikse5I4taMGVNCgIuxh82fqAo92fPkWru4H55jeVUOxpTyiGe 9KBQ== 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=LiEuvQ5837dDmV9cuDnpaWOy1YwYONvco8pKO+KyVCQ=; b=pvoVTn10t8pc8FerD+pN2OwtDjWXewzaj4V7njb1BsjqLF5tvHMJv+axT6iBBTfROC IPaaQlzCDZDdJgxn8sPwvOI2Yy+viD5EPI/f/YCUzJZ4LZDZKqMMVjaQRJGSS9koPgyC DuUJ2PBisg70VvGHW1v8WtIZYDDGxHE1NP3pdOcu4MTfw62DQh5JS6yfVgqV8Rw1JE4v 6+kGamr5LqMKb2EYd9EFuvNtc6SYex2ET+zhxrBFC30QfW5nMFQeVnCL1YOQ4qE/qJDi ucG3wQCjfDnhro9bdcisgHnmWPoFvTfNOtKaK07o2aSF1AOw5TBwFGMOfcyX4XHXuTRO 4Q5Q== X-Gm-Message-State: AOAM530rnWdDLU1WT1y/WSYf+O4agE1o2Y/0MlDMxtcUWUfK7TdPrOZ+ sPzgQ0KshFTEmR/x5hziM94= X-Received: by 2002:a17:902:8ec8:b0:154:5ecb:eb05 with SMTP id x8-20020a1709028ec800b001545ecbeb05mr23225582plo.56.1649497993193; Sat, 09 Apr 2022 02:53:13 -0700 (PDT) Received: from localhost.localdomain ([210.100.217.177]) by smtp.gmail.com with ESMTPSA id q13-20020aa7982d000000b004fb199b9c7dsm29684865pfl.119.2022.04.09.02.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Apr 2022 02:53:12 -0700 (PDT) From: Ohhoon Kwon To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jiyoup Kim , Wonhyuk Yang , Donghyeok Kim , Ohhoon Kwon , JaeSang Yoo Subject: [PATCH] mm/slab_common: move dma-kmalloc caches creation into new_kmalloc_cache() Date: Sat, 9 Apr 2022 18:53:05 +0900 Message-Id: <20220409095305.586412-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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 6ee64d6208b3..eb95512de983 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -849,6 +849,10 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type, slab_flags_t flags) return; } flags |= SLAB_ACCOUNT; +#ifdef CONFIG_ZONE_DMA + } else if (type == KMALLOC_DMA) { + flags |= SLAB_CACHE_DMA; +#endif } kmalloc_caches[type][idx] = create_kmalloc_cache( @@ -877,7 +881,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 +902,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