From patchwork Fri Sep 8 14:53:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlastimil Babka X-Patchwork-Id: 13377571 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 1BCA6EE8014 for ; Fri, 8 Sep 2023 14:53:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1E15A6B00CD; Fri, 8 Sep 2023 10:53:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 191356B00D0; Fri, 8 Sep 2023 10:53:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E887A6B00D3; Fri, 8 Sep 2023 10:53:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B581A6B00CD for ; Fri, 8 Sep 2023 10:53:23 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8E65FA107C for ; Fri, 8 Sep 2023 14:53:23 +0000 (UTC) X-FDA: 81213723486.24.BBBDBFA Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf04.hostedemail.com (Postfix) with ESMTP id 6E17640025 for ; Fri, 8 Sep 2023 14:53:21 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=AErap95n; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=PBQchTCP; dmarc=none; spf=pass (imf04.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=1694184801; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TBS/rfQAa9CuGAOXLs/AG66+kZ+35/pxxXJ2H3zd1io=; b=lvf5ajyMo7BqqNIx2w4A9ObEPTisnrNxjraZbpk7ZOxfQkGFxBlAbYIm61tnQLkxofi+gn cQE6I8JL72iK5+8grUkHP/MusIVb6wSiLIDIyB6ORmmmv5+frAkPctgUnEZXSTs0ESIjAk or5LPjJ39OVHMdnbWXl8dc4UIv9+TQE= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=AErap95n; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=PBQchTCP; dmarc=none; spf=pass (imf04.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=1694184801; a=rsa-sha256; cv=none; b=5YN3wRz+HwnqR2ZsNGDmXGyrDOm8oENhfG7NZwsCCzZV2e59yEO6qaHkxpqgwYqY0IYFzm Nd1uDxIv5ae1PkOVHPZoOK/eh/lROmWsY+DSGwZog79kTqp5rUCU/auszSZ2gTuZy9ztaO ZdRKjoMMrFPobwC1tKjqzzC5CXTPYyQ= 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 825EA1FEFF; Fri, 8 Sep 2023 14:53:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1694184799; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TBS/rfQAa9CuGAOXLs/AG66+kZ+35/pxxXJ2H3zd1io=; b=AErap95nCfprazdQmp9OXffnXycQVwIbGZpHDVA0rP1sASRm6I/cAKuQEAWyQwn3yPrIhj n2us9Yv71zG8n60xarSDoURo97o0UJr6tPpUw1eQl5dNdrsDvGofv7aMgtveGRu7mN2InU ErsEOQVo1bhO94LeTmRRs1dVrdIzL/Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1694184799; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TBS/rfQAa9CuGAOXLs/AG66+kZ+35/pxxXJ2H3zd1io=; b=PBQchTCPYcBZU1rMZMkGvd3jPhMJtIy0CS2wp+p1ullQX6NqzbDhx7UDZYJDCdQdtJKh3v ubVT/MasEOcFelDA== 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 59E68131FD; Fri, 8 Sep 2023 14:53:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iIFAFV81+2QaBQAAMHmgww (envelope-from ); Fri, 08 Sep 2023 14:53:19 +0000 From: Vlastimil Babka To: David Rientjes , Christoph Lameter , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Jay Patel Cc: Roman Gushchin , Pekka Enberg , Joonsoo Kim , linux-mm@kvack.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org, Vlastimil Babka Subject: [PATCH 4/4] mm/slub: refactor calculate_order() and calc_slab_order() Date: Fri, 8 Sep 2023 16:53:07 +0200 Message-ID: <20230908145302.30320-10-vbabka@suse.cz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230908145302.30320-6-vbabka@suse.cz> References: <20230908145302.30320-6-vbabka@suse.cz> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6E17640025 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: h3xtkx14cqfh7rqjf8imhrtadw15qsqi X-HE-Tag: 1694184801-541081 X-HE-Meta: U2FsdGVkX1+cbTcoqeu9x5QTEGtO5kNSg5nd9RUP0gESnHTGre9zO8NtFGrr2+N4QY+30Wq2+VYy4OiFvy1GEN2nWysQ7zWxym68Q8Kpwfn8Yi09U6m5p3lT5vgXpqu+PycRRFk/WoNb4JQWQfyraY+o/bF3xJ+KGW+Gr49sSwophKholO84OPCfy0QvAgVWDY5inR5UjRPwRc37W7Qq/IeiGGnFiKUQ69jKWWreDL2AE1UhhnM3LugupjgeJEJKuznu/eTOzJV0cfdLYwVZBTF/jMvSyfoIuOe5hj7PdvIIguA0pHzTNSvy7chAyKD8dD70EcmE++tBvd4TZthYnQgTQhr9g2fqmNsklCbhtysDs/OeAfoPJwE3aArhum5ma/6921gfwhSAxBnekJahpb6MRAaWog37ffrTk5Ad0Zdao38WJIsHH1FV0VkJgIGDGrlgMW92catTfb1Y8Rw1ARJORJ3XbP8ZMGxmsADJws+ZEiAwTINpJ6J1cqGgylHq6EcqReyXqWai0+SBen1SC27v9Er5l/3j1bS7McFIQsWuq5DvWO5hPo9/vZ96IUOAgxPs98LKVgen6HFYarEOnJfwCRHH37l9oodJjM4uJktGvhKZiAZeFlAgVDHD5+brre/NSdBmniplgP93uAIJK7h+Vt+XLoa91Ha4K/wawcO/C9+SNwQb5xMkmtmGEDFt3vBFoCjp81HMlJNySy8wJLlTHnDB+px/iOJ+NX5MHvlAe3aNmeeCPrF1mmEyOe5ZMUMEhoWqaGfO7ZLZmNz3iAxgNi+w0bH8Bg4A8vPrz5ClM+qMGRgzOoEwOrrp07bxu9Vvn+hs3QFu7xk4xMdhqgSnfJpo+nzCEtR5KQzcZorCxagm7kQgJZgLfqG312fvmwhDXehMABwl9jV1e3cfus2HpmoA0lL+khUyyZKYGdAzFKE4qFKyLgKfHWUsObgcHJmbi5ocrGOad2NnfgT iz9Jnmb1 lSFbdiqtEiywOvpI2LGGt91nq/DEKxTyMydjoG7JO3utfFhoGeqN0mqOfjSEB8x12p47czSoH0Jw8FeIhR8+gcmwHa+UXYD7/RCyIeBlsdm3zaKT0h88fccgphIDTl7jX9igc6tsr1OUaSSc0BPzIGVo3pEkBxw86K+ECfGKSWem/ExK1rMa4IA83NOcyR0DavdRhnyIhP3mQTMeNwD1giEqAWH+V66sprAqtojprDF3+Mz3UQIL0H+QFgciVQprZ6Z8NaLusPzKPAgHZwgK+/3FdMvPn+zu5lf9vdaXBNxPyvVvHEzo2SDAiGQ== 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: 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 Reviewed-by: Feng Tang --- 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); @@ -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;