Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp596651iof; Mon, 6 Jun 2022 09:07:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFUIT6m3fqleP4EbnaI7u/x2KuTdFjeB/CL3eHtlI01MdiQ6eSq+XVXcj4+ihQ6pcdiN10 X-Received: by 2002:a17:903:2281:b0:167:56a9:9359 with SMTP id b1-20020a170903228100b0016756a99359mr15390737plh.126.1654531623534; Mon, 06 Jun 2022 09:07:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654531623; cv=none; d=google.com; s=arc-20160816; b=qDwLzl3Sgor8XUXMqPVsJTWxfz6C4KtvIRF/doAhk2fhHsi5djaykVif7vFYls2Q5D GJd/6aKCCSlAY5S9WItbRbG8ECMu390eCxFZmT1X1iAIAwM1MHKqUHK1Cqor1mpDLfIm DJFLUrSciytkXevHIfj0nhbN8i2Wau+jhVHtPGX+hgCIfH7CTL8ciuQEAR+42QKdk64O FR6dAPXOEnC1sor1Cn3/fo9h5Ebyz4wiKT0F0Tw2pBz60OZfvTJMMSIiMRUbBjQT0LBR ZUUd286+Yee/NpGm+o3QJBsAVW2/M+J4sChlf4Jw7bIuHTkVjSl4k8DJjMYBYoxJWMis YXyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Hc9viEeZffCjBHu/ML1+/iUUNsF5FvYmtO3dN3G4Vlw=; b=eloMBJynMHtztBiyaWg5NNGFb8X5JY/Se6ksF4kc1w3b06jeegaqUW5V94b2X/l7VR h/jWD6W+JRRDva+4fOHqaKmu011UgsQ63y/jy5d2NlrlCRRVFX4tVI5wwDWt/mZAn/rK lj4ouy/gdWJTWU6MNs3nGhh/Z3N5OU7k1wC92zRPdKIJ0AebyVWmxoJG718egIDBpHis +IqcOFk5LcII5Nho98F6xkQ3edUmMKLJ5hWkDK0RDGwaR6s71W4aIjqd+G4zgyfVyJkq qzMnisVcxX73P/iRX0rRmYsNi8MZrwCxfSMFvz9dEWTi9aBV79iKCgQ6i3CydWBviVIa +xAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=kbPUnQSF; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d14-20020a056a0024ce00b0051b97c12336si5073695pfv.376.2022.06.06.09.06.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 09:07:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=kbPUnQSF; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E234E220FEC; Mon, 6 Jun 2022 08:51:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241267AbiFFPvy (ORCPT + 99 others); Mon, 6 Jun 2022 11:51:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241261AbiFFPvx (ORCPT ); Mon, 6 Jun 2022 11:51:53 -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 8E155221683 for ; Mon, 6 Jun 2022 08:51:52 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id o6-20020a17090a0a0600b001e2c6566046so18237401pjo.0 for ; Mon, 06 Jun 2022 08:51:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Hc9viEeZffCjBHu/ML1+/iUUNsF5FvYmtO3dN3G4Vlw=; b=kbPUnQSF99ZlyPwWnFMWPsmmeT5+u0GJl+ZGFTHeabKhMFFeDRnUeKGX3JhCSS+hY6 mMfS+PHJ9L5E095xRkAohdPXVJwDroRWIBlASitwNX9a3jAGrfYMSSDkqKcyUbDVXCul ruha7NS+uXWnUloG+ofrs0oYPnaI0Fp6cI5tGm0Va2Uh4gfskz3KLuwZksl4j4bc1Zai wppoYfumXRwL8ReXNQASidHso1uJrq1qx/g0f8or/mvDaG/HeoWDn4tbBUni0ZINeS3a IuYpHsffUxWApkozUXTvNEmul9Mwkyx//djSdvkunrnGH+v4GAJzi2f2WuINB6WhIKZs NydA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Hc9viEeZffCjBHu/ML1+/iUUNsF5FvYmtO3dN3G4Vlw=; b=aNtUz2jv4Pn6jAb6MhosC+3UDzzr6/CWr9aXnwi9YbTge7InrbQ6vAL0NU7MkKvhcR qCoUUHpFkJLWvEuICpYYy6cPEKHEN4NLyChGH9bv4eMGjAf5cgbN3hlX6/QWKqGXj3XV WS0vCh2M5eyJVXGt+aNbH/Ht0BnaD5wKYwjzkj8suZuzQV14Uz7R9Cy9SPccqw2v4FeD xAmOlAJGu5Ydb1/zFhzoyMLJFkvXMGI31yZSBp4kt1vl6Mq6PO5LHd3RVCZYV1CGmYcs 1tNmkXAJ6otmFWwqQYcGjvv1FTc/IVh/o9aXEdfP53eGSp+dJ6t621g2ol+MgbhVCppq 0FMg== X-Gm-Message-State: AOAM531iquANNIaWLj+kT9bLacDaU2d1HQYIIA1cDnoFedvDY6q6jwJ4 5WPbfYAu4teqvn9o/arvryyrNA== X-Received: by 2002:a17:902:b908:b0:163:e462:704c with SMTP id bf8-20020a170902b90800b00163e462704cmr24524551plb.145.1654530712020; Mon, 06 Jun 2022 08:51:52 -0700 (PDT) Received: from C02GD5ZHMD6R.bytedance.net ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id be3-20020a170902aa0300b001624b1e1a7bsm10941011plb.250.2022.06.06.08.51.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 08:51:51 -0700 (PDT) From: Jinke Han X-Google-Original-From: Jinke Han To: tytso@mit.edu, adilger.kernel@dilger.ca Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, lei.rao@intel.com, hanjinke Subject: [PATCH] ext4: reuse order and buddy in mb_mark_used when buddy split Date: Mon, 6 Jun 2022 23:51:25 +0800 Message-Id: <20220606155125.73990-1-hanjinke.666@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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-ext4@vger.kernel.org From: hanjinke After each buddy split, mb_mark_used will search the proper order for the block which may consume some loop in mb_find_order_for_block. In fact, we can reuse the oder and buddy generated by the buddy split. Reviewed by: lei.rao@intel.com Signed-off-by: hanjinke --- fs/ext4/mballoc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 9f12f29bc346..c7ac6b269dd8 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1933,6 +1933,7 @@ static int mb_mark_used(struct ext4_buddy *e4b, struct ext4_free_extent *ex) unsigned ret = 0; int len0 = len; void *buddy; + bool split = false; BUG_ON(start + len > (e4b->bd_sb->s_blocksize << 3)); BUG_ON(e4b->bd_group != ex->fe_group); @@ -1957,12 +1958,16 @@ static int mb_mark_used(struct ext4_buddy *e4b, struct ext4_free_extent *ex) /* let's maintain buddy itself */ while (len) { - ord = mb_find_order_for_block(e4b, start); + if (!split) + ord = mb_find_order_for_block(e4b, start); if (((start >> ord) << ord) == start && len >= (1 << ord)) { /* the whole chunk may be allocated at once! */ mlen = 1 << ord; - buddy = mb_find_buddy(e4b, ord, &max); + if (!split) + buddy = mb_find_buddy(e4b, ord, &max); + else + split = false; BUG_ON((start >> ord) >= max); mb_set_bit(start >> ord, buddy); e4b->bd_info->bb_counters[ord]--; @@ -1989,6 +1994,7 @@ static int mb_mark_used(struct ext4_buddy *e4b, struct ext4_free_extent *ex) mb_clear_bit(cur + 1, buddy); e4b->bd_info->bb_counters[ord]++; e4b->bd_info->bb_counters[ord]++; + split = true; } mb_set_largest_free_order(e4b->bd_sb, e4b->bd_info); -- 2.20.1