From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CFE2C433EF for ; Sat, 9 Apr 2022 09:53:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C4026B0071; Sat, 9 Apr 2022 05:53:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 24C236B0073; Sat, 9 Apr 2022 05:53:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0EC6C6B0075; Sat, 9 Apr 2022 05:53:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id F01396B0071 for ; Sat, 9 Apr 2022 05:53:14 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B27DD20FD7 for ; Sat, 9 Apr 2022 09:53:14 +0000 (UTC) X-FDA: 79336877508.07.01F98B0 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf06.hostedemail.com (Postfix) with ESMTP id 498EB180002 for ; Sat, 9 Apr 2022 09:53:14 +0000 (UTC) Received: by mail-pj1-f41.google.com with SMTP id s14-20020a17090a880e00b001caaf6d3dd1so13953712pjn.3 for ; Sat, 09 Apr 2022 02:53:14 -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=kORvfcaOheWx49EEciX/6OfzrbPJdc3PdO48C7xNY/pk7SATDoR+tFIXrrN2PflUnN AlBq3tisIGj1kjFyIYLc4AW3b8gNwXvuI7K2wfYRnhKtpdwKitUv4p0T2nyIcNHJHYAi stR3ll63Q7sljdEe0dYm+WPI6IcESy0gpgjMBgDFbpInpNDcbqGWZOoV/kOFBFSa7wLe gcQI84ZqY9umSv9695ST6VfU2+9WGriWVahyKBr0lJEebsligDD58rSy3zMY3BH1ia/z U1xP+SPkw2P7MvKmnMoIWpb5UVFk73LkfIe3WrN3D3TkbnwuaTd7icuXlebnRyVkbHFF lh2w== X-Gm-Message-State: AOAM532/4sN/uto9G/NiFPvOU1RjkXDsRB2cjH4WspVwy3I2tQfbJE8c /nXLkL+y7tn4LY3ZwODqBFk= X-Google-Smtp-Source: ABdhPJyfohctX+WKiL65gQ2lsudjB43W0uSz+T6jsLtKeBg9FgIlPUxoPcOJKhAEt83x8Fidvj2d2w== 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-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 498EB180002 X-Stat-Signature: bj6ob959zkxqu9wpkw8okpzjgjzhgdc4 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=isJJzeLp; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of ohkwon1043@gmail.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=ohkwon1043@gmail.com X-Rspam-User: X-HE-Tag: 1649497994-929229 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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