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 3CA2DC433EF for ; Sun, 10 Apr 2022 06:52:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 948516B0071; Sun, 10 Apr 2022 02:52:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F8A76B0073; Sun, 10 Apr 2022 02:52:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7C0906B0074; Sun, 10 Apr 2022 02:52:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 6C5576B0071 for ; Sun, 10 Apr 2022 02:52:09 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2BC60BF7 for ; Sun, 10 Apr 2022 06:52:09 +0000 (UTC) X-FDA: 79340049978.03.97A9E1C Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf13.hostedemail.com (Postfix) with ESMTP id A3BA420004 for ; Sun, 10 Apr 2022 06:52:08 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id p8so11957634pfh.8 for ; Sat, 09 Apr 2022 23:52:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=kiJ9APoqAB53N14utwlexldPR1v9F4okKCVpXr8jG00=; b=n4zvGtKXRzvGFfyO3u/RNn7kM4d6vqAkqEHKtvH94+JyXQY08F95Ae572CgcNvQt39 QtsCxAue8NbjMVDm4IeiAEIETT1QRZIHzAvpmkpNOQA55khboNhaNJ+N8v53Xw/URXg6 mz+jpvR2TVvxY8CWG2y7mt62Vz/CLURZL82BpHENZPLBNfBpTMEVC3PXCTPcYHJ8IlMT Vc2QhIyD4eo/pJZy6tGw31URtk68oNwH0himZ9JTkKtfXwAGGucL+aSSMtETLuaVrJPR 2PN14tnO9ha1xj5JAExdib4hzuWpTxOQcQ19nIvb1bT3ni95TfExlidI0/9QwBcf1fIv 8nOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=kiJ9APoqAB53N14utwlexldPR1v9F4okKCVpXr8jG00=; b=64QDV3LAHdQOOWm8RAqHcZel9TVgjWeNq+ePNzWoytWAOXkR6GNW7hO6od+P0b2oG9 GbQpk+P+jkTcPgeRpjA3mwTD3UE+6uhQYdu7HvsGhbfqwgLpMRqqLhHVBndnwzYsRAKU POvpe+idfia/OX/vmKQ4nO2DjJkuc9g8xt/YIlchx5TasZyIekSdEVNe3M4fuQs5Bq70 9pBLmeE1vLdVU2c9hYE1QLaTCKZ+sKXIovyAm8aL2ZHf4xOMpdOSZNkixcyEqRKXmc5P MV2BFgIVK2ROXpXxDDgFeNuJAxTVTDqGRSkDSdqL+1QP/CE2nn2IKo2IW0iMfUrZpYEJ xxXQ== X-Gm-Message-State: AOAM530H4jsH0AEhZ/v5MuQncZkJjnzkdlMcqM3vW8PQZ+ydiDhQ9scX yZOB+khcGzFUsR4QuPsHvdU= X-Google-Smtp-Source: ABdhPJyLDrSiTNb28nE2LmdJX9xLgOvCBSPQsqWb+YP4LtSAVp0Cq1LTlCiV+y5nX5NJXcJkRRrygQ== X-Received: by 2002:a63:ed45:0:b0:399:5116:312a with SMTP id m5-20020a63ed45000000b003995116312amr21326806pgk.611.1649573527624; Sat, 09 Apr 2022 23:52:07 -0700 (PDT) Received: from hyeyoo ([114.29.24.243]) by smtp.gmail.com with ESMTPSA id y3-20020a056a00190300b004fa2411bb92sm32594637pfi.93.2022.04.09.23.52.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Apr 2022 23:52:06 -0700 (PDT) Date: Sun, 10 Apr 2022 15:51:57 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Ohhoon Kwon Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jiyoup Kim , Wonhyuk Yang , Donghyeok Kim , JaeSang Yoo Subject: Re: [PATCH] mm/slab_common: move dma-kmalloc caches creation into new_kmalloc_cache() Message-ID: References: <20220409095305.586412-1-ohkwon1043@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220409095305.586412-1-ohkwon1043@gmail.com> X-Stat-Signature: jzjkgk4ynbkfekou6oy91f9ckgs6g316 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=n4zvGtKX; spf=pass (imf13.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: A3BA420004 X-HE-Tag: 1649573528-763875 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: On Sat, Apr 09, 2022 at 06:53:05PM +0900, Ohhoon Kwon wrote: > 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 Maybe IS_ENABLED() would be better instead of ifdef for consistency? > } > > 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 */ The patch overall looks good to me. Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Thanks! > -- > 2.25.1 > > -- Thanks, Hyeonggon