Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2384242pxb; Sun, 17 Apr 2022 21:07:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwXea7pqRrh0AtOvZw5p3xg0d3b+aW7wKdI9iOZh/ka/UhuKve+2IaINcczl1yf3cYh8Ds X-Received: by 2002:aa7:8a06:0:b0:506:28c:1282 with SMTP id m6-20020aa78a06000000b00506028c1282mr10197580pfa.19.1650254825728; Sun, 17 Apr 2022 21:07:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650254825; cv=none; d=google.com; s=arc-20160816; b=aENIqJoV38JCtMJH3OPrWC+ta2f2AVK8nPau7l67gtmG1k5DO99UB1UPp0zpDuHsQU f4Qzt3wmGQ75xMOYIKrYbtwxlFHVVT5oivOsd9D9mlWI3WGsLDOpZwtafgu5iPzlAVvo x1lm8YSQMW2r+a3saZ5OArp0Q3YN8zLnExUcqJiQA9v+UW2zJhV2qtvJ6HxUFnkz5SSI s9BvISL4LQsVBmmAFKXaxc+dL1mRz6g77slVIyAITMwz00//tMOmXrkJJAeBsOGjxtyJ CWN4PXqyfwB1ltnXRxBYExYGBvkCn7mCeXJ0SAu2a+j0xJG6pEHa/ko2kcx5J5evSpPY n7Ig== 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=YGLhajMrQZ0HNv4gi0NLxOpmUqsJjdy2hqp78V6xiwY=; b=07ohQ0Bosz6caHXaIC5GxgUchOycpSvpH37JLs38nEUjTxw9UW9327KTTPwP0PWPh2 ss7tuLKzdaYzdxHJlO+W8KgcMYmTNhGlH1iH7bPuxOPX/mSFb1LwoLXp0SwIPy2/rTbs pm5KlnYyTuAyxALjxWhfEahmcQo/7WMJzjQze+DrWnywvOjb8x/XXlfOIT8GUH6eVCce ISTrgDv8Ae9qFOT8q3D0aW2AjxeVHkuXt4bSQGbYqk5vGPGrta4QofKH3dQP1tChLsUM JPmdWuEDmxAP7UTXV1XFI5suA2vS2fi7WP9Jcp2o1lK0C5rNBmbe3qxk11D4SrILcwfz N7Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="g//V0jsc"; 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 v11-20020a1709029a0b00b00157110f1b48si7077481plp.229.2022.04.17.21.06.50; Sun, 17 Apr 2022 21:07:05 -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="g//V0jsc"; 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 S233200AbiDQBqI (ORCPT + 99 others); Sat, 16 Apr 2022 21:46:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232729AbiDQBqG (ORCPT ); Sat, 16 Apr 2022 21:46:06 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B372B1EC66 for ; Sat, 16 Apr 2022 18:43:30 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id u5-20020a17090a6a8500b001d0b95031ebso4352865pjj.3 for ; Sat, 16 Apr 2022 18:43:30 -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=YGLhajMrQZ0HNv4gi0NLxOpmUqsJjdy2hqp78V6xiwY=; b=g//V0jscMI2Iyi2QAQ+PFI2DZw+WBUeb1QJwsZJbLNu7fgV9Th/w+uwsLB5E7zAhI9 yygUNRHTbNBt9yDOep7SnjvKtg6Cxe0AqZfDkAQyNJeICjR9ZhWWkbLaLap1N3oSdA/+ O1bkxjJuTmaRSzucphnqxJfqfZPkKUmiLat/pdTy+TTaI5ej/z60OJI8OcDXAFiElWhl jDaXE0XACzc4ZlmZ0S1/90AjwKDyiGbelicBz08DAlgQGBbDIblDSU5uQ4w3i4/k9OCq E5UrugBJ8OSw5OOfy2KSzL6fZaWqLXeMY6JwXoVK8HdYmbUsovmdAzpTn9CYOWrfzEFj NLqw== 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=YGLhajMrQZ0HNv4gi0NLxOpmUqsJjdy2hqp78V6xiwY=; b=FDYLbDPGSXqqYKnMy720xwSNlvO3X8iG2PQR1kVOrs14KcRA+ny2j07+yPV9VdeIVr zVyOqJ7DHPNMyi0equN+AsEMAAag/djpKXsKbS+FwsxNS94wma2KVfntfBkpwMeLeL3N GpJtVwhDVPT+1DVsHADAC+AK5ZrJ6NIPm57Q9lXxcA2h7IbzaxBbDwMPDHlk4OFcZiXy tCMmymFnsv5YjmJDG7xcEdauHnwHLhVkaPveplzjKX8nWBsBSRswjr6SMT5s58UY0x7Z NVRiNc0v5ZMUldu/eQ7ya520G6Qy0KkRWpHOUpZVxwOCWeNinSKRAle2rz+6KhoH59cw iYTA== X-Gm-Message-State: AOAM532QoDLNgfWp+AK1QSPXbqsMwFRbw9r/gNE8VxG1Ag+Az7O/apQD eJ+6SdqnXOSG7UGoXfTIodg= X-Received: by 2002:a17:902:ea0a:b0:158:acff:ff89 with SMTP id s10-20020a170902ea0a00b00158acffff89mr5593131plg.88.1650159810180; Sat, 16 Apr 2022 18:43:30 -0700 (PDT) Received: from hyeyoo ([114.29.24.243]) by smtp.gmail.com with ESMTPSA id u25-20020aa78399000000b00505f75651e7sm7049105pfm.158.2022.04.16.18.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Apr 2022 18:43:28 -0700 (PDT) Date: Sun, 17 Apr 2022 10:43:20 +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: <20220416074059.526970-1-vvghjk1234@gmail.com> 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 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). > -- > 2.30.2 > > -- Thanks, Hyeonggon