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 A1ABCC433EF for ; Sun, 17 Apr 2022 02:07:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B8D2F6B0072; Sat, 16 Apr 2022 22:07:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B15936B0073; Sat, 16 Apr 2022 22:07:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98EDB6B0074; Sat, 16 Apr 2022 22:07:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0031.hostedemail.com [216.40.44.31]) by kanga.kvack.org (Postfix) with ESMTP id 8422A6B0072 for ; Sat, 16 Apr 2022 22:07:15 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3040AA5A6D for ; Sun, 17 Apr 2022 02:07:15 +0000 (UTC) X-FDA: 79364733630.28.EA651D6 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf07.hostedemail.com (Postfix) with ESMTP id 8E75C40004 for ; Sun, 17 Apr 2022 02:07:14 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id n11-20020a17090a73cb00b001d1d3a7116bso1909846pjk.0 for ; Sat, 16 Apr 2022 19:07:14 -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=08MfkTLEldJLUlaD/MdgyoPx0uF1VQacTsGqIQwI10GeKOYLWmiaj6OMwjJJmnK82W otZWu3ierTGZ2Ii4IOCCIurziU21xw0PnP8BPSj1EIy5HhNcyRlzkVIQw4WvHJZL3Qao EAjRXWHajmFtrfgOXfJvjDvv75lJ120mRZyOhyP4o0AHB1HuY8MiH3eMp6XOQDK+rjXt oTwRzVGISuOqGyKoVXuYThMh25e/T9D1wttsaYk2GmU+6loXZstgMq8OST3QtXtF6DhL ts4uKEdID6D2FFU6W7P+r/hWdeeyAv/umEf77KnjVvi8gQpgpwaHjyLRxCdsuQX7JCws FlFg== X-Gm-Message-State: AOAM530u/UCP35FzgoqLDfkuzLWlcbNzpXzAhEOg/2KiLopf05EwVU5D SHVBfAKFDSsPCS2qNdBXlZE= X-Google-Smtp-Source: ABdhPJyqQ+TKMVoT2fZeDnbZltdybRQpDs17aA6HMgvlJZOchOADOShcBVERF4ZK5loqxJ5PEWMpFw== 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: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=RgOopmUf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf07.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 8E75C40004 X-Stat-Signature: ynq9p37ajwr49bhi6p44rssfzu7ekkef X-HE-Tag: 1650161234-991112 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 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