Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp19482pxb; Tue, 12 Apr 2022 15:35:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyz3tx5q82h4w5iREf654Afom0uPrf1w8hhkOhLglH8ZvlXoQc78LysyucwenwJsX62kC5S X-Received: by 2002:a17:902:ce85:b0:158:66cd:c370 with SMTP id f5-20020a170902ce8500b0015866cdc370mr11891046plg.111.1649802949677; Tue, 12 Apr 2022 15:35:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649802949; cv=none; d=google.com; s=arc-20160816; b=jJLPHKfXF42JxvXy6PYOtH1dXE80KP2LL56JfD5mRP/RcGSrXXBfVSCxPTn5HxyFQa tQbROvy0BL/NEXPBY6U5VBauioMrwc6ZasXrAgQqk4GrB7j3KQBhqPGfv6QWEy9lFoOT lXNNqxw3YDsJtoHeKb3IGhiaG65VKLwlkBCzx/5xWEmHYtOjF+G/MLycLtz+tQFovvZR X87gvDPp/5JS+wbkbAAlh4wux+Jz/wDxKElAReoZl8HJniZCWXNSPhg70zjhkwwavLiJ +A5TJLQCoC1uecE5HTZWlwRL1qaaG0Uo9KlJNjOckt/7SazLirWvM1pl47fGoS//nkwp o3+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sLKOyEDQ94V4T7IMbKowetu23bD0e9Tu4ZHOeay0Nmw=; b=bwR7RvqBg4E941wHOb3K5PjE9k7jmTv2C3MQ1QoAeFSN7d3trlT4svyux3kdE90HY2 qKh+DNbCsHrDPdIbSs8Vdcuprr2oi7nyedtF816H5m0L7fN3iV9Pvtq1IQw/oWraQKAD 5h+fDNReyzFIIheOD22Bi2TL6srjqPcOzRXF0gpvsuI0E1/t52zkGnM1Z3c/F10tK0Ol tagrniPkCpBJk+ME6o0zmNiKnnj2Qcnunifz/a6yAQ49xZLjCcHdiuBVxhvftHXEbXS3 BGaXsv7+rK4IKJFT0cn1QiRMcTnvc+YHIc4+vbumwdjN4RR+MSoZeHJE1lSmlco+HuSw QzDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Z8w11Yyp; 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 g2-20020a17090a4b0200b001bd14e01f69si16093212pjh.87.2022.04.12.15.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 15:35:49 -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=Z8w11Yyp; 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 F2374198ECE; Tue, 12 Apr 2022 14:12:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244623AbiDKLNj (ORCPT + 99 others); Mon, 11 Apr 2022 07:13:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345925AbiDKLKr (ORCPT ); Mon, 11 Apr 2022 07:10:47 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 412AD4553B for ; Mon, 11 Apr 2022 04:08:04 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id j17so12825453pfi.9 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=ZmGW4uGI+c5hVLFjM0RoONLjSa+68Ba1pbEfEXfATst9cL09jf4qyIzhKc++BjN+mL U27iqFSnFEERVGePtpeTYwN1rrAZ4oggL9xzf+Uu0MOpEL2s5COMngzv8D8nsktNjS6h Oflbh4PKh8pHoOA1UitHQ3wKX4wZGUXL2/g4AuidWNQFkKQuUWi6Lf32qtSxNQOJjqo2 b3qcX82O+zKzsOGC8cxmSNFpiqU8GFJ1oN2NRsonoiPPy26z/Fbm3y5wbvopTFBlmrqL 8DeVTtTQh4Y/yeJHfllyMGtE177nUEiSULG6XAF712lfqr1FKUtEVOOmMlNbCwVazbFY ajeA== X-Gm-Message-State: AOAM531lU12h7Qay+PKTKIL2qQqb3Px2csWoot6OwYw8G/ZM98+dICyJ hZu4OiNECBPQEPyoQEZJn1I= 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-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,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 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