Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp49233pxf; Wed, 24 Mar 2021 20:37:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxk3lkrDn7Vhym6KJAAXSqkigrsyvHLOIltHy5Fky5K4FI79m1f4uCa0lhJPAvlUaGbbxj1 X-Received: by 2002:a05:6402:35cd:: with SMTP id z13mr6815385edc.21.1616643431715; Wed, 24 Mar 2021 20:37:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616643431; cv=none; d=google.com; s=arc-20160816; b=GdvrrdjFaLQt47/S+sckclCmMnlteYrrHMveo63P/FX2Fet0FEMHqozkh9ca5CQX/v +DARUYTLjTy4efbkaKv+zz68hewWYyI+CMgHvJC9XIidb0v2yFIayz5VzsqiyZGRZ6WA s5CNBRVKLFe93KCkTSvHm1x6MhGPyO2YMb/8BHGOY7vVPsmC6Kl98d45Ei9ULRtgvvfh lHmh0pz3azf0BoFFJsp1VwYsHzQ0oOLVeWhLNXSZHw3aGmsJOyGVCSBlroJKTN7M9fNj 4LKhARic6dwUYIyRKz9r5pKcS8W2sEXR4JiPUwvDBu8fRnspVuOUM3UJ6mhUASl4L1wP ju7Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ElMJ7bjXqaQdzuOQnFsg0ZG+tTn3DsBAWPK7hzq2d+0=; b=uPGMaK9OrHnEkmmeN4R1VIpMCB41hmMqpZnZqrQ4w98oYYJ0RDpYO+/+Q4gdtsVRL9 sebPhymXY6eiMXfPo3QWa8s18i36c+8WeQowmO8C/Nf6xL21raFV6dyHvJKf+VtQreoQ 5jhIPrU3QmBzwcdhNK962hX0GFcTQHPXBwUHniU5KNUUaBJS4O59op6fIROrcOYvv3Eh BRcbFZwagelfWLRYtXBcXNlD2M6GxppHLommp5y5hxg2QW3lG7vnwlvIlp4kbLn37SBE qyj5Tw18EbDc3tHmryLjo7Eb2F/OrjBUT9c/+skGAKjmBtqbQDLszeLd1EUAUwTf23K4 BBLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bMXF6Q30; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o13si3159246eje.367.2021.03.24.20.36.48; Wed, 24 Mar 2021 20:37:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bMXF6Q30; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-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 S239028AbhCXXTg (ORCPT + 99 others); Wed, 24 Mar 2021 19:19:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239022AbhCXXTd (ORCPT ); Wed, 24 Mar 2021 19:19:33 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07474C06175F for ; Wed, 24 Mar 2021 16:19:33 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id 11so49311pfn.9 for ; Wed, 24 Mar 2021 16:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ElMJ7bjXqaQdzuOQnFsg0ZG+tTn3DsBAWPK7hzq2d+0=; b=bMXF6Q30GU7fZH8Wk7H1TfNIbhOWjwZZglIqlASYeLcu7KnLlxN3j3KcSdv05iGhhh vdc6q6X9Cd4ng0RGewSGyhuSpmSL2lrpHyDXclnsLC+zbmgSRpkG0lCCb1MeXXJT6LeK SIWHDD7uCVhW3T8zjoaZOrAZMB6pSbVoGN19R+88IkXnOtiAtT1OEnHdWS1fa2EaZ96z zY1pM2wVW2pz0J5tnuxNxYU03ttXDqZeludYHMrN2xceovd9ClzWeYPKvwrWMUibYDbu 2Gl47fyZcJB8ynjI0HAAnEjGenYDCe20XMdec2QkOLM8mDDmSmADIboeSrNR6L9iL0QD nN3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ElMJ7bjXqaQdzuOQnFsg0ZG+tTn3DsBAWPK7hzq2d+0=; b=iZygXRz1M07SZ+KOus7c9CGh2QLpHzJUvmyR71mAfKQkNjp8bp9lD+zjcdhvSOdDg0 28wrXQIqlS2AB9Qd3u1q/POkP3evxA/nkgn1QPqiUgMiLizbqy79J0HSty04HqInwj/M szB+M8uy6TXpNSjasZbtmglifCLC866EZ+fouWCbxtc3cX7ihml/lvblxqL95+X0e37e 4DIq2GJJShdNEwwTQAVQY/ObWiRttr6DWiQL+J/R0wHh7OfYkkGBcimEt/h6+SPDAi4g giUa+e+GxHfjE1DFUhP4NVMMQMlbGLn512oICqHJRuJmVDw+JGC/wI14NvFY55QN6cq+ n3Vg== X-Gm-Message-State: AOAM532oDuoBsxFn7a9fh3c9IrAMTXA7bDu6ofKoWAHQksyTHQT9Hll1 E/EzQut0QfK7WH2aFM6XgJqdKbaYuTM= X-Received: by 2002:a63:3e06:: with SMTP id l6mr4892681pga.140.1616627972173; Wed, 24 Mar 2021 16:19:32 -0700 (PDT) Received: from harshads-520.kir.corp.google.com ([2620:15c:17:10:f8fe:8e5d:4c9f:edfd]) by smtp.googlemail.com with ESMTPSA id z3sm3629928pff.40.2021.03.24.16.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 16:19:31 -0700 (PDT) From: Harshad Shirwadkar To: linux-ext4@vger.kernel.org Cc: Harshad Shirwadkar , Andreas Dilger Subject: [PATCH v5 1/6] ext4: drop s_mb_bal_lock and convert protected fields to atomic Date: Wed, 24 Mar 2021 16:19:11 -0700 Message-Id: <20210324231916.2515824-2-harshadshirwadkar@gmail.com> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210324231916.2515824-1-harshadshirwadkar@gmail.com> References: <20210324231916.2515824-1-harshadshirwadkar@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org s_mb_buddies_generated gets used later in this patch series to determine if the cr 0 and cr 1 optimziations should be performed or not. Currently, s_mb_buddies_generated is protected under a spin_lock. In the allocation path, it is better if we don't depend on the lock and instead read the value atomically. In order to do that, we drop s_bal_lock altogether and we convert the only two protected fields by it s_mb_buddies_generated and s_mb_generation_time to atomic type. Signed-off-by: Harshad Shirwadkar Reviewed-by: Andreas Dilger --- fs/ext4/ext4.h | 5 ++--- fs/ext4/mballoc.c | 13 +++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 2866d249f3d2..cb0724b87d54 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1552,9 +1552,8 @@ struct ext4_sb_info { atomic_t s_bal_goals; /* goal hits */ atomic_t s_bal_breaks; /* too long searches */ atomic_t s_bal_2orders; /* 2^order hits */ - spinlock_t s_bal_lock; - unsigned long s_mb_buddies_generated; - unsigned long long s_mb_generation_time; + atomic_t s_mb_buddies_generated; /* number of buddies generated */ + atomic64_t s_mb_generation_time; atomic_t s_mb_lost_chunks; atomic_t s_mb_preallocated; atomic_t s_mb_discarded; diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 99bf091fee10..07b78a3cc421 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -816,10 +816,8 @@ void ext4_mb_generate_buddy(struct super_block *sb, clear_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &(grp->bb_state)); period = get_cycles() - period; - spin_lock(&sbi->s_bal_lock); - sbi->s_mb_buddies_generated++; - sbi->s_mb_generation_time += period; - spin_unlock(&sbi->s_bal_lock); + atomic_inc(&sbi->s_mb_buddies_generated); + atomic64_add(period, &sbi->s_mb_generation_time); } /* The buddy information is attached the buddy cache inode @@ -2843,7 +2841,6 @@ int ext4_mb_init(struct super_block *sb) } while (i <= sb->s_blocksize_bits + 1); spin_lock_init(&sbi->s_md_lock); - spin_lock_init(&sbi->s_bal_lock); sbi->s_mb_free_pending = 0; INIT_LIST_HEAD(&sbi->s_freed_data_list); @@ -2979,9 +2976,9 @@ int ext4_mb_release(struct super_block *sb) atomic_read(&sbi->s_bal_breaks), atomic_read(&sbi->s_mb_lost_chunks)); ext4_msg(sb, KERN_INFO, - "mballoc: %lu generated and it took %Lu", - sbi->s_mb_buddies_generated, - sbi->s_mb_generation_time); + "mballoc: %u generated and it took %llu", + atomic_read(&sbi->s_mb_buddies_generated), + atomic64_read(&sbi->s_mb_generation_time)); ext4_msg(sb, KERN_INFO, "mballoc: %u preallocated, %u discarded", atomic_read(&sbi->s_mb_preallocated), -- 2.31.0.291.g576ba9dcdaf-goog