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 DADCCCD37B1 for ; Sat, 16 Sep 2023 01:29:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01AB08D0048; Fri, 15 Sep 2023 21:29:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F0D3B8D003B; Fri, 15 Sep 2023 21:29:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD4118D0048; Fri, 15 Sep 2023 21:29:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CAAAB8D003B for ; Fri, 15 Sep 2023 21:29:07 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 88E54C04D7 for ; Sat, 16 Sep 2023 01:29:07 +0000 (UTC) X-FDA: 81240727134.05.E60F501 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 15BFC180013 for ; Sat, 16 Sep 2023 01:29:03 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ewsA4HbC; spf=pass (imf06.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694827745; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4qbIE5Sx2G6B9yvMVQiBRk6nSJz0jXl9dCA6L1yJm1M=; b=rjvoiP8kf3RSrYJzgVjVPjCiwHtqNDt8+4BDT6yerTXvVhw02YTdPN41hyZeDJxyCFRaM1 pVA0hdToAq5sdrcY2yy1NsIuErT0HcjJN+1UkVcx5FYTvPDQhErHjcp7rKP2CFt0LZcuHZ g2etvDTJ+fGeJ+SVxsavSkcjoncVmrk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694827745; a=rsa-sha256; cv=none; b=u0m47UVrmqU4Cup9Ed+OBTzNuTZYs529b9c4CUuoF+PBxyIGIPBkEqNMIFY4zETVTVGDUt JJ3AaJuePDamJH3PoCnVnKqyGCwDK74jlge0/QIlyAfnpqegArrQePbu2nSFYePIG9yQmZ 6eAFJ2uTUiTasMN4f7xbzKPW++wOHDY= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ewsA4HbC; spf=pass (imf06.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694827742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=4qbIE5Sx2G6B9yvMVQiBRk6nSJz0jXl9dCA6L1yJm1M=; b=ewsA4HbCDQU39sfU4LDeHJd5iaKfUIwg9niTqaLiTpXuTY7pUkQoNpn8aCtHEUvkK12Z2U oOhwRpbtPVMxPIRr6dENN0JgUZlJ9PPqdOeNeyZZgUsR/3L/J2FBoZmaJqqm5RXH6szUr6 CsA6MPGKSZ1WH2GODJI4GxShtgGuA1w= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-111-Tk3Gc_49MvaBP6egFecfag-1; Fri, 15 Sep 2023 21:28:56 -0400 X-MC-Unique: Tk3Gc_49MvaBP6egFecfag-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D85691875062; Sat, 16 Sep 2023 01:28:55 +0000 (UTC) Received: from localhost (unknown [10.72.112.6]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 05C732026D68; Sat, 16 Sep 2023 01:28:52 +0000 (UTC) Date: Sat, 16 Sep 2023 09:28:49 +0800 From: Baoquan He To: Vlastimil Babka Cc: David Rientjes , Christoph Lameter , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Jay Patel , Roman Gushchin , Pekka Enberg , Joonsoo Kim , linux-mm@kvack.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 4/4] mm/slub: refactor calculate_order() and calc_slab_order() Message-ID: References: <20230908145302.30320-6-vbabka@suse.cz> <20230908145302.30320-10-vbabka@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230908145302.30320-10-vbabka@suse.cz> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Queue-Id: 15BFC180013 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: hxdybe8zbskqpcd43txy81tqohyekq1j X-HE-Tag: 1694827743-617797 X-HE-Meta: U2FsdGVkX1/HweYsmyXs5z4ocvIyLAkjmYJZ/aS22pK3SoBo6ozwn9arBjbN7/kbxN54d75LLwIABSB4ulKkDME/WrO3DebnJtblRyjsW96JaI5YfzBKKjQtD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mZvUOqINSSS04UDyaEYTsj2Q6ukfpxCOnZA5WPuyxqCMPxQyQNsmvikM6kXR6rmuf6nqOJSV8gde/xWoz6WlHkbWz8703/1Azj63e8tfNP3iyxB 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 09/08/23 at 04:53pm, Vlastimil Babka wrote: > After the previous cleanups, we can now move some code from > calc_slab_order() to calculate_order() so it's executed just once, and > do some more cleanups. > > - move the min_order and MAX_OBJS_PER_PAGE evaluation to > calc_slab_order(). > > - change calc_slab_order() parameter min_objects to min_order > > Also make MAX_OBJS_PER_PAGE check more robust by considering also > min_objects in addition to slub_min_order. Otherwise this is not a > functional change. > > Signed-off-by: Vlastimil Babka > --- > mm/slub.c | 19 +++++++++---------- > 1 file changed, 9 insertions(+), 10 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index f04eb029d85a..1c91f72c7239 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -4110,17 +4110,12 @@ static unsigned int slub_min_objects; > * the smallest order which will fit the object. > */ > static inline unsigned int calc_slab_order(unsigned int size, > - unsigned int min_objects, unsigned int max_order, > + unsigned int min_order, unsigned int max_order, > unsigned int fract_leftover) > { > - unsigned int min_order = slub_min_order; > unsigned int order; > > - if (order_objects(min_order, size) > MAX_OBJS_PER_PAGE) > - return get_order(size * MAX_OBJS_PER_PAGE) - 1; > - > - for (order = max(min_order, (unsigned int)get_order(min_objects * size)); > - order <= max_order; order++) { > + for (order = min_order; order <= max_order; order++) { > > unsigned int slab_size = (unsigned int)PAGE_SIZE << order; > unsigned int rem; > @@ -4139,7 +4134,7 @@ static inline int calculate_order(unsigned int size) > unsigned int order; > unsigned int min_objects; > unsigned int max_objects; > - unsigned int nr_cpus; > + unsigned int min_order; > > min_objects = slub_min_objects; > if (!min_objects) { > @@ -4152,7 +4147,7 @@ static inline int calculate_order(unsigned int size) > * order on systems that appear larger than they are, and too > * low order on systems that appear smaller than they are. > */ > - nr_cpus = num_present_cpus(); > + unsigned int nr_cpus = num_present_cpus(); > if (nr_cpus <= 1) > nr_cpus = nr_cpu_ids; > min_objects = 4 * (fls(nr_cpus) + 1); A minor concern, should we change 'min_objects' to be a local static to avoid the "if (!min_objects) {" code block every time? It's deducing the value from nr_cpus, we may not need do the calculation each time. > @@ -4160,6 +4155,10 @@ static inline int calculate_order(unsigned int size) > max_objects = order_objects(slub_max_order, size); > min_objects = min(min_objects, max_objects); > > + min_order = max(slub_min_order, (unsigned int)get_order(min_objects * size)); > + if (order_objects(min_order, size) > MAX_OBJS_PER_PAGE) > + return get_order(size * MAX_OBJS_PER_PAGE) - 1; > + > /* > * Attempt to find best configuration for a slab. This works by first > * attempting to generate a layout with the best possible configuration and > @@ -4176,7 +4175,7 @@ static inline int calculate_order(unsigned int size) > * long as at least single object fits within slub_max_order. > */ > for (unsigned int fraction = 16; fraction > 1; fraction /= 2) { > - order = calc_slab_order(size, min_objects, slub_max_order, > + order = calc_slab_order(size, min_order, slub_max_order, > fraction); > if (order <= slub_max_order) > return order; > -- > 2.42.0 >