Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4878516iob; Mon, 9 May 2022 03:54:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuXiO5SC6XL8seeygPSfcrmvkBDSmL+dfLRfm15f+5v337Hv9GrXjZ7dslL9AKF+uGHNUm X-Received: by 2002:a17:90b:1d03:b0:1dc:db97:942c with SMTP id on3-20020a17090b1d0300b001dcdb97942cmr16607203pjb.238.1652093696203; Mon, 09 May 2022 03:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652093696; cv=none; d=google.com; s=arc-20160816; b=yi05+VFhqqz2MzIx4YMyKTaVdCFb43ZQHXWQq3gKqF0b/kxBKau6fGKYJelqWOTN7y /rNghOS/e/mjEDOOzfjdw3K3H8t5kld07ZpM/RbJuU9uGujgFj+p7nVJByrC8UN/Y8z5 AoFIqdAB+VsU84ibX9P3teehpJpxqz8GIZN9s9lMltHh32zduLWI8JMfQw2kPpVkJSll H9bYrCr8Fg6kzZa6wkp1gAMEfXJ+9GGxol37ToDiVA4pFPnL7pSXdY9GEtMFbXGHQ00e rVamsKJqCGyaJOUL269Y3x9jq3rXJyTkmDWED9CzRb87UzY7Iz5vD/jv0feOpZYIccud tFdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=M6N0wgYMD6AvDl9pK6OWMAXj6rVMyYj7BLt9cpbI8cI=; b=dgTXv1BDPo/3+u3V0JBKb+JWks2K9U2AWDtG56r0u7klhpHuAp8CX+EvIyQHrcw7ia dSCO/PQdUoGNvHi8UTwhyrD66/HnXbRXVtOXzBv43BDsrSpY/w4OEAmn/qvzsbcMskX1 WxUAagu7tktZ8aRBu5jOYF9E9ldaXFiDRkNoN9LYabSALs2otcqsIlYe6GV5ppjp9+Fm yht3xfhhFhMbL969fFv2r5whUU2maoDWniUivmI5pdoAdZDos1Bvys+q1L8iKX5CSvfJ 0bDngWFKhrzcWlwy3nAYsOazOtzDkHO5b/Dn2q2Z1b+FX10co5pK+rCpJuCZsa0H4xSA oxTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="GazxP/IP"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h4-20020a636c04000000b003c21cf1aa49si13820198pgc.483.2022.05.09.03.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 03:54:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="GazxP/IP"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A3F4023AF0F; Mon, 9 May 2022 03:11:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236032AbiEIJxY (ORCPT + 99 others); Mon, 9 May 2022 05:53:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239802AbiEIJr2 (ORCPT ); Mon, 9 May 2022 05:47:28 -0400 Received: from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com [IPv6:2607:f8b0:4864:20::1134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B1491756B4 for ; Mon, 9 May 2022 02:43:32 -0700 (PDT) Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-2f7c424c66cso137949937b3.1 for ; Mon, 09 May 2022 02:43:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=M6N0wgYMD6AvDl9pK6OWMAXj6rVMyYj7BLt9cpbI8cI=; b=GazxP/IPUdJpR9ySfbbmwBGpFTShUJw/9vCL34Abf2Vr7lgqLld5QeJSaPKVU3yN5H tCJB++ISaQAxpt1YYsVQhvzwckMc1WIRedMUkF/bDC40jzpslm0Bu5kCkSYsm8ESW9kG 1tUkGKq7mBvOjFHofFfz2UT2WnyQ8bihwqOQRXuqHqUY670z7Gk4SlqFgO20JM5tJU3e MrHTv2oL+M2TzDXxdH8OFHpp2u1AfVvYcYSpZc5tWi9JRQCOimhSdryUm1pSPTk/k1XS GXLnehf/zxiDDuvpLlBwnGJO5BQ6eg6OGIuznFqR99T32qMeF74wtUDTkQVtUtqnFt+L WWBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=M6N0wgYMD6AvDl9pK6OWMAXj6rVMyYj7BLt9cpbI8cI=; b=x17ejPCgXiQjZIDtIkA1IgGUb0XdOOUb3grVePQOPTyH9+9t+QEfbTg6BtvaJpIZo6 nLJKvfdMfVhUncLLvW78idaw6H5zILdeT1FJc+h0pAINH+35Ss3rsYHHyI0VRJWD5/02 TK5ZJ/sqpLTus/n0bE0hxJk3Q7Um9DYRsL9BgGJMEWIrGPmMs1SQJldO+i+yOf8xdT7Z tIs3s/62KAvelq8ua8ZajpcNWWPdXxFYC4AZuh11Wg8lbu+62FWrUWz0aYJiqdWEnl+r oh20O/u8SH7DSJ9pY86FIP5/IHXMw1X05dqDeNkvJJOXMMf55qNqLBRpGMsph4uXlSqT ZcBA== X-Gm-Message-State: AOAM53278JCssgKvPmL775o6MQ6LtSAB2hKiiVIbJpwhuF8IIht38izq ZVslZbb4ovL4YNQboGtcDRsj71t+ZF4VB/v9ors= X-Received: by 2002:a0d:d510:0:b0:2f4:e202:2d9d with SMTP id x16-20020a0dd510000000b002f4e2022d9dmr13462464ywd.237.1652089372220; Mon, 09 May 2022 02:42:52 -0700 (PDT) MIME-Version: 1.0 References: <20220430002555.3881-1-vvghjk1234@gmail.com> <49b0d611-e116-c78d-cf14-6d5f96ae500e@suse.cz> In-Reply-To: <49b0d611-e116-c78d-cf14-6d5f96ae500e@suse.cz> From: Wonhyuk Yang Date: Mon, 9 May 2022 18:42:40 +0900 Message-ID: Subject: Re: [Patch v3] mm/slub: Remove repeated action in calculate_order() To: Vlastimil Babka Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,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 Mon, May 2, 2022 at 7:00 PM Vlastimil Babka wrote: > > 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. Yes, I agree that checking the overflow of object number explicitly is better even if it is almost impossible. But it checked repeatedly by calling calc_slab_order(). It seems to me that is unnecessary doesn't it? > > > + > > /* > > * 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? That's sounds reasonable. When it reached here, we don't need to keep the slub_min_order. > > > +out: > > if (order < MAX_ORDER) > > return order; > > return -ENOSYS; >