Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp203712iob; Mon, 2 May 2022 17:07:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgIzwBNrQkhPExFXRgHmHaL2wbQaQEU34e7IAY6z7zGKNw3hISL+QXwJfWUVyPL1CXAhzS X-Received: by 2002:a63:981a:0:b0:398:49ba:a65e with SMTP id q26-20020a63981a000000b0039849baa65emr11713374pgd.231.1651536461276; Mon, 02 May 2022 17:07:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651536461; cv=none; d=google.com; s=arc-20160816; b=K1YPZJfTZXFprDCvGY7dwLmbjfrVjwNGcAhq/atXD1t5saU75X0i2imKyPkvHDC6X/ wsFMEEZRRjiQQBS8+yK3+IJQN5ls7ZwmIDhR2Hn/l14lxhCE4+v7cGr7Fgzeg2byg6n2 /SPz0akqW/IxyPrk8GDvFjpuz1lUiY5jigYUwH/Hk+DxuplERYPcLOto5YcwcN05erWF ZYeJH9MR2VlX4IG3LtNtvPV8Vn4VSSCXibS4Sm+nD7N4loZ8e1yAiswJUhBGg5rNPV/F FZ2ZzbSylBUjBcEzaWPk/+Wux3xuRaWQrvDeBhA8KbC0UXmuMuCt1b2T9SZX2e6seQCp v7wA== 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:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature; bh=iTKK1xDtnmXAYeBi+dPbi8yteaHw0P2nDeN1SBWNaj0=; b=zefBpkpGff8C6sxxtkJGlTvQR4eV0seXZdmO9FyMeDO08s3MV9+A7wl5WxEXVqLeTF Rpp7+I2ifcebNKMJg+Iu5BqgEyb/oJ+j/SAn14SO1wWt9JPTeNjFB2Iza5tJ0iiLdJQf sI3z39MDayF7nQPMjHa21DsEzRlJr99DEgUCN791+/G+BH5l8gxh7rdThWS/gcrdfwO7 IB8EXbCfUsmdbSi4qZFYIxewNXzyZnsIoSZUmW6rcbnbXUpQP56klsxl821grCfSymdL /QWxl5A7SI0mxEPp1ApG5eIG9lZt9MFO5ZMV/59Wka9Cp+yq36Ne2Ed0tJZt1SQDq9o/ S0dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=MgkEFVOI; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id z15-20020a056a00240f00b0050cff7b2666si15559790pfh.241.2022.05.02.17.07.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 17:07:41 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=MgkEFVOI; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DB9FC1DA58; Mon, 2 May 2022 17:07:12 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384440AbiEBKE3 (ORCPT + 99 others); Mon, 2 May 2022 06:04:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384346AbiEBKEU (ORCPT ); Mon, 2 May 2022 06:04:20 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A17BC2645 for ; Mon, 2 May 2022 03:00:46 -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-out1.suse.de (Postfix) with ESMTPS id 33C57210E5; Mon, 2 May 2022 10:00:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1651485645; 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=iTKK1xDtnmXAYeBi+dPbi8yteaHw0P2nDeN1SBWNaj0=; b=MgkEFVOILNEsJGU7lV+W1Duv+D56s8qcIPD4uiurhbUaI/fFhxuJSLbeXuUPNPmp3T3LwB R8LwQ+czdbKNkckdwJ54YxfupZX0dszqy2x2mwyobcMoRGhMdLOwgVeXLBw9NYfsakApZx MF9gYw0I7LGB3sNLonS1iTGeVvrNLko= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1651485645; 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=iTKK1xDtnmXAYeBi+dPbi8yteaHw0P2nDeN1SBWNaj0=; b=Nj3KJAWkFC19kauBWwlkVq6mk+bTmGIo7dy42UvYuLm4H1AizBwqdlXYcPuTlnjyD92aF5 MrexEt86CBj5ENCA== 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 10CF513491; Mon, 2 May 2022 10:00:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id xXQUA82rb2J9NgAAMHmgww (envelope-from ); Mon, 02 May 2022 10:00:45 +0000 Message-ID: <49b0d611-e116-c78d-cf14-6d5f96ae500e@suse.cz> Date: Mon, 2 May 2022 12:00:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Content-Language: en-US To: Wonhyuk Yang , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20220430002555.3881-1-vvghjk1234@gmail.com> From: Vlastimil Babka Subject: Re: [Patch v3] mm/slub: Remove repeated action in calculate_order() In-Reply-To: <20220430002555.3881-1-vvghjk1234@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 4/30/22 02:25, Wonhyuk Yang wrote: > To calculate order, calc_slab_order() is called repeatly changing the > fract_leftover. Thus, the branch which is not dependent on > fract_leftover is executed repeatly. So make it run only once. > > Plus, when min_object reached to 1, we set fract_leftover to 1. In > this case, we can calculate order by max(slub_min_order, > get_order(size)) instead of calling calc_slab_order(). > > No functional impact expected. > > Signed-off-by: Wonhyuk Yang > Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> > --- > > mm/slub.c | 18 +++++++----------- > 1 file changed, 7 insertions(+), 11 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index ed5c2c03a47a..1fe4d62b72b8 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -3795,9 +3795,6 @@ static inline unsigned int calc_slab_order(unsigned int size, > 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++) { > > @@ -3820,6 +3817,11 @@ static inline int calculate_order(unsigned int size) > unsigned int max_objects; > unsigned int nr_cpus; > > + if (unlikely(order_objects(slub_min_order, size) > MAX_OBJS_PER_PAGE)) { > + order = get_order(size * MAX_OBJS_PER_PAGE) - 1; > + goto out; > + } Hm interestingly, both before and after your patch, MAX_OBJS_PER_PAGE might be theoretically overflowed not by slub_min_order, but then with higher orders. Seems to be prevented only as a side-effect of fragmentation close to none, thus higher orders not attempted. Would be maybe less confusing to check that explicitly. Even if that's wasteful, but this is not really perf critical code. > + > /* > * Attempt to find best configuration for a slab. This > * works by first attempting to generate a layout with > @@ -3865,14 +3867,8 @@ static inline int calculate_order(unsigned int size) > * We were unable to place multiple objects in a slab. Now > * lets see if we can place a single object there. > */ > - order = calc_slab_order(size, 1, slub_max_order, 1); > - if (order <= slub_max_order) > - return order; > - > - /* > - * Doh this slab cannot be placed using slub_max_order. > - */ > - order = calc_slab_order(size, 1, MAX_ORDER, 1); > + order = max_t(unsigned int, slub_min_order, get_order(size)); If we failed to assign order above, then AFAICS it means even slub_min_order will not give us more than 1 object per slub. Thus it doesn't make sense to use it in a max() formula, and we can just se get_order(), no? > +out: > if (order < MAX_ORDER) > return order; > return -ENOSYS;