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 8E6ACC433F5 for ; Mon, 11 Apr 2022 11:08:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5E1A6B0072; Mon, 11 Apr 2022 07:08:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0DDF6B0073; Mon, 11 Apr 2022 07:08:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AE766B0074; Mon, 11 Apr 2022 07:08:05 -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 78D306B0072 for ; Mon, 11 Apr 2022 07:08:05 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 504F961844 for ; Mon, 11 Apr 2022 11:08:05 +0000 (UTC) X-FDA: 79344323730.15.EC45681 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf14.hostedemail.com (Postfix) with ESMTP id C7F7F100005 for ; Mon, 11 Apr 2022 11:08:04 +0000 (UTC) Received: by mail-pf1-f177.google.com with SMTP id f3so14315778pfe.2 for ; Mon, 11 Apr 2022 04:08:04 -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=sLKOyEDQ94V4T7IMbKowetu23bD0e9Tu4ZHOeay0Nmw=; b=Z8w11YypcQClOBGXJEkE3vzocyTa84nM9++PON2DhSNRnGzR8wLsabf1eZWhjFrkLQ t4gZm37BQaOhYyaq6Za4OLDl5zRWURbf3+lYpuTwMRrZrKH9hLcWmERyyHXL/D1ujwkB TqrQ/J00olz2VGqofIzSgZsoOHlc9O0SKZywuyxbg2UARzRza79eEG6eWkc91expZqrb f7KtUHhHNDqOtQ+A/+WgfZaTbax3tuUrv1E/csb6EPOMxm9o0szDmysiZg8Q+D4sCjNu uOA4RmeMGMYP/fnskE11HyF2xUI4mrUWZ5AwDXk0cs/nwXgGJjjRtpizE4QwfO77QbVT aTew== 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=sLKOyEDQ94V4T7IMbKowetu23bD0e9Tu4ZHOeay0Nmw=; b=wYQ+uiqV6Wf7iFRUwx2PHCQFirHvYAuVnwHtcFTEFnDIx8/h26ccNMJcM4j84sBnZC nR2Mdms/SeSxB0/IM2WCKpWNlURKia/DvPkGNuVQfHud72j2Ciujl1068noyyhuhmtSK +deKKqb5ij0dQdPmD4q7Zg5bU67GXFvu8UgeJv7bJ6zM4X8ZlCnldRiVZZOBifpj+hwt WUS4z14JoHSRwiqks/eCBFH3kb9aey7LcUr7EP0S1UIR4S9eEgabciHDSJ2V1g3EKqYR geAjs1iAbKsR5fxZmM5HOo1wCZnwKaED0SKV4LVTAxR3A+hGRUwgHX6hW1sadH3n1wZO Bk8Q== X-Gm-Message-State: AOAM5309fhr943P+6yjyOWhpGTXeAtpi5B1C7pUA9p7WvxPpkuW72jOU Csy8b6z0PXipFL5S2bGVQsQ= X-Google-Smtp-Source: ABdhPJz7/6ofoutkdPkyf59dqggkjVqNNJBtorDyZuwg3taNrLb8ll7lpbYgrDXUBoT1TBI7CHlX0A== X-Received: by 2002:a63:db4c:0:b0:39d:18bf:7857 with SMTP id x12-20020a63db4c000000b0039d18bf7857mr9615859pgi.413.1649675283592; Mon, 11 Apr 2022 04:08:03 -0700 (PDT) Received: from hyeyoo ([114.29.24.243]) by smtp.gmail.com with ESMTPSA id c74-20020a621c4d000000b00505be1ae39bsm3694138pfc.9.2022.04.11.04.07.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 04:08:02 -0700 (PDT) Date: Mon, 11 Apr 2022 20:07:55 +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 , JaeSang Yoo , Wonhyuk Yang , Jiyoup Kim , Donghyeok Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/slab_common: move dma-kmalloc caches creation into new_kmalloc_cache() Message-ID: References: <20220410162511.656541-1-ohkwon1043@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220410162511.656541-1-ohkwon1043@gmail.com> X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Z8w11Yyp; spf=pass (imf14.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C7F7F100005 X-Stat-Signature: 9y15ymaukmn9cb99smdseixcw6crau8z X-HE-Tag: 1649675284-872867 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 Mon, Apr 11, 2022 at 01:25:11AM +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 | 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 */ > Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> BTW this patch may conflict with [1] (not merged yet) [1] https://lore.kernel.org/linux-mm/20220405135758.774016-9-catalin.marinas@arm.com/ Thanks! > -- > 2.25.1 > -- Thanks, Hyeonggon