Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2468663pxb; Mon, 18 Apr 2022 00:20:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQQZzNGIRviUYxnbNVRSAFh8aUwGftcl8UdXtfSrhBJ7sOvx33A+BzF0BWxNCfEavhflzQ X-Received: by 2002:a17:907:9703:b0:6e8:d248:f8d0 with SMTP id jg3-20020a170907970300b006e8d248f8d0mr8088385ejc.428.1650266440065; Mon, 18 Apr 2022 00:20:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650266440; cv=none; d=google.com; s=arc-20160816; b=GL4zMDWnCYaxifghWrcI+LugWXrkdxYccZ3dLontczw+BXSL8bii3eBHM0z5tg6Em2 dXXiOE/bfJ2GiZSGuB3MEyzpZ408pdfQbzQnpue+GDpkEJCdCsQPZJpxICgHmguyriA+ 2Arzbky+Ivm4ZmQyH2Z5N73vIUTnVMkhzxksvqKvDAMkC+5fKVHR+DmCqWPa1CFwMjmZ XcGc1yBfq32PM2szbxEVXZBblMEyJe7r/T7cGuHPfbvUW2RHfqUWhlpZOlBHOVJX5n93 Nm5x6hFQVL18/lPxHeQ2DE+mmIta1gjVJIUjx9uag2AhvVQMwx4LIeXFwm3SGrrXvVl1 gXfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QHd9CQFIYlOCi6fBEm7pnjqFGa8zbI3JTmRYYQX8W44=; b=Dnjs9K3WC1KeUIbj330ZK96gOCYHzwP8XqKqzuzRvazYnQt0Cbqk5ZGPthj/vFebzw K38Hd3vUeNdWI0FV2TDERizg2JMJnLHwvVyMTIbV2SNPjp+h/wBdcPHyXAR26eERNtpG xZBr0/fchsOmvAIYumvNgKRrNM40ALE0YSJPVerMgVznYqij25VZq1vtjv9zvEc21c3d ZlPwFnSfT909XP1O0iucahfBj5qZZ/DsPufNGFkn1gGvEPq3sAJvUNKBoTnsHwO8Sk5C Vgwjc96dBYSwdD1k8yFN92npdzXth+k/nE6HJliK+6vH6qhWCwj8OQyxVxkNzGHYLcZh fwzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RgOopmUf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o21-20020a056402439500b00423eeb136e5si812251edc.332.2022.04.18.00.20.16; Mon, 18 Apr 2022 00:20:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RgOopmUf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233251AbiDQCJu (ORCPT + 99 others); Sat, 16 Apr 2022 22:09:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231488AbiDQCJs (ORCPT ); Sat, 16 Apr 2022 22:09:48 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C8F731537 for ; Sat, 16 Apr 2022 19:07:15 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id be5so9898453plb.13 for ; Sat, 16 Apr 2022 19:07:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=QHd9CQFIYlOCi6fBEm7pnjqFGa8zbI3JTmRYYQX8W44=; b=RgOopmUfrgVixcUJfSi6UvD4IxlD5NakuaHEXATlspyZ5Hpb7JkBfT6Uu87pVs0YQK 4eLP27IXOtAaA3l2QYgfMBjxrOM+s2EMu0WHurykaTf9KocSc4FMrvPxnHEWFpugwxdP TsYvWgy0yyph1Q2bFOORkdV+D5CFGU3M9t8y0R+NzCWindZkVoCN2WpSwy7UNGDJ5gaD hxfjmeJ6qzuiv61Npd0LT0sAH8IUx3yLep86t/V/m7aHf+yAT8qJOg4KtbZ9eApTHUFz +jrjz5uABJ3CJS2yycto49ii2FP4FSotEzsQ42O32H3hB96Iqng4sBvXviLNqFjUrvqU KPdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QHd9CQFIYlOCi6fBEm7pnjqFGa8zbI3JTmRYYQX8W44=; b=CB/monauhd5ikreGnm3derK2KS0nFpOXT+Lj7OiHM8VfTpQxB0ltjVyQXOO8P4a931 SrxflzRFl9IKY6i5E2vNuGl1iIognDHAfLZo2X1PsfAC1UdKGh4gPnNlxfuK9K8z/bH9 JiME+DvMN/cf+n4kVdmtodd6QwZc94LijQxQwskVpCZytKkiVLQlGkSQEH6mXKBbRZNL wY3QrRkckC71JXxLdxcogpkM5tkytdtm4uYwYcFwqgpD5KB3mR5P1niOXJqaFr11+Vvu 7t5t7tkWzUcdBxkx2/7ofwfTHWf086+YBpZopIERw3dqlmVSLcUesftft4nziMfM8uIP gxaw== X-Gm-Message-State: AOAM530P21bjyslat8usZTUrBdapaH9JzvlAKMnCGizzvbo6nv1X2hJv HHhHGI2WgQjPEKzH4eSVrA0= X-Received: by 2002:a17:902:6bc2:b0:158:a26b:5884 with SMTP id m2-20020a1709026bc200b00158a26b5884mr5616991plt.38.1650161233610; Sat, 16 Apr 2022 19:07:13 -0700 (PDT) Received: from hyeyoo ([114.29.24.243]) by smtp.gmail.com with ESMTPSA id y20-20020aa79af4000000b0050832e3caadsm7275065pfp.216.2022.04.16.19.07.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Apr 2022 19:07:12 -0700 (PDT) Date: Sun, 17 Apr 2022 11:07:04 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Wonhyuk Yang Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Ohhoon Kwon , JaeSang Yoo , Jiyoup Kim , Donghyeok Kim , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm/slub: Remove repeated action in calculate_order() Message-ID: References: <20220416074059.526970-1-vvghjk1234@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 Sun, Apr 17, 2022 at 10:43:20AM +0900, Hyeonggon Yoo wrote: > On Sat, Apr 16, 2022 at 04:40:59PM +0900, 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 0, we set fract_leftover to 1. In > > Maybe you mean when min_object reached 1. > > > 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 > > --- > > V1 -> V2: Fix typo miss in a commit message > > > > mm/slub.c | 18 +++++++----------- > > 1 file changed, 7 insertions(+), 11 deletions(-) > > > > diff --git a/mm/slub.c b/mm/slub.c > > index ed5c2c03a47a..e7a394d7b75a 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; > > + } > > + > > /* > > * 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, (unsigned int)get_order(size)); > > +out: > > You don't need to cast value of get_order(size). max_t() does cast both operands. > > > if (order < MAX_ORDER) > > return order; > > return -ENOSYS; > > For the correctness of the patch, I don't see any problem about the > code. > > But to be honest I'm a bit skeptical about saving some cycles in > calculating slab order. It's done only when creating caches (usually in boot > process). But yeah, maybe it's worth for better maintenance of code. So after considering my comments, feel free to add: Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Thanks! > > -- > > 2.30.2 > > > > > > -- > Thanks, > Hyeonggon -- Thanks, Hyeonggon