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 0F744E7D0D2 for ; Fri, 22 Sep 2023 07:00:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9AA6C6B027B; Fri, 22 Sep 2023 03:00:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 95A8F6B0281; Fri, 22 Sep 2023 03:00:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 849436B0285; Fri, 22 Sep 2023 03:00:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 773516B027B for ; Fri, 22 Sep 2023 03:00:50 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1AD151A0942 for ; Fri, 22 Sep 2023 07:00:50 +0000 (UTC) X-FDA: 81263335860.22.32783A3 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf26.hostedemail.com (Postfix) with ESMTP id E8934140006 for ; Fri, 22 Sep 2023 07:00:47 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=mpg0WKy4; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=3RPCloKx; dmarc=none; spf=pass (imf26.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695366048; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hzC90i38T7FBA12FfFnH5tEY2/bPD5iOP/QAXB6HLew=; b=CmmvAqZTvEbpPNdqKQN3YfqEpQv4NKHEuFF/8ohge+GWNjZlaqS0/eOjL3AusobezpIPKf 9qqpg/oK4CR4LNEVj9RCzMJija8Y8q8uFUf/VHhr411Ky0LBw7Wmq8Wy8k/SxxWHGWc0D4 XkLjJb8iRQ8PcvCG183c9J/8hLHeagI= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=mpg0WKy4; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=3RPCloKx; dmarc=none; spf=pass (imf26.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695366048; a=rsa-sha256; cv=none; b=6urEi8kKK1AJe+VJ7i6eMcmnPKPi3R7hxr2NShb/L97Otn75MmGS+CL/i7rCSCIr6IFpTz j2cdMjAzUGNF/vEM/sU5ZY+E2qoo5m0Yo4BPGIG0IRW/o8hXD8+IC9jgwrBSJ3qACcUYLO 80M/J7OZW8yDt075pUnYSRTIKnVHKp4= 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-Rspamd-Queue-Id: E8934140006 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: isrjejgprxt7g7ynwwzyo6kjswx8o4bi X-HE-Tag: 1695366047-368763 X-HE-Meta: U2FsdGVkX1+Mu2a3ArrEuSnuCHMrcUKcWjabx7CBzcxS+zgzfnPaIX038qGFQUy+0FnTG2JCY/iBXFbDoyu3fvrEjuih4w8ohkTDuMMpb4PavImyZj/r9pGZE3yb3v+snUe9Fx2Eyp2ZCx3FrcCa+Ece4YbCcXrkXLSJfp5Vif757DCvPPBJSWVpS3N38RE9vlM2iPyZ0MAExnWraAM+KKJLqepZQC0CzzNh+elU2nW0IOK4bR49hBSDUKJIEzqhV1qOQBLy/ZaqLmV003IOQD5HP44uEnNkmvxAAq1+XzmtjIPbT4zXymPJj3/hZu+pxPe7XvJ+KrUyumZ+QCEU8p+3aqPyuVRdC1K+HQqOMrrJeFxeXP8laHc//EkbXvOjuQuBf94y7Ov5JgmOQt/lQdBz4LCYeBAXB2R6FEsYIqRJxaVPXuZgc4tYwy6gqn5FTk6Iz4cl92MHX66GgmHqnqLbdoZwU+0CJuytfUVd17AMChsZeiCMlqPkOXjcpsXxmFMCPj+Xxms8rMY57umr2ZbkDnptRKVJbhLtOwD9Flm8i6rWWnK3SAuP8lfBB5ga1YwFam24h0dSBHQbTNn/po23oOCB2qdIoVotXvVlwbKAhPc0gOPufdS19YysjwHSJBWo/arncbDRgIgHstAK6teq/WHD1ViPGrGFu9SawmimuO/ntg3LVufid10AoAhRMJpZhaGgsvMeIv+/rDysFSwkPezvuHYZY/8uNbIZhRp/tmhDGfAGboZPsTRfiFg4Xx2FeNsWotMn2kQERaDUwpAZ3eoyEcv/zprbcDP34SeOjh6ttv8NOtHWwmwoukHzVweqwvEcnXc2qMwadRHyEWlwH0Ht1X1XgRpdgimYGYd8Th9K/+a4DH9yjiqwF1L1PEYAxsCOMNbR1Kvdf2EJnVJ2EKzcqhl9ZUejl8tl0iZckGdYu/sVeMC84v8cGeX/NUkECsH9HkGxSy35mil JGpXCo3V EvLy/qyf5vYm7k2ChLPMPynDCQeiW+rfWXyRTaQFOX24FStlx48gRmRvOK9ivNF3CAARtez3+NNjydXjYpG3aT6065Ln+4QVFkD7uQXr3d5SPRXLExAISN72kcivgbY5YwDkYBve7bQqMun37lijZDiIQP1sKVJdT+Iob29ij/mEYdu5zy9wPQmibhLDs5TQ7qfcRIb8Y0qaUc+O44kwIP85J6KkClxcsnoWcMh4G401oFfmCmZfRy3IhIW0LEVj+ZN6hV2ysmBaYuNeRFBHM+oB1Gu/64fbwOr/CLKgdBAl3jm4fksg0Hn4imZhJAi03Vqc9 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 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 >> >