Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2558998rdb; Fri, 22 Sep 2023 02:04:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZjqEVOYjdeQnLzTm8OXwg2+wtt5itfCuJ8LFyT/KwX1wS2e0tORr8IkV5z3C8q5WIwHaW X-Received: by 2002:a17:902:e812:b0:1c0:7e86:4f6 with SMTP id u18-20020a170902e81200b001c07e8604f6mr8938085plg.14.1695373456723; Fri, 22 Sep 2023 02:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695373456; cv=none; d=google.com; s=arc-20160816; b=RI9aTstOCwZ3gWDskdEqqJNtcx1yXP1OtnT+tcve6zgibcgrOVTYyJSzYkXFEj5Jv1 juhLsuyNEI+w1R90wvf5j6am7+s54RzpW1O3/4HGBal2ACX8+XcuuYC4dOZKUBYyN8Nb /0X6MQlHbvyGBIJRa/nqsE8OmJdiY7q2mRSD0StdKxOJrreInAAmlv11Jd+iP0WpB0kd XwVi95LbQFotX/2NJMzT4cy3E++pHUw+58+q3pYeHcUPbmwamKrm2NogZFmLck6sQnso GLSQMBFSLVo6KGtGC9+QAqIDrNKsmt/yXRyDFS/OhLxgwwtWuuhY0Lk0Zg66aacNmazB +KUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=hzC90i38T7FBA12FfFnH5tEY2/bPD5iOP/QAXB6HLew=; fh=UB/yUW8LKZBJ7ZTY0dXd1ai7Z7c9cuG9ebJPTEeVq4k=; b=j1dJXH+SD4uymk9rgADJU4c4YfWfHkDMbXjiBRovVXio9EXbRxxhFdfdYSeIMPoquf 22Vti+JSt3rO65hjUFEpfMfaOyWgXuECBOb6KlTT87BK3g6tlp1UVGkf4Qnqvk5U7tB3 rLZujqfrvIjZmleBsmerhc1m0Uguy5PzGeXf/B5/jya+5mpFHcmaaJbODIiu6Ql/W9H5 6A3KkHYj9YNbXUGTtR7pUPvbHE5dDI9iQff5nzXnBB2jS0o26dcTgEHjqoiE/gwMq6f9 GBsHViXMmuvtjqgb4IhHcKZm2j3cRZpTot4lgz/dYahETDPZZ1kd9Dvnv1Su5EFcSCMy RzdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=mpg0WKy4; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=3RPCloKx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id q5-20020a17090311c500b001c3fa95ca18si3584660plh.333.2023.09.22.02.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 02:04:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=mpg0WKy4; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=3RPCloKx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 7864A8067A44; Fri, 22 Sep 2023 00:00:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230036AbjIVHAy (ORCPT + 99 others); Fri, 22 Sep 2023 03:00:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229623AbjIVHAx (ORCPT ); Fri, 22 Sep 2023 03:00:53 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87B41192 for ; Fri, 22 Sep 2023 00:00:47 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 05D031F38A; Fri, 22 Sep 2023 07:00:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1695366046; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hzC90i38T7FBA12FfFnH5tEY2/bPD5iOP/QAXB6HLew=; b=mpg0WKy4e1LNUZ0O9RZBFgZG3LRiQOVOUFzGi6eudHfJf9xRXvkb2CNXkH9uupPBn1ZTsD WFyB8AqhoFCyBU9CMTq0ETaSWsu8quH+ekQNv3ufMj+tKStXqHrxFSIpSJPA8rB3Y1RFCb JoXkpHvkpxw2Uj5oLlWN0v2UyLUIUi8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1695366046; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hzC90i38T7FBA12FfFnH5tEY2/bPD5iOP/QAXB6HLew=; b=3RPCloKxh+Kl7Ij3jJpGTh4ew9VIdNDrcsxKs54eoWzjDikCQ5hmvisS4iQg7Jr3CW8HDa 5m5Ed1ULPIj9mvCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CAF1813478; Fri, 22 Sep 2023 07:00:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Y5vCMJ07DWXjEQAAMHmgww (envelope-from ); Fri, 22 Sep 2023 07:00:45 +0000 Message-ID: <4662588e-fc8b-1854-57f8-d15e08a3c368@suse.cz> Date: Fri, 22 Sep 2023 09:00:45 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH 4/4] mm/slub: refactor calculate_order() and calc_slab_order() Content-Language: en-US To: Baoquan He 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 References: <20230908145302.30320-6-vbabka@suse.cz> <20230908145302.30320-10-vbabka@suse.cz> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 22 Sep 2023 00:00:56 -0700 (PDT) On 9/16/23 03:28, Baoquan He wrote: > On 09/08/23 at 04:53pm, Vlastimil Babka wrote: >> @@ -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. Maybe, although it's not a hot path. But we should make sure the num_present_cpus() cannot change. Could it be e.g. low (1) very early when we bootstrap the initial caches, but then update and at least most of the caches then reflect the real number of cpus? With a static we would create everything with 1. >> @@ -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 >> >