From patchwork Sun Feb 25 02:38:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205965 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406095dyb; Sat, 24 Feb 2024 18:39:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVUknaWH1bMRqd7E4xqLFUtw29OtF9XsstK5X40a/j/+bGKpH46cYrlNQxYfloLvmQzOfBR4toggCa2DEc2C8KCptSwPw== X-Google-Smtp-Source: AGHT+IFhmfJlIa9uDA+iYTxzifTFOYdLO7Bsm96VGZuJgNFFfJYReE5dsfG/u17VIuFbVZiTGrer X-Received: by 2002:a2e:9d8d:0:b0:2d2:7e73:6770 with SMTP id c13-20020a2e9d8d000000b002d27e736770mr1436013ljj.49.1708828796921; Sat, 24 Feb 2024 18:39:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828796; cv=pass; d=google.com; s=arc-20160816; b=mYPtghd2EMN1jMXbEBYhkQ1CdG7RnZRlzxwBD49Gd+iLCOr6p8nUdYG4xZ9LU7em6v 70WQIrl648m33Fy5Ea37FG+xxpg66GC4nED0XvQvIwKRgPvxRoQehoqM5U1D0YM2LCun U0Wg+a6VSVW7EsaoGw89E3S8lwzUMfiP5kWCNP+qV//k1Ts3iTbYUdPHFke4IKqPFsjc F+U/wmvC7zvvOm0n5UTwFe1WqMDVHUfiXV7UGZBRHfOcHVQiR1qJi1q7zFfT20Mhz15w eXpuICjVkwmK1ikDiv5oztyg4IoZm6FMhC4AD0tUKd2AJ53Cmrzcyb27evhQJDDUp/Vd blVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=zl/wHtbVZwctaDzKPv15EO94P0+3HzLA0UW5JZF/pxI=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=TRhukIeUdyuJ/N3gR2E3VZsMjfSIiWoTroYYBnbzuuz/fUhNNUw1FeQcHW74qqyxTa DIrFPmWADpcqi0l4xh6UkyCZTSIiPMdDeHv3459WT59MeDbIFwRucVijAyWg6gT0jWEH sJjehJmi9676gGV0BpW414WfedkNwfWDitCCssoTsjR4Vvc1kkHFV43Iwg25haxktspl zQgBLeafXxnSrLaSkaLG4xMioJfoWj1zNEV7BAL+sy6gAINGDMFCAIk2OT8sjasoZNhM CnFEn6XzjAqlnS6fOs/bjDPqDsJzfywc3Bz9yWFwH9jMv3jKygSQdDSVFO82qJhWnrUT dfbQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=v1MNIKkb; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79930-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79930-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w30-20020a50d79e000000b00565b8d2940esi593623edi.8.2024.02.24.18.39.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:39:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79930-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=v1MNIKkb; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79930-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79930-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5C6BE1F21764 for ; Sun, 25 Feb 2024 02:39:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F92C10949; Sun, 25 Feb 2024 02:38:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="v1MNIKkb" Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E49A33E1 for ; Sun, 25 Feb 2024 02:38:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828719; cv=none; b=d4T1l0lDd8dEzLyClbECZI87fCdNMPxxXsd2RvXUx0xFGl1JMjQhkyGaKLF3H6idM4uHmIwBNOo9zXr4ii36K9Fn92sUlFY15KJJW5NsBRR7IfdxSO+9u9a5Md/yQbfOPpPBfwSSVUoXPL8x7A6V2CB4ob+2SgIpOCR0DBfdK4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828719; c=relaxed/simple; bh=HeNS1iPBZ5lAlddImoTA33wWf0HYkhdae2awGoF0K+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J5Xyh9dn1SOVVyzSbBDcxWrUKEnqJqdwhSIVbaUw0FfJuM6obY7/zaXJUbQxRyzqybEzl2r2dcCFmGftJ2YbjzcjZSnn+djsZzHU4xjRFWvI+1b82qWLhAn5TTOdyGllmaD0IjATDA3WdnU/Be/p9OdjaUXv4Daa+9jt7kC8F70= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=v1MNIKkb; arc=none smtp.client-ip=95.215.58.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828715; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zl/wHtbVZwctaDzKPv15EO94P0+3HzLA0UW5JZF/pxI=; b=v1MNIKkbFwTFtfvLjog2D14bfQficAunRudKPocggSrwalxyTzlI/kLXdSKQHcufvWC4Zg 8h9qboDqXIG39mInHi+z9p3D9LTfrz4CJMxApn4rxGCNjxeYNmHoIZMqQfrSkBJsbnxZb5 2dBovt6i+oJCeXgaQYd8Fnghgq/3VsA= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 01/21] bcachefs: KEY_TYPE_accounting Date: Sat, 24 Feb 2024 21:38:03 -0500 Message-ID: <20240225023826.2413565-2-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791836864203615978 X-GMAIL-MSGID: 1791836864203615978 New key type for the disk space accounting rewrite. - Holds a variable sized array of u64s (may be more than one for accounting e.g. compressed and uncompressed size, or buckets and sectors for a given data type) - Updates are deltas, not new versions of the key: this means updates to accounting can happen via the btree write buffer, which we'll be teaching to accumulate deltas. Signed-off-by: Kent Overstreet --- fs/bcachefs/Makefile | 3 +- fs/bcachefs/bcachefs.h | 1 + fs/bcachefs/bcachefs_format.h | 80 +++------------ fs/bcachefs/bkey_methods.c | 1 + fs/bcachefs/disk_accounting.c | 70 ++++++++++++++ fs/bcachefs/disk_accounting.h | 52 ++++++++++ fs/bcachefs/disk_accounting_format.h | 139 +++++++++++++++++++++++++++ fs/bcachefs/replicas_format.h | 21 ++++ fs/bcachefs/sb-downgrade.c | 12 ++- fs/bcachefs/sb-errors_types.h | 3 +- 10 files changed, 311 insertions(+), 71 deletions(-) create mode 100644 fs/bcachefs/disk_accounting.c create mode 100644 fs/bcachefs/disk_accounting.h create mode 100644 fs/bcachefs/disk_accounting_format.h create mode 100644 fs/bcachefs/replicas_format.h diff --git a/fs/bcachefs/Makefile b/fs/bcachefs/Makefile index f42f6d256945..94b2edb4155f 100644 --- a/fs/bcachefs/Makefile +++ b/fs/bcachefs/Makefile @@ -27,10 +27,11 @@ bcachefs-y := \ checksum.o \ clock.o \ compress.o \ + data_update.o \ debug.o \ dirent.o \ + disk_accounting.o \ disk_groups.o \ - data_update.o \ ec.o \ errcode.o \ error.o \ diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 0bee9dab6068..62812fc1cad0 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -509,6 +509,7 @@ enum gc_phase { GC_PHASE_BTREE_logged_ops, GC_PHASE_BTREE_rebalance_work, GC_PHASE_BTREE_subvolume_children, + GC_PHASE_BTREE_accounting, GC_PHASE_PENDING_DELETE, }; diff --git a/fs/bcachefs/bcachefs_format.h b/fs/bcachefs/bcachefs_format.h index bff8750ac0d7..313ca7dc370d 100644 --- a/fs/bcachefs/bcachefs_format.h +++ b/fs/bcachefs/bcachefs_format.h @@ -416,7 +416,8 @@ static inline void bkey_init(struct bkey *k) x(bucket_gens, 30) \ x(snapshot_tree, 31) \ x(logged_op_truncate, 32) \ - x(logged_op_finsert, 33) + x(logged_op_finsert, 33) \ + x(accounting, 34) enum bch_bkey_type { #define x(name, nr) KEY_TYPE_##name = nr, @@ -501,17 +502,19 @@ struct bch_sb_field { x(downgrade, 14) #include "alloc_background_format.h" +#include "dirent_format.h" +#include "disk_accounting_format.h" #include "extents_format.h" -#include "reflink_format.h" #include "ec_format.h" #include "inode_format.h" -#include "dirent_format.h" -#include "xattr_format.h" -#include "quota_format.h" #include "logged_ops_format.h" +#include "quota_format.h" +#include "reflink_format.h" +#include "replicas_format.h" +#include "sb-counters_format.h" #include "snapshot_format.h" #include "subvolume_format.h" -#include "sb-counters_format.h" +#include "xattr_format.h" enum bch_sb_field_type { #define x(f, nr) BCH_SB_FIELD_##f = nr, @@ -680,69 +683,11 @@ LE64_BITMASK(BCH_KDF_SCRYPT_P, struct bch_sb_field_crypt, kdf_flags, 32, 48); /* BCH_SB_FIELD_replicas: */ -#define BCH_DATA_TYPES() \ - x(free, 0) \ - x(sb, 1) \ - x(journal, 2) \ - x(btree, 3) \ - x(user, 4) \ - x(cached, 5) \ - x(parity, 6) \ - x(stripe, 7) \ - x(need_gc_gens, 8) \ - x(need_discard, 9) - -enum bch_data_type { -#define x(t, n) BCH_DATA_##t, - BCH_DATA_TYPES() -#undef x - BCH_DATA_NR -}; - -static inline bool data_type_is_empty(enum bch_data_type type) -{ - switch (type) { - case BCH_DATA_free: - case BCH_DATA_need_gc_gens: - case BCH_DATA_need_discard: - return true; - default: - return false; - } -} - -static inline bool data_type_is_hidden(enum bch_data_type type) -{ - switch (type) { - case BCH_DATA_sb: - case BCH_DATA_journal: - return true; - default: - return false; - } -} - -struct bch_replicas_entry_v0 { - __u8 data_type; - __u8 nr_devs; - __u8 devs[]; -} __packed; - struct bch_sb_field_replicas_v0 { struct bch_sb_field field; struct bch_replicas_entry_v0 entries[]; } __packed __aligned(8); -struct bch_replicas_entry_v1 { - __u8 data_type; - __u8 nr_devs; - __u8 nr_required; - __u8 devs[]; -} __packed; - -#define replicas_entry_bytes(_i) \ - (offsetof(typeof(*(_i)), devs) + (_i)->nr_devs) - struct bch_sb_field_replicas { struct bch_sb_field field; struct bch_replicas_entry_v1 entries[]; @@ -875,7 +820,8 @@ struct bch_sb_field_downgrade { x(rebalance_work, BCH_VERSION(1, 3)) \ x(member_seq, BCH_VERSION(1, 4)) \ x(subvolume_fs_parent, BCH_VERSION(1, 5)) \ - x(btree_subvolume_children, BCH_VERSION(1, 6)) + x(btree_subvolume_children, BCH_VERSION(1, 6)) \ + x(disk_accounting_v2, BCH_VERSION(1, 7)) enum bcachefs_metadata_version { bcachefs_metadata_version_min = 9, @@ -1525,7 +1471,9 @@ enum btree_id_flags { x(rebalance_work, 18, BTREE_ID_SNAPSHOT_FIELD, \ BIT_ULL(KEY_TYPE_set)|BIT_ULL(KEY_TYPE_cookie)) \ x(subvolume_children, 19, 0, \ - BIT_ULL(KEY_TYPE_set)) + BIT_ULL(KEY_TYPE_set)) \ + x(accounting, 20, BTREE_ID_SNAPSHOT_FIELD, \ + BIT_ULL(KEY_TYPE_accounting)) \ enum btree_id { #define x(name, nr, ...) BTREE_ID_##name = nr, diff --git a/fs/bcachefs/bkey_methods.c b/fs/bcachefs/bkey_methods.c index 5e52684764eb..da25bdd1e8a6 100644 --- a/fs/bcachefs/bkey_methods.c +++ b/fs/bcachefs/bkey_methods.c @@ -7,6 +7,7 @@ #include "btree_types.h" #include "alloc_background.h" #include "dirent.h" +#include "disk_accounting.h" #include "ec.h" #include "error.h" #include "extents.h" diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c new file mode 100644 index 000000000000..209f59e87b34 --- /dev/null +++ b/fs/bcachefs/disk_accounting.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include "bcachefs.h" +#include "btree_update.h" +#include "buckets.h" +#include "disk_accounting.h" +#include "replicas.h" + +static const char * const disk_accounting_type_strs[] = { +#define x(t, n, ...) [n] = #t, + BCH_DISK_ACCOUNTING_TYPES() +#undef x + NULL +}; + +int bch2_accounting_invalid(struct bch_fs *c, struct bkey_s_c k, + enum bkey_invalid_flags flags, + struct printbuf *err) +{ + return 0; +} + +void bch2_accounting_key_to_text(struct printbuf *out, struct disk_accounting_key *k) +{ + if (k->type >= BCH_DISK_ACCOUNTING_TYPE_NR) { + prt_printf(out, "unknown type %u", k->type); + return; + } + + prt_str(out, disk_accounting_type_strs[k->type]); + prt_str(out, " "); + + switch (k->type) { + case BCH_DISK_ACCOUNTING_nr_inodes: + break; + case BCH_DISK_ACCOUNTING_persistent_reserved: + prt_printf(out, "replicas=%u", k->persistent_reserved.nr_replicas); + break; + case BCH_DISK_ACCOUNTING_replicas: + bch2_replicas_entry_to_text(out, &k->replicas); + break; + case BCH_DISK_ACCOUNTING_dev_data_type: + prt_printf(out, "dev=%u data_type=", k->dev_data_type.dev); + bch2_prt_data_type(out, k->dev_data_type.data_type); + break; + case BCH_DISK_ACCOUNTING_dev_stripe_buckets: + prt_printf(out, "dev=%u", k->dev_stripe_buckets.dev); + break; + } +} + +void bch2_accounting_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c k) +{ + struct bkey_s_c_accounting acc = bkey_s_c_to_accounting(k); + struct disk_accounting_key acc_k; + bpos_to_disk_accounting_key(&acc_k, k.k->p); + + bch2_accounting_key_to_text(out, &acc_k); + + for (unsigned i = 0; i < bch2_accounting_counters(k.k); i++) + prt_printf(out, " %lli", acc.v->d[i]); +} + +void bch2_accounting_swab(struct bkey_s k) +{ + for (u64 *p = (u64 *) k.v; + p < (u64 *) bkey_val_end(k); + p++) + *p = swab64(*p); +} diff --git a/fs/bcachefs/disk_accounting.h b/fs/bcachefs/disk_accounting.h new file mode 100644 index 000000000000..e15299665859 --- /dev/null +++ b/fs/bcachefs/disk_accounting.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BCACHEFS_DISK_ACCOUNTING_H +#define _BCACHEFS_DISK_ACCOUNTING_H + +static inline unsigned bch2_accounting_counters(const struct bkey *k) +{ + return bkey_val_u64s(k) - offsetof(struct bch_accounting, d) / sizeof(u64); +} + +static inline void bch2_accounting_accumulate(struct bkey_i_accounting *dst, + struct bkey_s_c_accounting src) +{ + EBUG_ON(dst->k.u64s != src.k->u64s); + + for (unsigned i = 0; i < bch2_accounting_counters(&dst->k); i++) + dst->v.d[i] += src.v->d[i]; + if (bversion_cmp(dst->k.version, src.k->version) < 0) + dst->k.version = src.k->version; +} + +static inline void bpos_to_disk_accounting_key(struct disk_accounting_key *acc, struct bpos p) +{ + acc->_pad = p; +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + bch2_bpos_swab(&acc->_pad); +#endif +} + +static inline struct bpos disk_accounting_key_to_bpos(struct disk_accounting_key *k) +{ + struct bpos ret = k->_pad; + +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + bch2_bpos_swab(&ret); +#endif + return ret; +} + +int bch2_accounting_invalid(struct bch_fs *, struct bkey_s_c, + enum bkey_invalid_flags, struct printbuf *); +void bch2_accounting_key_to_text(struct printbuf *, struct disk_accounting_key *); +void bch2_accounting_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c); +void bch2_accounting_swab(struct bkey_s); + +#define bch2_bkey_ops_accounting ((struct bkey_ops) { \ + .key_invalid = bch2_accounting_invalid, \ + .val_to_text = bch2_accounting_to_text, \ + .swab = bch2_accounting_swab, \ + .min_val_size = 8, \ +}) + +#endif /* _BCACHEFS_DISK_ACCOUNTING_H */ diff --git a/fs/bcachefs/disk_accounting_format.h b/fs/bcachefs/disk_accounting_format.h new file mode 100644 index 000000000000..e06a42f0d578 --- /dev/null +++ b/fs/bcachefs/disk_accounting_format.h @@ -0,0 +1,139 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BCACHEFS_DISK_ACCOUNTING_FORMAT_H +#define _BCACHEFS_DISK_ACCOUNTING_FORMAT_H + +#include "replicas_format.h" + +/* + * Disk accounting - KEY_TYPE_accounting - on disk format: + * + * Here, the key has considerably more structure than a typical key (bpos); an + * accounting key is 'struct disk_accounting_key', which is a union of bpos. + * + * This is a type-tagged union of all our various subtypes; a disk accounting + * key can be device counters, replicas counters, et cetera - it's extensible. + * + * The value is a list of u64s or s64s; the number of counters is specific to a + * given accounting type. + * + * Unlike with other key types, updates are _deltas_, and the deltas are not + * resolved until the update to the underlying btree, done by btree write buffer + * flush or journal replay. + * + * Journal replay in particular requires special handling. The journal tracks a + * range of entries which may possibly have not yet been applied to the btree + * yet - it does not know definitively whether individual entries are dirty and + * still need to be applied. + * + * To handle this, we use the version field of struct bkey, and give every + * accounting update a unique version number - a total ordering in time; the + * version number is derived from the key's position in the journal. Then + * journal replay can compare the version number of the key from the journal + * with the version number of the key in the btree to determine if a key needs + * to be replayed. + * + * For this to work, we must maintain this strict time ordering of updates as + * they are flushed to the btree, both via write buffer flush and via journal + * replay. This has complications for the write buffer code while journal replay + * is still in progress; the write buffer cannot flush any accounting keys to + * the btree until journal replay has finished replaying its accounting keys, or + * the (newer) version number of the keys from the write buffer will cause + * updates from journal replay to be lost. + */ + +struct bch_accounting { + struct bch_val v; + __u64 d[]; +}; + +#define BCH_ACCOUNTING_MAX_COUNTERS 3 + +#define BCH_DATA_TYPES() \ + x(free, 0) \ + x(sb, 1) \ + x(journal, 2) \ + x(btree, 3) \ + x(user, 4) \ + x(cached, 5) \ + x(parity, 6) \ + x(stripe, 7) \ + x(need_gc_gens, 8) \ + x(need_discard, 9) + +enum bch_data_type { +#define x(t, n) BCH_DATA_##t, + BCH_DATA_TYPES() +#undef x + BCH_DATA_NR +}; + +static inline bool data_type_is_empty(enum bch_data_type type) +{ + switch (type) { + case BCH_DATA_free: + case BCH_DATA_need_gc_gens: + case BCH_DATA_need_discard: + return true; + default: + return false; + } +} + +static inline bool data_type_is_hidden(enum bch_data_type type) +{ + switch (type) { + case BCH_DATA_sb: + case BCH_DATA_journal: + return true; + default: + return false; + } +} + +#define BCH_DISK_ACCOUNTING_TYPES() \ + x(nr_inodes, 0) \ + x(persistent_reserved, 1) \ + x(replicas, 2) \ + x(dev_data_type, 3) \ + x(dev_stripe_buckets, 4) + +enum disk_accounting_type { +#define x(f, nr) BCH_DISK_ACCOUNTING_##f = nr, + BCH_DISK_ACCOUNTING_TYPES() +#undef x + BCH_DISK_ACCOUNTING_TYPE_NR, +}; + +struct bch_nr_inodes { +}; + +struct bch_persistent_reserved { + __u8 nr_replicas; +}; + +struct bch_dev_data_type { + __u8 dev; + __u8 data_type; +}; + +struct bch_dev_stripe_buckets { + __u8 dev; +}; + +struct disk_accounting_key { + union { + struct { + __u8 type; + union { + struct bch_nr_inodes nr_inodes; + struct bch_persistent_reserved persistent_reserved; + struct bch_replicas_entry_v1 replicas; + struct bch_dev_data_type dev_data_type; + struct bch_dev_stripe_buckets dev_stripe_buckets; + }; + }; + struct bpos _pad; + }; +}; + +#endif /* _BCACHEFS_DISK_ACCOUNTING_FORMAT_H */ diff --git a/fs/bcachefs/replicas_format.h b/fs/bcachefs/replicas_format.h new file mode 100644 index 000000000000..ed94f8c636b3 --- /dev/null +++ b/fs/bcachefs/replicas_format.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _BCACHEFS_REPLICAS_FORMAT_H +#define _BCACHEFS_REPLICAS_FORMAT_H + +struct bch_replicas_entry_v0 { + __u8 data_type; + __u8 nr_devs; + __u8 devs[]; +} __packed; + +struct bch_replicas_entry_v1 { + __u8 data_type; + __u8 nr_devs; + __u8 nr_required; + __u8 devs[]; +} __packed; + +#define replicas_entry_bytes(_i) \ + (offsetof(typeof(*(_i)), devs) + (_i)->nr_devs) + +#endif /* _BCACHEFS_REPLICAS_FORMAT_H */ diff --git a/fs/bcachefs/sb-downgrade.c b/fs/bcachefs/sb-downgrade.c index 3337419faeff..33db8d7ca8c4 100644 --- a/fs/bcachefs/sb-downgrade.c +++ b/fs/bcachefs/sb-downgrade.c @@ -52,9 +52,15 @@ BCH_FSCK_ERR_subvol_fs_path_parent_wrong) \ x(btree_subvolume_children, \ BIT_ULL(BCH_RECOVERY_PASS_check_subvols), \ - BCH_FSCK_ERR_subvol_children_not_set) + BCH_FSCK_ERR_subvol_children_not_set) \ + x(disk_accounting_v2, \ + BIT_ULL(BCH_RECOVERY_PASS_check_allocations), \ + BCH_FSCK_ERR_accounting_mismatch) -#define DOWNGRADE_TABLE() +#define DOWNGRADE_TABLE() \ + x(disk_accounting_v2, \ + BIT_ULL(BCH_RECOVERY_PASS_check_alloc_info), \ + BCH_FSCK_ERR_dev_usage_buckets_wrong) struct upgrade_downgrade_entry { u64 recovery_passes; @@ -108,7 +114,7 @@ void bch2_sb_set_upgrade(struct bch_fs *c, } } -#define x(ver, passes, ...) static const u16 downgrade_ver_##errors[] = { __VA_ARGS__ }; +#define x(ver, passes, ...) static const u16 downgrade_##ver##_errors[] = { __VA_ARGS__ }; DOWNGRADE_TABLE() #undef x diff --git a/fs/bcachefs/sb-errors_types.h b/fs/bcachefs/sb-errors_types.h index 0df4b0e7071a..383e13711001 100644 --- a/fs/bcachefs/sb-errors_types.h +++ b/fs/bcachefs/sb-errors_types.h @@ -264,7 +264,8 @@ x(subvol_children_not_set, 256) \ x(subvol_children_bad, 257) \ x(subvol_loop, 258) \ - x(subvol_unreachable, 259) + x(subvol_unreachable, 259) \ + x(accounting_mismatch, 260) enum bch_sb_error_id { #define x(t, n) BCH_FSCK_ERR_##t = n, From patchwork Sun Feb 25 02:38:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205967 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406172dyb; Sat, 24 Feb 2024 18:40:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVJxOpMjxEw89clJkSNjFeVhCMerbWtpi6grjb8CTTZnSfL9rtChxIBWSqv6JsddynpY9IolBNHiPQmHk3bYwtRd+RF+g== X-Google-Smtp-Source: AGHT+IHxNMLw6EVWJwktC8o2/Rvoo226PP84+Y/QBXMKFRmn5a+7lDvE/EtAjQYJFHVnvUacxrsm X-Received: by 2002:a05:620a:1135:b0:783:afb3:d16 with SMTP id p21-20020a05620a113500b00783afb30d16mr4098371qkk.30.1708828822500; Sat, 24 Feb 2024 18:40:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828822; cv=pass; d=google.com; s=arc-20160816; b=eIYYk3yZiLvFo/WFWLRD76v7x4Cg9w/kFcCsvkB3l52n8pvKyJxZJ4+J7lMMRN/6eQ ZAKhcyiKC6vuyHCstgOF3cHlYA3p2Yiw3O89T68J/+e7uReHLegeT5KIQplc5heznVAy 0MovQz2DHTGWUfLgtf/zUzP6ITpH/WyITQqzkKWp0kf0s7Dj51EHUfQFG9cuh2awhomi lN2TEMWkvFzRwpWbdRsOuPxckybIY+JdqrQOyGF7POqX3sW0KVDkqbP+jxP5cErEs3lx DlObH+XwKQwwIBb7XIqLjhlHi5JMGmqcN3FOO/4bWJlJDsQAXQZ7piZRuZg5mG2chZ9b dFoA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DrOHx5wMYDRZo/YqdsvPnCBIdET0WVtHDJeAbRuqJI0=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=eWBHYALyUSwLEZUt4yXIuV1MMzrQ8tWARAFRBVT+hQBma+Ygjh1IknJGe9crr3kS/R p+EitgIpeKg7gPEb9NxetnZFeFrTn59MIOv1NVTQkeIhMwKiuiPvt52WkEV0XKCDfg7r W7FiZlRtEIK5lYZzKN2C8AUgXpWWvcMcdzwViSbwcBnIsKJ6NxoW8JGX2POfLjoXEKKk afx6IL5B7ZasDSi5Pu/vj87ShV0SscaIzOY59PZHNZCzvpp4xtFya+RDrjax6Hkhr0S5 OwrBGR/nibUjSVz5y7zRTivrvt8yfFTyWPcKJbVW+3m8mM9Z6hycm1iY9K4zTadQQNx3 iazA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="dGAOx/GL"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79933-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79933-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w14-20020a05620a444e00b00787cd797455si256214qkp.391.2024.02.24.18.40.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:40:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79933-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="dGAOx/GL"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79933-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79933-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 47A791C20E75 for ; Sun, 25 Feb 2024 02:40:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5254113FF5; Sun, 25 Feb 2024 02:38:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="dGAOx/GL" Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80FAE8C07 for ; Sun, 25 Feb 2024 02:38:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828722; cv=none; b=j/KEA38oBQjiVCt+OIXqGbkVroaKfFTo3ahmTKgrq3BNRtuw+qBJY0+41rfDUfwf5IAP0ygL5JmYaN9fR6PHzEhyHResE6+HDVXF9Jajvz89HfTz1FL2naecJ+eby2FnmM4beeJL6yBX+8lvQ0DTt1gJ23uGJfSm1vdgZrOhsGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828722; c=relaxed/simple; bh=WhdKHqtzSdKzXSywa8/Kdpjd1qyDu5Tei06epJX7qUk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SbvhgwpQyS/hhx0M/Nyss3j5HswQZoi64SxpRsXwvx2YB9LHMBy/Jb3s+381NkMJJW7kz3Pmk+tFjDYweQjl1U5yaC7jl65TTH3rUnHcC11bDPRgxKFk9hAoRaV++ce+YMD/jLx3V17WYm2OnzGBKJEJorqwntjGpdGmLxZAugc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=dGAOx/GL; arc=none smtp.client-ip=95.215.58.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828718; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DrOHx5wMYDRZo/YqdsvPnCBIdET0WVtHDJeAbRuqJI0=; b=dGAOx/GLUxtEdliB0UdEMTiotkvOejJNPfJ61o3fMSJjoewuwiT3emDwd6XodW30MavCZb jB3slYjO1Uy9H72d5KMb9yXufezoiKDtmz1+I1cAzdDELRlh7FrPEa/l37qal7/ruDAtS/ 9hYMIPbSuygjbJL+DJPEvhfCmIdEQ1o= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 05/21] bcachefs: dev_usage updated by new accounting Date: Sat, 24 Feb 2024 21:38:07 -0500 Message-ID: <20240225023826.2413565-6-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791836891050484838 X-GMAIL-MSGID: 1791836891050484838 Reading disk accounting now requires an eytzinger lookup (see: bch2_accounting_mem_read()), but the per-device counters are used frequently enough that we'd like to still be able to read them with just a percpu sum, as in the old code. This patch special cases the device counters; when we update in-memory accounting we also update the old style percpu counters if it's a deice counter update. Signed-off-by: Kent Overstreet --- fs/bcachefs/bcachefs.h | 3 +-- fs/bcachefs/btree_gc.c | 2 +- fs/bcachefs/buckets.c | 36 +++++------------------------------ fs/bcachefs/buckets_types.h | 2 +- fs/bcachefs/disk_accounting.c | 14 ++++++++++++++ fs/bcachefs/disk_accounting.h | 11 ++++++++++- fs/bcachefs/recovery.c | 14 -------------- fs/bcachefs/sb-clean.c | 17 ----------------- 8 files changed, 32 insertions(+), 67 deletions(-) diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 18c00051a8f6..91c40fde1925 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -576,8 +576,7 @@ struct bch_dev { unsigned long *buckets_nouse; struct rw_semaphore bucket_lock; - struct bch_dev_usage *usage_base; - struct bch_dev_usage __percpu *usage[JOURNAL_BUF_NR]; + struct bch_dev_usage __percpu *usage; struct bch_dev_usage __percpu *usage_gc; /* Allocator: */ diff --git a/fs/bcachefs/btree_gc.c b/fs/bcachefs/btree_gc.c index 2dfa7ca95fc0..93826749356e 100644 --- a/fs/bcachefs/btree_gc.c +++ b/fs/bcachefs/btree_gc.c @@ -1233,7 +1233,7 @@ static int bch2_gc_done(struct bch_fs *c, bch2_fs_usage_acc_to_base(c, i); __for_each_member_device(c, ca) { - struct bch_dev_usage *dst = ca->usage_base; + struct bch_dev_usage *dst = this_cpu_ptr(ca->usage); struct bch_dev_usage *src = (void *) bch2_acc_percpu_u64s((u64 __percpu *) ca->usage_gc, dev_usage_u64s()); diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index fb915c1b7844..7540486ae266 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -69,15 +69,8 @@ void bch2_fs_usage_initialize(struct bch_fs *c) void bch2_dev_usage_read_fast(struct bch_dev *ca, struct bch_dev_usage *usage) { - struct bch_fs *c = ca->fs; - unsigned seq, i, u64s = dev_usage_u64s(); - - do { - seq = read_seqcount_begin(&c->usage_lock); - memcpy(usage, ca->usage_base, u64s * sizeof(u64)); - for (i = 0; i < ARRAY_SIZE(ca->usage); i++) - acc_u64s_percpu((u64 *) usage, (u64 __percpu *) ca->usage[i], u64s); - } while (read_seqcount_retry(&c->usage_lock, seq)); + memset(usage, 0, sizeof(*usage)); + acc_u64s_percpu((u64 *) usage, (u64 __percpu *) ca->usage, dev_usage_u64s()); } u64 bch2_fs_usage_read_one(struct bch_fs *c, u64 *v) @@ -147,16 +140,6 @@ void bch2_fs_usage_acc_to_base(struct bch_fs *c, unsigned idx) (u64 __percpu *) c->usage[idx], u64s); percpu_memset(c->usage[idx], 0, u64s * sizeof(u64)); - rcu_read_lock(); - for_each_member_device_rcu(c, ca, NULL) { - u64s = dev_usage_u64s(); - - acc_u64s_percpu((u64 *) ca->usage_base, - (u64 __percpu *) ca->usage[idx], u64s); - percpu_memset(ca->usage[idx], 0, u64s * sizeof(u64)); - } - rcu_read_unlock(); - write_seqcount_end(&c->usage_lock); preempt_enable(); } @@ -1214,23 +1197,14 @@ void bch2_dev_buckets_free(struct bch_dev *ca) { kvfree(ca->buckets_nouse); kvfree(rcu_dereference_protected(ca->bucket_gens, 1)); - - for (unsigned i = 0; i < ARRAY_SIZE(ca->usage); i++) - free_percpu(ca->usage[i]); - kfree(ca->usage_base); + free_percpu(ca->usage); } int bch2_dev_buckets_alloc(struct bch_fs *c, struct bch_dev *ca) { - ca->usage_base = kzalloc(sizeof(struct bch_dev_usage), GFP_KERNEL); - if (!ca->usage_base) + ca->usage = alloc_percpu(struct bch_dev_usage); + if (!ca->usage) return -BCH_ERR_ENOMEM_usage_init; - for (unsigned i = 0; i < ARRAY_SIZE(ca->usage); i++) { - ca->usage[i] = alloc_percpu(struct bch_dev_usage); - if (!ca->usage[i]) - return -BCH_ERR_ENOMEM_usage_init; - } - return bch2_dev_buckets_resize(c, ca, ca->mi.nbuckets); } diff --git a/fs/bcachefs/buckets_types.h b/fs/bcachefs/buckets_types.h index 6a31740222a7..baa7e0924390 100644 --- a/fs/bcachefs/buckets_types.h +++ b/fs/bcachefs/buckets_types.h @@ -33,7 +33,7 @@ struct bucket_gens { }; struct bch_dev_usage { - struct { + struct bch_dev_usage_type { u64 buckets; u64 sectors; /* _compressed_ sectors: */ /* diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c index 327c586ac661..e0114d8eb5a8 100644 --- a/fs/bcachefs/disk_accounting.c +++ b/fs/bcachefs/disk_accounting.c @@ -330,6 +330,20 @@ int bch2_accounting_read(struct bch_fs *c) case BCH_DISK_ACCOUNTING_replicas: fs_usage_data_type_to_base(usage, k.replicas.data_type, v[0]); break; + case BCH_DISK_ACCOUNTING_dev_data_type: + if (bch2_dev_exists2(c, k.dev_data_type.dev)) { + struct bch_dev *ca = bch_dev_bkey_exists(c, k.dev_data_type.dev); + struct bch_dev_usage_type __percpu *d = &ca->usage->d[k.dev_data_type.data_type]; + + percpu_u64_set(&d->buckets, v[0]); + percpu_u64_set(&d->sectors, v[1]); + percpu_u64_set(&d->fragmented, v[2]); + + if (k.dev_data_type.data_type == BCH_DATA_sb || + k.dev_data_type.data_type == BCH_DATA_journal) + usage->hidden += v[0] * ca->mi.bucket_size; + } + break; } } preempt_enable(); diff --git a/fs/bcachefs/disk_accounting.h b/fs/bcachefs/disk_accounting.h index 5fd053a819df..a8526bf43207 100644 --- a/fs/bcachefs/disk_accounting.h +++ b/fs/bcachefs/disk_accounting.h @@ -3,6 +3,7 @@ #define _BCACHEFS_DISK_ACCOUNTING_H #include +#include "sb-members.h" static inline void bch2_u64s_neg(u64 *v, unsigned nr) { @@ -126,6 +127,7 @@ static inline int __bch2_accounting_mem_add(struct bch_fs *c, struct bkey_s_c_ac static inline int bch2_accounting_mem_add(struct btree_trans *trans, struct bkey_s_c_accounting a) { + struct bch_fs *c = trans->c; struct disk_accounting_key acc_k; bpos_to_disk_accounting_key(&acc_k, a.k->p); @@ -136,8 +138,15 @@ static inline int bch2_accounting_mem_add(struct btree_trans *trans, struct bkey case BCH_DISK_ACCOUNTING_replicas: fs_usage_data_type_to_base(&trans->fs_usage_delta, acc_k.replicas.data_type, a.v->d[0]); break; + case BCH_DISK_ACCOUNTING_dev_data_type: { + struct bch_dev *ca = bch_dev_bkey_exists(c, acc_k.dev_data_type.dev); + + this_cpu_add(ca->usage->d[acc_k.dev_data_type.data_type].buckets, a.v->d[0]); + this_cpu_add(ca->usage->d[acc_k.dev_data_type.data_type].sectors, a.v->d[1]); + this_cpu_add(ca->usage->d[acc_k.dev_data_type.data_type].fragmented, a.v->d[2]); + } } - return __bch2_accounting_mem_add(trans->c, a); + return __bch2_accounting_mem_add(c, a); } static inline void bch2_accounting_mem_read_counters(struct bch_fs *c, diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c index 140393256f32..5a0ab3920382 100644 --- a/fs/bcachefs/recovery.c +++ b/fs/bcachefs/recovery.c @@ -368,20 +368,6 @@ static int journal_replay_entry_early(struct bch_fs *c, le64_to_cpu(u->v)); break; } - case BCH_JSET_ENTRY_dev_usage: { - struct jset_entry_dev_usage *u = - container_of(entry, struct jset_entry_dev_usage, entry); - struct bch_dev *ca = bch_dev_bkey_exists(c, le32_to_cpu(u->dev)); - unsigned i, nr_types = jset_entry_dev_usage_nr_types(u); - - for (i = 0; i < min_t(unsigned, nr_types, BCH_DATA_NR); i++) { - ca->usage_base->d[i].buckets = le64_to_cpu(u->d[i].buckets); - ca->usage_base->d[i].sectors = le64_to_cpu(u->d[i].sectors); - ca->usage_base->d[i].fragmented = le64_to_cpu(u->d[i].fragmented); - } - - break; - } case BCH_JSET_ENTRY_blacklist: { struct jset_entry_blacklist *bl_entry = container_of(entry, struct jset_entry_blacklist, entry); diff --git a/fs/bcachefs/sb-clean.c b/fs/bcachefs/sb-clean.c index 5980ba2563fe..a7f2cc774492 100644 --- a/fs/bcachefs/sb-clean.c +++ b/fs/bcachefs/sb-clean.c @@ -228,23 +228,6 @@ void bch2_journal_super_entries_add_common(struct bch_fs *c, "embedded variable length struct"); } - for_each_member_device(c, ca) { - unsigned b = sizeof(struct jset_entry_dev_usage) + - sizeof(struct jset_entry_dev_usage_type) * BCH_DATA_NR; - struct jset_entry_dev_usage *u = - container_of(jset_entry_init(end, b), - struct jset_entry_dev_usage, entry); - - u->entry.type = BCH_JSET_ENTRY_dev_usage; - u->dev = cpu_to_le32(ca->dev_idx); - - for (unsigned i = 0; i < BCH_DATA_NR; i++) { - u->d[i].buckets = cpu_to_le64(ca->usage_base->d[i].buckets); - u->d[i].sectors = cpu_to_le64(ca->usage_base->d[i].sectors); - u->d[i].fragmented = cpu_to_le64(ca->usage_base->d[i].fragmented); - } - } - percpu_up_read(&c->mark_lock); for (unsigned i = 0; i < 2; i++) { From patchwork Sun Feb 25 02:38:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205966 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406149dyb; Sat, 24 Feb 2024 18:40:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWPIa/ElsGB2NhVWcnIX27K3+vLoAmg+fu5PQP5yDUjhIi93dLj2kT4E2RrX17saszmW038DpS9h5du4DHYfNxK/I7OJw== X-Google-Smtp-Source: AGHT+IFQn/8RQN4rQmeHGW6wElkMGYXpHEOj+BW6BYIAVWARoeflyOnnVa4wrq94+mbj6+HM7lLe X-Received: by 2002:a17:90a:bd0a:b0:299:489f:fd2d with SMTP id y10-20020a17090abd0a00b00299489ffd2dmr2344833pjr.20.1708828814362; Sat, 24 Feb 2024 18:40:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828814; cv=pass; d=google.com; s=arc-20160816; b=AMuoMqeKQovQvuVDtKzqPFiAdqbjnpRUbK9MPKsFzVv5cuETjp1b/uw91yeYLni2zO BlWil0iCUl3AbdHUvBL4hbIF6IlVtH51ZmBkr8yb/f0VG5vGIhgAL5EYqIj6rgEG+7QC jsgBzSOroOegCFTmkFcGzm2adPPhmmk+7qd0HD8mHMi06mOisLT/OZWkZUEMYEu5zsEt FQpvvsfklvEnhx7lBL9ko6pE4g68BNPL/tDfidxSDCvdLd8LrUnl/e7sSQvUh6wMoJfl kMu/qnn49HdNu4QzPTka7YXkcFyeVzLx9EA0Jg7G82sot2SRPQiR+4UdztY9qxZFoEMs wnwA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=LpqGNmxVz4nH/s+HZrDUNHReRjWltPhY2a8VCj1nHDg=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=ZOYcQq8QZtM7md8TnK1NwLgYW/P6tEYtElFx6KNtS5M8YzkPNak5lHXDaFqEMC6MdK G6iPRF6XoTgi1Q6ztujQd4Th8+W8XVWC6wN7zraTwkwhhf1UyRk6hQMw1weOX6HrJ8kz Ae+kJ9iFMt/PVJ3fTa6f53+fV5XsbOvjo/HQbxFuMwcQs9axsA1DTujJuaY0YTDhwYrC qPmaHkFdS2uQLnE7KH87BI8GGFhqyZHkaPAFuJOuMdfj2vGFuSxcqgQ/iPzuo1jTCrrk NGKpskbNPQMRZGq+JpQCmIrM3uJ6H4WH89fNIdnMKdt3XEKaEOncUosT+KlJczyn70tw r5Fw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=d2sSfVLe; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79934-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79934-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id z15-20020a17090a66cf00b0029970f8cb1bsi3470485pjl.80.2024.02.24.18.40.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:40:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79934-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=d2sSfVLe; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79934-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79934-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1DE31281724 for ; Sun, 25 Feb 2024 02:40:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D2B3B134A0; Sun, 25 Feb 2024 02:38:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="d2sSfVLe" Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 79E6FA94D for ; Sun, 25 Feb 2024 02:38:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828723; cv=none; b=j1xCyMinpPAJAlF/D013XSifeQFrhKLIm07PK9/KcVucrEL0v0gvtPwYnyDe0V1zTDhFP91BsyUyKEhQI+hXmpWw9vrJUaw6z5AT/67t+JiIFabOU1WnDAliyaBYkoD7/8gCQNwyu/p3UPJ86bD4wzMnkLoPOQ38L+ilfREmilI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828723; c=relaxed/simple; bh=p7O3MH5Pv6ZYytgnV2uzMgTPCfEDxUNuHv6Bvd2aaxU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lfg3S5hYDoSZHJyK+kTNZTm6PR8Oa1tGglSfvWp/inlbYsjR7JxTsm922S0kcV8D1upAKcSVcjdejJ81ydHbbnSYczkolvOetsrBsAB6YinTI56W20LszvMzS6pz/NtHUbv8o+axsr0am2ag5TEKnwOdgX0WmRptjrilwUj0kMQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=d2sSfVLe; arc=none smtp.client-ip=95.215.58.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LpqGNmxVz4nH/s+HZrDUNHReRjWltPhY2a8VCj1nHDg=; b=d2sSfVLeCn+Z852b+5f+xPu13H2zmwi9gFUfGFrtsmTCSf3LTon4K8IJSM6bwVmCNw2lG7 7Sa57u1Vi3FPOp77P/As+QRnYkx0/cljMXy1JBdts1G3Af1FVHyF97qPKePgv03wwEZxPy djVNmYb5U+qdpDcb2mbbph7W50k1YXc= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 06/21] bcachefs: Kill bch2_fs_usage_initialize() Date: Sat, 24 Feb 2024 21:38:08 -0500 Message-ID: <20240225023826.2413565-7-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791836882882683186 X-GMAIL-MSGID: 1791836882882683186 Deleting code for the old disk accounting scheme. Signed-off-by: Kent Overstreet --- fs/bcachefs/buckets.c | 29 ----------------------------- fs/bcachefs/buckets.h | 2 -- fs/bcachefs/recovery.c | 2 -- 3 files changed, 33 deletions(-) diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index 7540486ae266..054c4c8d9c1b 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -38,35 +38,6 @@ static inline struct bch_fs_usage *fs_usage_ptr(struct bch_fs *c, : c->usage[journal_seq & JOURNAL_BUF_MASK]); } -void bch2_fs_usage_initialize(struct bch_fs *c) -{ - percpu_down_write(&c->mark_lock); - struct bch_fs_usage *usage = c->usage_base; - - for (unsigned i = 0; i < ARRAY_SIZE(c->usage); i++) - bch2_fs_usage_acc_to_base(c, i); - - for (unsigned i = 0; i < BCH_REPLICAS_MAX; i++) - usage->b.reserved += usage->persistent_reserved[i]; - - for (unsigned i = 0; i < c->replicas.nr; i++) { - struct bch_replicas_entry_v1 *e = - cpu_replicas_entry(&c->replicas, i); - - fs_usage_data_type_to_base(&usage->b, e->data_type, usage->replicas[i]); - } - - for_each_member_device(c, ca) { - struct bch_dev_usage dev = bch2_dev_usage_read(ca); - - usage->b.hidden += (dev.d[BCH_DATA_sb].buckets + - dev.d[BCH_DATA_journal].buckets) * - ca->mi.bucket_size; - } - - percpu_up_write(&c->mark_lock); -} - void bch2_dev_usage_read_fast(struct bch_dev *ca, struct bch_dev_usage *usage) { memset(usage, 0, sizeof(*usage)); diff --git a/fs/bcachefs/buckets.h b/fs/bcachefs/buckets.h index f9a1d24c997b..4e14615c770e 100644 --- a/fs/bcachefs/buckets.h +++ b/fs/bcachefs/buckets.h @@ -316,8 +316,6 @@ void bch2_dev_usage_update_m(struct bch_fs *, struct bch_dev *, int bch2_update_replicas(struct bch_fs *, struct bkey_s_c, struct bch_replicas_entry_v1 *, s64); -void bch2_fs_usage_initialize(struct bch_fs *); - int bch2_check_bucket_ref(struct btree_trans *, struct bkey_s_c, const struct bch_extent_ptr *, s64, enum bch_data_type, u8, u8, u32); diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c index 5a0ab3920382..4936b18e5a58 100644 --- a/fs/bcachefs/recovery.c +++ b/fs/bcachefs/recovery.c @@ -426,8 +426,6 @@ static int journal_replay_early(struct bch_fs *c, } } - bch2_fs_usage_initialize(c); - return 0; } From patchwork Sun Feb 25 02:38:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205968 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406183dyb; Sat, 24 Feb 2024 18:40:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX03nrLzBxgU7vqyb7UVFj0kea8AARDBkFJbzkLHWmKXPvpZymIdOqfI8s9JAsszUfwsdkJVrQ7FXLu++0NXvzViDkTqw== X-Google-Smtp-Source: AGHT+IEk5OoABaCzNKzE0ws0WQV4OXzpZ2eIuGSmPxmQ7XJuzDI9ShTwEhFzfVje5X6PVDy+tWIg X-Received: by 2002:aa7:9edd:0:b0:6e4:e65f:b0cd with SMTP id r29-20020aa79edd000000b006e4e65fb0cdmr4272750pfq.10.1708828825322; Sat, 24 Feb 2024 18:40:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828825; cv=pass; d=google.com; s=arc-20160816; b=Et4lYpRXuZGHrVLRf8lFO73x6jyn7d4kRX8dqwdbddJR7qvWoI1Gmo+nYplmWLkouW BiKHda7yQxp2zANYczpyKKjtR3uIUhGl/jrIpN/PrTxaBSQkKvy0cs0ZozzDfI/Il/GZ b1Qj7o4O36rqVPQ2syEkIdMfnLUKEcdBNBHGqzS6bHRJWhFH/OHPiyghZkiVXlszbXMN f/lBGyl/JEj5B2G/XCh2HUxlGb9dlmaQVUFiARIXm36l7kx/Pu06HvmuGETWWh5sxa/z GGhFCooEmAVOPZJWkTMWj21hwxB4S7DCMgBcRq83KTuDowEwKDxyFkupSu4DFyzmJfqD DDgw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=YboY8McwKZ8bbD5v2MLi4a2lKe9cbZ9uUy04W0G/mjo=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=WZhYACTKr/koBext82IuHEUFS5wP7PavntnTch687Qp93XvMzLrQ56KUOeNWsnJwXl AHqXFtUGluIiSwRkvAg2UMR8hcSBe5UCKEOfpsuol1QYmxEN5sNubm0F5CCv3GrGKuTE EVBwomhd66RK6e5fO/ElezBd1pKzNBl6T1BQNwe+1pYvyJhOg5QHppNJTKx7hAZnWmvZ sta83o/FbIXPTWdNR43H7YAXhifSL2FA1UM50JsrYvNQzXm+73B7t8JzFPObt3EyLQCF xP78KgYpPgrN5SI/K+2PJrClzX+xiSYPFsTKwFFVGZ8sUIISSggsghNVJGlF4a3z99rE 3new==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=cuC2Dm84; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79935-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79935-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x14-20020aa784ce000000b006e4a3d07e29si1621165pfn.80.2024.02.24.18.40.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:40:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79935-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=cuC2Dm84; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79935-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79935-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id F3F99281896 for ; Sun, 25 Feb 2024 02:40:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 88EEB1400B; Sun, 25 Feb 2024 02:38:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="cuC2Dm84" Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D472C2ED for ; Sun, 25 Feb 2024 02:38:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828724; cv=none; b=HjutlcGvtjMndjEZ69koehMyq90wBSddx/xGMsnFBAMQl9kuleJV2U47r2FRWVkZLHPqBesGF/cIQbd7WeYHY6OzGLv89M9ud72+NVrKWxGQ6j3rLDOYmgZUZQqatbdTTvMFoeOjTsRI4t7HLWVb3+lexKbcM9Gs5RjxsvI2vRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828724; c=relaxed/simple; bh=6mSrCXsXi3Y+WGJ2l3uOvmTKcFFx9GJUElF7uHdTim4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EakVbCqyHE9YLeWw2lR6JB9IqR528TVCtnqrtWWk+w8shWm54ctr6OLQxAp0j9/OFWsxU2kB7862geToq9obEKqD7v+1yplf+w0ZOuV20e9zmzuxUf7a9/CmBxXeDZYln0Fu1ilPIGjHIG7maD8F3o8jPtybbs9TN+tQivzjHSg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cuC2Dm84; arc=none smtp.client-ip=95.215.58.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828720; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YboY8McwKZ8bbD5v2MLi4a2lKe9cbZ9uUy04W0G/mjo=; b=cuC2Dm84QZNf9uWwz0FZ7YV3pOrzRtNt9Hw0gOtM7PYFz1pDsv20+1XBSvVcWihPqreTth K90XUlAFGmpHfZZDqSr+M45J26yZ46f1vJJNdPY6gd2ts/hEd29xg2yTb9d32jq5lLDGYP +EzpRuwWfP3QR4318kESDtCr2PM6SJM= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 07/21] bcachefs: Convert bch2_ioctl_fs_usage() to new accounting Date: Sat, 24 Feb 2024 21:38:09 -0500 Message-ID: <20240225023826.2413565-8-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791836894471669050 X-GMAIL-MSGID: 1791836894471669050 This converts bch2_ioctl_fs_usage() to read from the new disk accounting, via bch2_fs_replicas_usage_read(). Signed-off-by: Kent Overstreet --- fs/bcachefs/chardev.c | 68 ++++++++++++------------------------------- 1 file changed, 19 insertions(+), 49 deletions(-) diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c index 992939152f01..13ea852be153 100644 --- a/fs/bcachefs/chardev.c +++ b/fs/bcachefs/chardev.c @@ -5,6 +5,7 @@ #include "bcachefs_ioctl.h" #include "buckets.h" #include "chardev.h" +#include "disk_accounting.h" #include "journal.h" #include "move.h" #include "recovery.h" @@ -500,11 +501,11 @@ static long bch2_ioctl_data(struct bch_fs *c, static long bch2_ioctl_fs_usage(struct bch_fs *c, struct bch_ioctl_fs_usage __user *user_arg) { - struct bch_ioctl_fs_usage *arg = NULL; - struct bch_replicas_usage *dst_e, *dst_end; - struct bch_fs_usage_online *src; - u32 replica_entries_bytes; + struct bch_ioctl_fs_usage arg; + struct bch_fs_usage_online *src = NULL; + darray_char replicas = {}; unsigned i; + u32 replica_entries_bytes; int ret = 0; if (!test_bit(BCH_FS_started, &c->flags)) @@ -513,9 +514,16 @@ static long bch2_ioctl_fs_usage(struct bch_fs *c, if (get_user(replica_entries_bytes, &user_arg->replica_entries_bytes)) return -EFAULT; - arg = kzalloc(size_add(sizeof(*arg), replica_entries_bytes), GFP_KERNEL); - if (!arg) - return -ENOMEM; + ret = bch2_fs_replicas_usage_read(c, &replicas) ?: + (replica_entries_bytes < replicas.nr ? -ERANGE : 0) ?: + copy_to_user_errcode(&user_arg->replicas, replicas.data, replicas.nr); + if (ret) + goto err; + + arg.capacity = c->capacity; + arg.used = bch2_fs_sectors_used(c, src); + arg.online_reserved = src->online_reserved; + arg.replica_entries_bytes = replicas.nr; src = bch2_fs_usage_read(c); if (!src) { @@ -523,52 +531,14 @@ static long bch2_ioctl_fs_usage(struct bch_fs *c, goto err; } - arg->capacity = c->capacity; - arg->used = bch2_fs_sectors_used(c, src); - arg->online_reserved = src->online_reserved; - for (i = 0; i < BCH_REPLICAS_MAX; i++) - arg->persistent_reserved[i] = src->u.persistent_reserved[i]; - - dst_e = arg->replicas; - dst_end = (void *) arg->replicas + replica_entries_bytes; - - for (i = 0; i < c->replicas.nr; i++) { - struct bch_replicas_entry_v1 *src_e = - cpu_replicas_entry(&c->replicas, i); - - /* check that we have enough space for one replicas entry */ - if (dst_e + 1 > dst_end) { - ret = -ERANGE; - break; - } - - dst_e->sectors = src->u.replicas[i]; - dst_e->r = *src_e; - - /* recheck after setting nr_devs: */ - if (replicas_usage_next(dst_e) > dst_end) { - ret = -ERANGE; - break; - } - - memcpy(dst_e->r.devs, src_e->devs, src_e->nr_devs); - - dst_e = replicas_usage_next(dst_e); - } - - arg->replica_entries_bytes = (void *) dst_e - (void *) arg->replicas; - + arg.persistent_reserved[i] = src->u.persistent_reserved[i]; percpu_up_read(&c->mark_lock); - kfree(src); - - if (ret) - goto err; - ret = copy_to_user_errcode(user_arg, arg, - sizeof(*arg) + arg->replica_entries_bytes); + ret = copy_to_user_errcode(user_arg, &arg, sizeof(arg)); err: - kfree(arg); + darray_exit(&replicas); + kfree(src); return ret; } From patchwork Sun Feb 25 02:38:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205970 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406364dyb; Sat, 24 Feb 2024 18:41:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXe65xe6MnV7B9ijNc2TXS+la77RHn+Ed9S1mfZmE2BNHLp/GjBStJTn/vmFnWxxQbyngimS7O95G2Wqnhtgl6GRW/iqA== X-Google-Smtp-Source: AGHT+IE4O+dwFfWVc68iov2xxKEP1SQpVi+Z9DVuzZUsBri3ITIm8m1Qt/Mjtiz/dg+ZIrgB0Bw1 X-Received: by 2002:a17:90a:ad8a:b0:29a:a38c:8262 with SMTP id s10-20020a17090aad8a00b0029aa38c8262mr1257470pjq.48.1708828876995; Sat, 24 Feb 2024 18:41:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828876; cv=pass; d=google.com; s=arc-20160816; b=Ih4V+yqBAAVAIj/NSPQsGkfpUgMqF8rLjE674mFTgaEt2quLEZC1E0kFm2wbmu3e9l 3ZWRVXFyXI6GfiDxyfFZEKu73YvFP/Smx1g7uYb0yf4LdUB/oKyh5GC+6l2Gx0HIhwfi RnP6LAvm4GDzavlZKWeTpt/QTVEMh4dB3IRInxNHENXmoKHGAE0VV4ykdHYdHJdxXvh8 hYL/0N7rpG4BwA7xhTGJe/0HFcqKcxtYcPy8W/x1F2YBRqr6vB1OYdl2SgyvhsZQhXTk rn2nPY/9QLj5wjWI9tqJF7i6Z1xPwUMiXqz7b59Xas1TspeucD8vmpDq8yEMHWmZfO7p PI0w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=2Qqw98+K10fXhVd6VHbNJh2AoZpuXWUlc5V3sQ9k6Jk=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=PjM8EX8iQw8LpVXsDCcKUg45tP82rdaPN8XNZpjC1DqIeQnHDlYzLpQSCLDt0jdsfn I/k7ai7lQqZllXUFq/szazoM33cO/IFSR9btNvavEurQtU0dlIuV+ty5aLb+iEXtDfXm MYbwXd7Unwoo1k+5toSfxN6NcKbkVuWAouBBuqYOcuXZxZBlWtYBIzlKHJEhgZNckvPi S8fnh32aX6P1UmU33LokpjfTVueFKy6mKwmxhmuTJ5idm7n1U7LhT8oiwx4YBnsBWstU HqayvCYYpVWylAjPSjR01s4SX5d4ZoSJ7pTQtpfq4i7KD+A1EyQV2XvpGk54GKjS4I+C 6CoA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=meWmYrgS; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79938-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79938-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id z15-20020a17090a66cf00b0029970f8cb1bsi3470485pjl.80.2024.02.24.18.41.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:41:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79938-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=meWmYrgS; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79938-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79938-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C60692821B1 for ; Sun, 25 Feb 2024 02:41:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9BADF179B2; Sun, 25 Feb 2024 02:38:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="meWmYrgS" Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 742E9DDC4 for ; Sun, 25 Feb 2024 02:38:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828727; cv=none; b=ntpLDOOePepweODPFlWVv21t9aBxIFRKKKlS0De53hHJ5DU8vnjW/mfeJz8nCKSV/CT9FXB97IVuVVNHube2zDiteJxBkqEZRS4Ac5xb94SipWAODveIZNvwmaC9sEnBYrWRnEq4+ZSUicijmZ+x+3A2xRMmTwrj12GWtu7PThw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828727; c=relaxed/simple; bh=11AZzASOqgnR9hZpIfthFRQECtC3R7F7mXZu7eJ2AyY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mE5UrUnhjFZMx0doW7T8nLs9AkBmdIqYIvvr4AjlPoOByLoSG49PB8QyM7naLzSfp2GYfphUYGbKVblFuSZ9PgTqbcUCDZmdJBZoj9/jClQgHtOcocV/JtkhHWKtCWt0sbJRm4nvCOKM1Umu6jqxpZpry4vhML7Orm76n7rnqrE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=meWmYrgS; arc=none smtp.client-ip=95.215.58.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2Qqw98+K10fXhVd6VHbNJh2AoZpuXWUlc5V3sQ9k6Jk=; b=meWmYrgSRX7MdEz5MWTgRZSo+xAxpbBg6J3OUwA3jREQgddOHCPVIsX/otgbLgqfn95uUo jqYPtMcBepMrDoWz1yKqjc+kxvFRRz9npzVPvCsdjU8SXxnDWkCX9bO+tC+c3HFhnKcFAl UkJ3UDpXsIZsaHCp0REIjBFJIy2VL+c= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 08/21] bcachefs: kill bch2_fs_usage_read() Date: Sat, 24 Feb 2024 21:38:10 -0500 Message-ID: <20240225023826.2413565-9-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791836948784603745 X-GMAIL-MSGID: 1791836948784603745 With bch2_ioctl_fs_usage(), this is now dead code. Signed-off-by: Kent Overstreet --- fs/bcachefs/bcachefs.h | 4 ---- fs/bcachefs/buckets.c | 34 ---------------------------------- fs/bcachefs/buckets.h | 2 -- fs/bcachefs/chardev.c | 25 ++++++++++++------------- fs/bcachefs/replicas.c | 7 ------- fs/bcachefs/super.c | 2 -- 6 files changed, 12 insertions(+), 62 deletions(-) diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 91c40fde1925..5824cf57defd 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -912,10 +912,6 @@ struct bch_fs { struct bch_fs_usage __percpu *usage_gc; u64 __percpu *online_reserved; - /* single element mempool: */ - struct mutex usage_scratch_lock; - struct bch_fs_usage_online *usage_scratch; - struct io_clock io_clock[2]; /* JOURNAL SEQ BLACKLIST */ diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index 054c4c8d9c1b..24b53f449313 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -64,40 +64,6 @@ u64 bch2_fs_usage_read_one(struct bch_fs *c, u64 *v) return ret; } -struct bch_fs_usage_online *bch2_fs_usage_read(struct bch_fs *c) -{ - struct bch_fs_usage_online *ret; - unsigned nr_replicas = READ_ONCE(c->replicas.nr); - unsigned seq, i; -retry: - ret = kmalloc(__fs_usage_online_u64s(nr_replicas) * sizeof(u64), GFP_KERNEL); - if (unlikely(!ret)) - return NULL; - - percpu_down_read(&c->mark_lock); - - if (nr_replicas != c->replicas.nr) { - nr_replicas = c->replicas.nr; - percpu_up_read(&c->mark_lock); - kfree(ret); - goto retry; - } - - ret->online_reserved = percpu_u64_get(c->online_reserved); - - do { - seq = read_seqcount_begin(&c->usage_lock); - unsafe_memcpy(&ret->u, c->usage_base, - __fs_usage_u64s(nr_replicas) * sizeof(u64), - "embedded variable length struct"); - for (i = 0; i < ARRAY_SIZE(c->usage); i++) - acc_u64s_percpu((u64 *) &ret->u, (u64 __percpu *) c->usage[i], - __fs_usage_u64s(nr_replicas)); - } while (read_seqcount_retry(&c->usage_lock, seq)); - - return ret; -} - void bch2_fs_usage_acc_to_base(struct bch_fs *c, unsigned idx) { unsigned u64s = fs_usage_u64s(c); diff --git a/fs/bcachefs/buckets.h b/fs/bcachefs/buckets.h index 4e14615c770e..356f725a4fad 100644 --- a/fs/bcachefs/buckets.h +++ b/fs/bcachefs/buckets.h @@ -296,8 +296,6 @@ static inline unsigned dev_usage_u64s(void) u64 bch2_fs_usage_read_one(struct bch_fs *, u64 *); -struct bch_fs_usage_online *bch2_fs_usage_read(struct bch_fs *); - void bch2_fs_usage_acc_to_base(struct bch_fs *, unsigned); void bch2_fs_usage_to_text(struct printbuf *, diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c index 13ea852be153..03a1339e8f3b 100644 --- a/fs/bcachefs/chardev.c +++ b/fs/bcachefs/chardev.c @@ -502,9 +502,7 @@ static long bch2_ioctl_fs_usage(struct bch_fs *c, struct bch_ioctl_fs_usage __user *user_arg) { struct bch_ioctl_fs_usage arg; - struct bch_fs_usage_online *src = NULL; darray_char replicas = {}; - unsigned i; u32 replica_entries_bytes; int ret = 0; @@ -520,25 +518,26 @@ static long bch2_ioctl_fs_usage(struct bch_fs *c, if (ret) goto err; + struct bch_fs_usage_short u = bch2_fs_usage_read_short(c); arg.capacity = c->capacity; - arg.used = bch2_fs_sectors_used(c, src); - arg.online_reserved = src->online_reserved; + arg.used = u.used; + arg.online_reserved = percpu_u64_get(c->online_reserved); arg.replica_entries_bytes = replicas.nr; - src = bch2_fs_usage_read(c); - if (!src) { - ret = -ENOMEM; - goto err; - } + for (unsigned i = 0; i < BCH_REPLICAS_MAX; i++) { + struct disk_accounting_key k = { + .type = BCH_DISK_ACCOUNTING_persistent_reserved, + .persistent_reserved.nr_replicas = i, + }; - for (i = 0; i < BCH_REPLICAS_MAX; i++) - arg.persistent_reserved[i] = src->u.persistent_reserved[i]; - percpu_up_read(&c->mark_lock); + bch2_accounting_mem_read(c, + disk_accounting_key_to_bpos(&k), + &arg.persistent_reserved[i], 1); + } ret = copy_to_user_errcode(user_arg, &arg, sizeof(arg)); err: darray_exit(&replicas); - kfree(src); return ret; } diff --git a/fs/bcachefs/replicas.c b/fs/bcachefs/replicas.c index dde581a49e28..d02eb03d2ebd 100644 --- a/fs/bcachefs/replicas.c +++ b/fs/bcachefs/replicas.c @@ -319,13 +319,10 @@ static int replicas_table_update(struct bch_fs *c, struct bch_replicas_cpu *new_r) { struct bch_fs_usage __percpu *new_usage[JOURNAL_BUF_NR]; - struct bch_fs_usage_online *new_scratch = NULL; struct bch_fs_usage __percpu *new_gc = NULL; struct bch_fs_usage *new_base = NULL; unsigned i, bytes = sizeof(struct bch_fs_usage) + sizeof(u64) * new_r->nr; - unsigned scratch_bytes = sizeof(struct bch_fs_usage_online) + - sizeof(u64) * new_r->nr; int ret = 0; memset(new_usage, 0, sizeof(new_usage)); @@ -336,7 +333,6 @@ static int replicas_table_update(struct bch_fs *c, goto err; if (!(new_base = kzalloc(bytes, GFP_KERNEL)) || - !(new_scratch = kmalloc(scratch_bytes, GFP_KERNEL)) || (c->usage_gc && !(new_gc = __alloc_percpu_gfp(bytes, sizeof(u64), GFP_KERNEL)))) goto err; @@ -355,12 +351,10 @@ static int replicas_table_update(struct bch_fs *c, for (i = 0; i < ARRAY_SIZE(new_usage); i++) swap(c->usage[i], new_usage[i]); swap(c->usage_base, new_base); - swap(c->usage_scratch, new_scratch); swap(c->usage_gc, new_gc); swap(c->replicas, *new_r); out: free_percpu(new_gc); - kfree(new_scratch); for (i = 0; i < ARRAY_SIZE(new_usage); i++) free_percpu(new_usage[i]); kfree(new_base); @@ -1024,7 +1018,6 @@ void bch2_fs_replicas_exit(struct bch_fs *c) { unsigned i; - kfree(c->usage_scratch); for (i = 0; i < ARRAY_SIZE(c->usage); i++) free_percpu(c->usage[i]); kfree(c->usage_base); diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index 685d54d0ddbb..a26472f4620a 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -783,8 +783,6 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts) INIT_LIST_HEAD(&c->list); - mutex_init(&c->usage_scratch_lock); - mutex_init(&c->bio_bounce_pages_lock); mutex_init(&c->snapshot_table_lock); init_rwsem(&c->snapshot_create_lock); From patchwork Sun Feb 25 02:38:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205969 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406350dyb; Sat, 24 Feb 2024 18:41:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXrFL7TVsheJPdnmDz82wM7H6i7z/CjhmFz/CkWuKe5eIec8N9XP8SSRJqEx0R/DSX/fpXmQnkwVmBES3zf581CoHAEjg== X-Google-Smtp-Source: AGHT+IEZT8Y4aMqPQ1hGgxgls75xdcdvrQoGA/YjfemzGy19J8yQz4VqqlWGPquLxH6GibKfrBlD X-Received: by 2002:a17:902:8d85:b0:1db:fc18:2db9 with SMTP id v5-20020a1709028d8500b001dbfc182db9mr3356533plo.64.1708828872506; Sat, 24 Feb 2024 18:41:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828872; cv=pass; d=google.com; s=arc-20160816; b=dLz61f+kMyVfU3k/Hy2DHnaUsQoh3qj1u2f05jN08+MNthF3gEWBcXHSa8sB+4tyuR wJ3o7wArbB4pCEEs7zGQwtho8UDU+1Q24s1yYDH3JD6s57ferNrv1udxmo+qN4uP5iva X2WMhnr/xr0etMYnHCP/p6MZQs1tv8Y5964o+OV+r8P2m4X37udxb4UJHf/UL7W9duip WKVYJ0YkRnjdwTrhg84OxDgTUl+ta6zGfEUzIXRbMvc2dCQtpA/1i+NqysGHa67ieMWe AY/UnxhavBEX7vPY5Q/2H5ygiMuE2nCpDgGeaJ/jIAXkeEDv4EGteXjiDKICAlj5Xv/N mZQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=sochMrpvNfdQFlEjZm/ljf2msW7UTBhTHpI35Xx9Jzs=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=WryRcB07s+Oev0ogN4NzvcPSLpb/ewBlRdRNX4GBs2G8D3gjBRn1v1cJBn8lAwJM+8 HcBcm9tZas1R7EQIReNcSKtXMJOJ9CjHdcpER6EObRfsot15ztLuZ+qf4sIrNOc8AVXr ZDp0by2YeM8fungPvFgzN8ekvuzDWNQQmoB4y/a8N04lDDr5/4N4f6ekZSIjalaELFUU 1/3cHdVK2LUcVSzM8126yGDxu49TCA9AVrNl4v0J/GAKTxc5B0ZGLnF/t2tDNv2eky62 xUY7jzrriz+FB3PJJqWQDXGIXFDUucZjoe6WjzHtCKInDQ5kew2WYkaxhWy9l8UJRFsg 4erg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=CHg59nt2; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79937-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79937-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b8-20020a170903228800b001d9859103e0si1586022plh.153.2024.02.24.18.41.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:41:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79937-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=CHg59nt2; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79937-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79937-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id DAAC1B20E11 for ; Sun, 25 Feb 2024 02:40:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D0F717551; Sun, 25 Feb 2024 02:38:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="CHg59nt2" Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50AA5EEC6 for ; Sun, 25 Feb 2024 02:38:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828726; cv=none; b=qmHV2z7ERKCqGCUnnRSioFbzab83i+m6QFOPcUHuwLttmkd8h67Q0wrSJNbUVM8ZcQadRK/Y+vf7bxI+Z4E+4C1x0PXv+gwInEUgrhnY58f1DdMyARH57vjOestvbrGemDlCWiNwysSuU+/wABBsT07CR/Bh1z14xHCo/ilHdaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828726; c=relaxed/simple; bh=u2DvZcMqKB6og8Lq7jawbKRlhTvu+07YR4ER+eXC/KI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VCHbipdlgS7elrLoTJ7ObypNXCz+xGuwy/dRxDmMt/+SMA+DPy+9dfDdU4pB0jrIu+RxwFlkwa+Ysil/R7umr+t3qJQcN8mDW7lnU89tXl30Z/8d5+YkpRBrvH9pn1mBJ+CjPWRbAciDvgdt4SbT8zi7qfk7rv24S1zcjZrNIro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=CHg59nt2; arc=none smtp.client-ip=95.215.58.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828722; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sochMrpvNfdQFlEjZm/ljf2msW7UTBhTHpI35Xx9Jzs=; b=CHg59nt2Qc17U0pd3Uar1bIzO02xmb907r29R+H1Ixq3v6WI/2XSZIJLjqKNjZ6nEm1rxD RhcM4nF1wtBLX7jXN0JoWApSoWtOFmwradLNdJ5wZqB+gnt8Bbs4UbGeDAU1nq6dOFNBYL gVrJR7dzjGlV4CQotVij2gybSgRaPH4= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 09/21] bcachefs: Kill writing old accounting to journal Date: Sat, 24 Feb 2024 21:38:11 -0500 Message-ID: <20240225023826.2413565-10-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791836943936433385 X-GMAIL-MSGID: 1791836943936433385 More ripping out of the old disk space accounting. Note that the new disk space accounting is incompatible with the old, and writing out old style disk space accounting with the new code is infeasible. This means upgrading and downgrading past this version requires regenerating accounting. Signed-off-by: Kent Overstreet --- fs/bcachefs/sb-clean.c | 45 ------------------------------------------ 1 file changed, 45 deletions(-) diff --git a/fs/bcachefs/sb-clean.c b/fs/bcachefs/sb-clean.c index a7f2cc774492..1af2785653f6 100644 --- a/fs/bcachefs/sb-clean.c +++ b/fs/bcachefs/sb-clean.c @@ -175,25 +175,6 @@ void bch2_journal_super_entries_add_common(struct bch_fs *c, struct jset_entry **end, u64 journal_seq) { - percpu_down_read(&c->mark_lock); - - if (!journal_seq) { - for (unsigned i = 0; i < ARRAY_SIZE(c->usage); i++) - bch2_fs_usage_acc_to_base(c, i); - } else { - bch2_fs_usage_acc_to_base(c, journal_seq & JOURNAL_BUF_MASK); - } - - { - struct jset_entry_usage *u = - container_of(jset_entry_init(end, sizeof(*u)), - struct jset_entry_usage, entry); - - u->entry.type = BCH_JSET_ENTRY_usage; - u->entry.btree_id = BCH_FS_USAGE_inodes; - u->v = cpu_to_le64(c->usage_base->b.nr_inodes); - } - { struct jset_entry_usage *u = container_of(jset_entry_init(end, sizeof(*u)), @@ -204,32 +185,6 @@ void bch2_journal_super_entries_add_common(struct bch_fs *c, u->v = cpu_to_le64(atomic64_read(&c->key_version)); } - for (unsigned i = 0; i < BCH_REPLICAS_MAX; i++) { - struct jset_entry_usage *u = - container_of(jset_entry_init(end, sizeof(*u)), - struct jset_entry_usage, entry); - - u->entry.type = BCH_JSET_ENTRY_usage; - u->entry.btree_id = BCH_FS_USAGE_reserved; - u->entry.level = i; - u->v = cpu_to_le64(c->usage_base->persistent_reserved[i]); - } - - for (unsigned i = 0; i < c->replicas.nr; i++) { - struct bch_replicas_entry_v1 *e = - cpu_replicas_entry(&c->replicas, i); - struct jset_entry_data_usage *u = - container_of(jset_entry_init(end, sizeof(*u) + e->nr_devs), - struct jset_entry_data_usage, entry); - - u->entry.type = BCH_JSET_ENTRY_data_usage; - u->v = cpu_to_le64(c->usage_base->replicas[i]); - unsafe_memcpy(&u->r, e, replicas_entry_bytes(e), - "embedded variable length struct"); - } - - percpu_up_read(&c->mark_lock); - for (unsigned i = 0; i < 2; i++) { struct jset_entry_clock *clock = container_of(jset_entry_init(end, sizeof(*clock)), From patchwork Sun Feb 25 02:38:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205973 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406458dyb; Sat, 24 Feb 2024 18:41:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXrbatfBJydVdCfzD+4jkuIf+DzIejJ476z34xj/wbf6LDZP3y0LcIRu6N40AQmpyU1h2cF43LcREKe6+MvyCIZrL/WPw== X-Google-Smtp-Source: AGHT+IFXVeFTarIaJWOs6Fi+MJQLC9lRGpE0nUrx5IqoyLWywLlhuBOkwEts/3i07JxC93bbtTwS X-Received: by 2002:a05:6a20:d908:b0:1a0:eddb:f2f7 with SMTP id jd8-20020a056a20d90800b001a0eddbf2f7mr3597747pzb.51.1708828904896; Sat, 24 Feb 2024 18:41:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828904; cv=pass; d=google.com; s=arc-20160816; b=uXrg8XA82T5vrL4u2yhdEhtFfl9oIdSzSsBPi4F+nF9jaO+X6yYpUEcXaGrR149C1g 3fp98fIwTtXgeQU4HodSECJZXxdci/2bBqFRqK9wZLbIEpNl4QXFjxcjEGADdqB68Kj7 N6OnM/yRrhfKU8gXbpecZuIEZ/3Eedxt0kZ6tS1moEB7A4r+0GNBsDA1Hvy2SH+9tPXw UrPZjH85FGt8zwq4jRX3h8uGf7MwCGEl2v2YXYwImDBCr+qFFmmlRyx75NuOjV8RpPPv YYdSOrVM58wANvdMz7aqtBrGDX4EadmDWusJI+Wscge52pWoe7NnIRzrjESEDYCP9UwI bewg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=feltRpT2GfQrxVlgaHX2FneBv3ceqjBYGcQemtXMFOY=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=ECTymEk9cgckfCO4XDHF5H3dJAkoAtIM6r5FrcuoydzfzagpWub0hUiyhBRhI82e5u 30P1Lv0t59gG88hDXlTxFZ9RqGwvllAkzB4WqZqSFVCrKHHxBWZGNZ38Fzb64GTN52Md YJFKylCVIW9+Uh7FCstp4u/RgEDZvtd2d1sAnprP+G0/CxNg4DB+3QgKys5v/SQoj4u3 PsnKkhGHUolt+Li8in6k94c613KmspXfa5XslcdDncGhsJUQt5RZ0rXzaaDa6CPgUfC6 77br+zXXOjeU/MQ9xL/xAVMuY43/ILcwSQjSIxbbrvWZa2Lwl8TKyUT1zbt4+GdeqDRs Zykg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="A3/4XoC1"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79939-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79939-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g1-20020a63dd41000000b005d8bd587734si1589540pgj.772.2024.02.24.18.41.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:41:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79939-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="A3/4XoC1"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79939-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79939-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AB9ED2822B4 for ; Sun, 25 Feb 2024 02:41:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CCC8C18EA2; Sun, 25 Feb 2024 02:38:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="A3/4XoC1" Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37DCFFC12 for ; Sun, 25 Feb 2024 02:38:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828727; cv=none; b=tsZI5o4MT4aHmR8lkeNNb+6yEmATpiefMnFKRgM5wuaTbkx4vjK0kTMAplGs3Qi4fNNYm7DNs5Nt7GKqPuDnoN5Ad2noZoVOR2cwitQQKQN+PFS3Mv7tBTjSPe5lCYnXmcwBqqRY9sb7JtYwMBlLyOxYSGBJlkpjYaTBqc5vRcs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828727; c=relaxed/simple; bh=4ofseTkI0NYTSy2SqN8qmDFsYCyfnkox/iwtJ5pAAVE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZutdYWYH7tqlUoJKEGttJCZnElpq16clbPPfgkiCQyXMUnEArDgvjHRgBzPNmtf+2yMvMX3e5JTS5AhH1yRIOBGraZGGFhIfsloeT6C9uUb18YQWYIRNhCqoeuy3iHDk95S998tj7a8zTIKRWJwsgRtDLgd0cdzsUPFFgPyjqfQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=A3/4XoC1; arc=none smtp.client-ip=95.215.58.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828723; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=feltRpT2GfQrxVlgaHX2FneBv3ceqjBYGcQemtXMFOY=; b=A3/4XoC1dWRBf8ZzMlzDrBAEbZBt1AXPOutmDEPLieM+m75bBVp0nfoXVGtjp/bKQZRPpK 1CM8EAimSlVXFd7fO+2g2cg1EF2iHD7bbfpacZ0GjORDwdXORqRvt4iXXPLyrWv0Q+AZGo xSg8KXEbYVzTw1FmzAaSexVFA59CH5A= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 10/21] bcachefs: Delete journal-buf-sharded old style accounting Date: Sat, 24 Feb 2024 21:38:12 -0500 Message-ID: <20240225023826.2413565-11-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791836977697588169 X-GMAIL-MSGID: 1791836977697588169 More deletion of dead code. Signed-off-by: Kent Overstreet --- fs/bcachefs/bcachefs.h | 3 +- fs/bcachefs/btree_gc.c | 9 ++--- fs/bcachefs/buckets.c | 61 ++++----------------------------- fs/bcachefs/buckets.h | 4 --- fs/bcachefs/disk_accounting.c | 2 +- fs/bcachefs/recovery.c | 20 +---------- fs/bcachefs/replicas.c | 63 +++-------------------------------- fs/bcachefs/replicas.h | 4 --- fs/bcachefs/super.c | 2 ++ 9 files changed, 21 insertions(+), 147 deletions(-) diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 5824cf57defd..2e7c4d10c951 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -907,8 +907,7 @@ struct bch_fs { struct percpu_rw_semaphore mark_lock; seqcount_t usage_lock; - struct bch_fs_usage *usage_base; - struct bch_fs_usage __percpu *usage[JOURNAL_BUF_NR]; + struct bch_fs_usage_base __percpu *usage; struct bch_fs_usage __percpu *usage_gc; u64 __percpu *online_reserved; diff --git a/fs/bcachefs/btree_gc.c b/fs/bcachefs/btree_gc.c index 93826749356e..15a8796197f3 100644 --- a/fs/bcachefs/btree_gc.c +++ b/fs/bcachefs/btree_gc.c @@ -1229,10 +1229,8 @@ static int bch2_gc_done(struct bch_fs *c, #define copy_fs_field(_err, _f, _msg, ...) \ copy_field(_err, _f, "fs has wrong " _msg, ##__VA_ARGS__) - for (i = 0; i < ARRAY_SIZE(c->usage); i++) - bch2_fs_usage_acc_to_base(c, i); - __for_each_member_device(c, ca) { + /* XXX */ struct bch_dev_usage *dst = this_cpu_ptr(ca->usage); struct bch_dev_usage *src = (void *) bch2_acc_percpu_u64s((u64 __percpu *) ca->usage_gc, @@ -1249,8 +1247,10 @@ static int bch2_gc_done(struct bch_fs *c, } { +#if 0 unsigned nr = fs_usage_u64s(c); - struct bch_fs_usage *dst = c->usage_base; + /* XX: */ + struct bch_fs_usage *dst = this_cpu_ptr(c->usage); struct bch_fs_usage *src = (void *) bch2_acc_percpu_u64s((u64 __percpu *) c->usage_gc, nr); @@ -1290,6 +1290,7 @@ static int bch2_gc_done(struct bch_fs *c, copy_fs_field(fs_usage_replicas_wrong, replicas[i], "%s", buf.buf); } +#endif } #undef copy_fs_field diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index 24b53f449313..8476bd5cb3af 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -26,61 +26,12 @@ #include -static inline struct bch_fs_usage *fs_usage_ptr(struct bch_fs *c, - unsigned journal_seq, - bool gc) -{ - percpu_rwsem_assert_held(&c->mark_lock); - BUG_ON(!gc && !journal_seq); - - return this_cpu_ptr(gc - ? c->usage_gc - : c->usage[journal_seq & JOURNAL_BUF_MASK]); -} - void bch2_dev_usage_read_fast(struct bch_dev *ca, struct bch_dev_usage *usage) { memset(usage, 0, sizeof(*usage)); acc_u64s_percpu((u64 *) usage, (u64 __percpu *) ca->usage, dev_usage_u64s()); } -u64 bch2_fs_usage_read_one(struct bch_fs *c, u64 *v) -{ - ssize_t offset = v - (u64 *) c->usage_base; - unsigned i, seq; - u64 ret; - - BUG_ON(offset < 0 || offset >= fs_usage_u64s(c)); - percpu_rwsem_assert_held(&c->mark_lock); - - do { - seq = read_seqcount_begin(&c->usage_lock); - ret = *v; - - for (i = 0; i < ARRAY_SIZE(c->usage); i++) - ret += percpu_u64_get((u64 __percpu *) c->usage[i] + offset); - } while (read_seqcount_retry(&c->usage_lock, seq)); - - return ret; -} - -void bch2_fs_usage_acc_to_base(struct bch_fs *c, unsigned idx) -{ - unsigned u64s = fs_usage_u64s(c); - - BUG_ON(idx >= ARRAY_SIZE(c->usage)); - - preempt_disable(); - write_seqcount_begin(&c->usage_lock); - - acc_u64s_percpu((u64 *) c->usage_base, - (u64 __percpu *) c->usage[idx], u64s); - percpu_memset(c->usage[idx], 0, u64s * sizeof(u64)); - - write_seqcount_end(&c->usage_lock); - preempt_enable(); -} - void bch2_fs_usage_to_text(struct printbuf *out, struct bch_fs *c, struct bch_fs_usage_online *fs_usage) @@ -142,17 +93,17 @@ __bch2_fs_usage_read_short(struct bch_fs *c) u64 data, reserved; ret.capacity = c->capacity - - bch2_fs_usage_read_one(c, &c->usage_base->b.hidden); + percpu_u64_get(&c->usage->hidden); - data = bch2_fs_usage_read_one(c, &c->usage_base->b.data) + - bch2_fs_usage_read_one(c, &c->usage_base->b.btree); - reserved = bch2_fs_usage_read_one(c, &c->usage_base->b.reserved) + + data = percpu_u64_get(&c->usage->data) + + percpu_u64_get(&c->usage->btree); + reserved = percpu_u64_get(&c->usage->reserved) + percpu_u64_get(c->online_reserved); ret.used = min(ret.capacity, data + reserve_factor(reserved)); ret.free = ret.capacity - ret.used; - ret.nr_inodes = bch2_fs_usage_read_one(c, &c->usage_base->b.nr_inodes); + ret.nr_inodes = percpu_u64_get(&c->usage->nr_inodes); return ret; } @@ -461,7 +412,7 @@ void bch2_trans_account_disk_usage_change(struct btree_trans *trans) percpu_down_read(&c->mark_lock); preempt_disable(); - struct bch_fs_usage_base *dst = &fs_usage_ptr(c, trans->journal_res.seq, false)->b; + struct bch_fs_usage_base *dst = this_cpu_ptr(c->usage); struct bch_fs_usage_base *src = &trans->fs_usage_delta; s64 added = src->btree + src->data + src->reserved; diff --git a/fs/bcachefs/buckets.h b/fs/bcachefs/buckets.h index 356f725a4fad..dfdf1b3ee817 100644 --- a/fs/bcachefs/buckets.h +++ b/fs/bcachefs/buckets.h @@ -294,10 +294,6 @@ static inline unsigned dev_usage_u64s(void) return sizeof(struct bch_dev_usage) / sizeof(u64); } -u64 bch2_fs_usage_read_one(struct bch_fs *, u64 *); - -void bch2_fs_usage_acc_to_base(struct bch_fs *, unsigned); - void bch2_fs_usage_to_text(struct printbuf *, struct bch_fs *, struct bch_fs_usage_online *); diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c index e0114d8eb5a8..f898323f72c7 100644 --- a/fs/bcachefs/disk_accounting.c +++ b/fs/bcachefs/disk_accounting.c @@ -314,7 +314,7 @@ int bch2_accounting_read(struct bch_fs *c) percpu_down_read(&c->mark_lock); preempt_disable(); - struct bch_fs_usage_base *usage = &c->usage_base->b; + struct bch_fs_usage_base *usage = this_cpu_ptr(c->usage); for (unsigned i = 0; i < acc->k.nr; i++) { struct disk_accounting_key k; diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c index 4936b18e5a58..18fd71960d2e 100644 --- a/fs/bcachefs/recovery.c +++ b/fs/bcachefs/recovery.c @@ -344,28 +344,10 @@ static int journal_replay_entry_early(struct bch_fs *c, container_of(entry, struct jset_entry_usage, entry); switch (entry->btree_id) { - case BCH_FS_USAGE_reserved: - if (entry->level < BCH_REPLICAS_MAX) - c->usage_base->persistent_reserved[entry->level] = - le64_to_cpu(u->v); - break; - case BCH_FS_USAGE_inodes: - c->usage_base->b.nr_inodes = le64_to_cpu(u->v); - break; case BCH_FS_USAGE_key_version: - atomic64_set(&c->key_version, - le64_to_cpu(u->v)); + atomic64_set(&c->key_version, le64_to_cpu(u->v)); break; } - - break; - } - case BCH_JSET_ENTRY_data_usage: { - struct jset_entry_data_usage *u = - container_of(entry, struct jset_entry_data_usage, entry); - - ret = bch2_replicas_set_usage(c, &u->r, - le64_to_cpu(u->v)); break; } case BCH_JSET_ENTRY_blacklist: { diff --git a/fs/bcachefs/replicas.c b/fs/bcachefs/replicas.c index d02eb03d2ebd..6dca705eaf1f 100644 --- a/fs/bcachefs/replicas.c +++ b/fs/bcachefs/replicas.c @@ -318,46 +318,23 @@ static void __replicas_table_update_pcpu(struct bch_fs_usage __percpu *dst_p, static int replicas_table_update(struct bch_fs *c, struct bch_replicas_cpu *new_r) { - struct bch_fs_usage __percpu *new_usage[JOURNAL_BUF_NR]; struct bch_fs_usage __percpu *new_gc = NULL; - struct bch_fs_usage *new_base = NULL; - unsigned i, bytes = sizeof(struct bch_fs_usage) + + unsigned bytes = sizeof(struct bch_fs_usage) + sizeof(u64) * new_r->nr; int ret = 0; - memset(new_usage, 0, sizeof(new_usage)); - - for (i = 0; i < ARRAY_SIZE(new_usage); i++) - if (!(new_usage[i] = __alloc_percpu_gfp(bytes, - sizeof(u64), GFP_KERNEL))) - goto err; - - if (!(new_base = kzalloc(bytes, GFP_KERNEL)) || - (c->usage_gc && + if ((c->usage_gc && !(new_gc = __alloc_percpu_gfp(bytes, sizeof(u64), GFP_KERNEL)))) goto err; - for (i = 0; i < ARRAY_SIZE(new_usage); i++) - if (c->usage[i]) - __replicas_table_update_pcpu(new_usage[i], new_r, - c->usage[i], &c->replicas); - if (c->usage_base) - __replicas_table_update(new_base, new_r, - c->usage_base, &c->replicas); if (c->usage_gc) __replicas_table_update_pcpu(new_gc, new_r, c->usage_gc, &c->replicas); - for (i = 0; i < ARRAY_SIZE(new_usage); i++) - swap(c->usage[i], new_usage[i]); - swap(c->usage_base, new_base); swap(c->usage_gc, new_gc); swap(c->replicas, *new_r); out: free_percpu(new_gc); - for (i = 0; i < ARRAY_SIZE(new_usage); i++) - free_percpu(new_usage[i]); - kfree(new_base); return ret; err: bch_err(c, "error updating replicas table: memory allocation failure"); @@ -544,6 +521,8 @@ int bch2_replicas_gc_start(struct bch_fs *c, unsigned typemask) */ int bch2_replicas_gc2(struct bch_fs *c) { + return 0; +#if 0 struct bch_replicas_cpu new = { 0 }; unsigned i, nr; int ret = 0; @@ -598,34 +577,7 @@ int bch2_replicas_gc2(struct bch_fs *c) mutex_unlock(&c->sb_lock); return ret; -} - -int bch2_replicas_set_usage(struct bch_fs *c, - struct bch_replicas_entry_v1 *r, - u64 sectors) -{ - int ret, idx = bch2_replicas_entry_idx(c, r); - - if (idx < 0) { - struct bch_replicas_cpu n; - - n = cpu_replicas_add_entry(c, &c->replicas, r); - if (!n.entries) - return -BCH_ERR_ENOMEM_cpu_replicas; - - ret = replicas_table_update(c, &n); - if (ret) - return ret; - - kfree(n.entries); - - idx = bch2_replicas_entry_idx(c, r); - BUG_ON(ret < 0); - } - - c->usage_base->replicas[idx] = sectors; - - return 0; +#endif } /* Replicas tracking - superblock: */ @@ -1016,11 +968,6 @@ unsigned bch2_dev_has_data(struct bch_fs *c, struct bch_dev *ca) void bch2_fs_replicas_exit(struct bch_fs *c) { - unsigned i; - - for (i = 0; i < ARRAY_SIZE(c->usage); i++) - free_percpu(c->usage[i]); - kfree(c->usage_base); kfree(c->replicas.entries); kfree(c->replicas_gc.entries); } diff --git a/fs/bcachefs/replicas.h b/fs/bcachefs/replicas.h index f00c586f8cd9..eac2dff20423 100644 --- a/fs/bcachefs/replicas.h +++ b/fs/bcachefs/replicas.h @@ -54,10 +54,6 @@ int bch2_replicas_gc_end(struct bch_fs *, int); int bch2_replicas_gc_start(struct bch_fs *, unsigned); int bch2_replicas_gc2(struct bch_fs *); -int bch2_replicas_set_usage(struct bch_fs *, - struct bch_replicas_entry_v1 *, - u64); - #define for_each_cpu_replicas_entry(_r, _i) \ for (_i = (_r)->entries; \ (void *) (_i) < (void *) (_r)->entries + (_r)->nr * (_r)->entry_size;\ diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index a26472f4620a..30b41c8de309 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -567,6 +567,7 @@ static void __bch2_fs_free(struct bch_fs *c) darray_exit(&c->btree_roots_extra); free_percpu(c->pcpu); + free_percpu(c->usage); mempool_exit(&c->large_bkey_pool); mempool_exit(&c->btree_bounce_pool); bioset_exit(&c->btree_bio); @@ -893,6 +894,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts) offsetof(struct btree_write_bio, wbio.bio)), BIOSET_NEED_BVECS) || !(c->pcpu = alloc_percpu(struct bch_fs_pcpu)) || + !(c->usage = alloc_percpu(struct bch_fs_usage_base)) || !(c->online_reserved = alloc_percpu(u64)) || mempool_init_kvmalloc_pool(&c->btree_bounce_pool, 1, c->opts.btree_node_size) || From patchwork Sun Feb 25 02:38:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205971 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406382dyb; Sat, 24 Feb 2024 18:41:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUGW8GJb/oRkWMpjeIjvQthypDaN14xDmFnncDVeC3BR0b8mGb/AatH8Q+w/ZpTEx33lhXRVKmTeB4gk08fjwyAe4J+SQ== X-Google-Smtp-Source: AGHT+IH2ocuTj3Rzu75RXmxnI7avr+9CuHJyHvPMzIiANwekQ0AvMbEYQ3MuuM4acCBYmk5FowZC X-Received: by 2002:a17:906:1718:b0:a3f:a2b6:74b5 with SMTP id c24-20020a170906171800b00a3fa2b674b5mr2314463eje.60.1708828882454; Sat, 24 Feb 2024 18:41:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828882; cv=pass; d=google.com; s=arc-20160816; b=t+pRu1jwAxuxlTDPlHMoSHQqzd7N3T4a6noLs7Yo67T5l1eUa+1tT3CvIDYMss2LNm 7IefG0AYXYXb/fFLtqWgVm+3NiEHpYn2mNcpVHCbfzRrvO3bFcHhKDY1OCiLQz/U9F3o 7oS1AjIfzTOOndgr66FuHGo23VL9VEyVTbAcrnflY1xgWz3XrGzW3DAlJwOXRkf3uNQk I+sDulId8hcN46mn7E9PvMUHh6LXFxIMIKnJOanBkpVp/hrzupw+71aOTFGYbT4l+2QR U7eVoqLchGKZNBFrDZI33s/TpeGe8s4KlLrpto7fIaYiMxfu3Xssj7s+YXgLDNLk3tJy KKHQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=7nYmc8JzzayqwmwTcyeDB+fspGtJHDUPXZk3mSOrddE=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=vVe3pVHQSawiGpqoBLqdtEavfIThYQFY0T4I79p61gBOMapElQKc/wHsNseexcqtCU 2+RWhOunOl9DQ2Xwif9gn4LmkIlqhfmpHkQx6ZAy5xGIf9RGFc6uxpS/Hng5kPHv29qb zs/UbeHO5tqAerrtYdc1583WKvCynCuUY01QVoXC7xF/FCIRUOU42KkZ4wqTNJ0awA/r zHCAk/tgY8yKEYDKfCHg5VnxyFVAO+WOKdoo9vo8JkfdTKpVjGhgjGJCJuUQzmsNCYli O+obzRyUqm6RVyeDYFkHcCtSvOXVm+LmCLyn3Xm2aiRABdYEdBSzUBl9SPuE+CaCTEti DLjA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=QX5sk03l; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79940-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79940-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u13-20020a1709060b0d00b00a3fc779c150si962533ejg.671.2024.02.24.18.41.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:41:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79940-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=QX5sk03l; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79940-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79940-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 156901F217D5 for ; Sun, 25 Feb 2024 02:41:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0000F17BC2; Sun, 25 Feb 2024 02:38:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="QX5sk03l" Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB4CE11718 for ; Sun, 25 Feb 2024 02:38:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828728; cv=none; b=fg/YDDzcdYYsdF5kbfWI6qArGtPDTLc8qUXI5dfsM0SFUY1A3tU7mif07/ks4mnGOjkAPwe3z26wKS4mC5uSwih+nFjCplAf2TpvJ/1TFgEcUgKUs9cOs7sULt1sI733+dNNAmtyyTXHVACHdoH33U/8OCqRdRdG5z16Z7Agzv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828728; c=relaxed/simple; bh=E/Dw+70hY8yzNuYISXbZNy7QhvNTNxoGY+Dru6pQDaY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C+s0rnO+VUToOx3Fyk9Hwjm24jz+GRD7m5vxaW4MV0AUZiV48PVsytA+ePDGfUQPuZL9vh3W6nleXuCMdotrBobuo+3kV9rl7pUvvgau7/sgXUjV73FoV/6BKaJEz7fYmbehOtxb81jsXyCZ/WQChjXQTuX+iGvxplVL+ZM625Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=QX5sk03l; arc=none smtp.client-ip=95.215.58.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828724; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7nYmc8JzzayqwmwTcyeDB+fspGtJHDUPXZk3mSOrddE=; b=QX5sk03loVgVOzDEg/keMY5owPiZTJ3+TdpipV+jUiDa++8JEBtz5FnYXvCpNkH5KQT6gy bD7x6WgvlMGsCwMbJ5P8aWaS6aqKDIPsAaBUZtNstJtQXdmQtSwXcmktZ7uUjhhkyXIDZS q7BL40Ei0WhoEKhdATFkWEamlBHafuM= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 11/21] bcachefs: Kill bch2_fs_usage_to_text() Date: Sat, 24 Feb 2024 21:38:13 -0500 Message-ID: <20240225023826.2413565-12-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791836954546840278 X-GMAIL-MSGID: 1791836954546840278 Dead code. Signed-off-by: Kent Overstreet --- fs/bcachefs/buckets.c | 39 --------------------------------------- fs/bcachefs/buckets.h | 3 --- 2 files changed, 42 deletions(-) diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index 8476bd5cb3af..c261fa3a0273 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -32,45 +32,6 @@ void bch2_dev_usage_read_fast(struct bch_dev *ca, struct bch_dev_usage *usage) acc_u64s_percpu((u64 *) usage, (u64 __percpu *) ca->usage, dev_usage_u64s()); } -void bch2_fs_usage_to_text(struct printbuf *out, - struct bch_fs *c, - struct bch_fs_usage_online *fs_usage) -{ - unsigned i; - - prt_printf(out, "capacity:\t\t\t%llu\n", c->capacity); - - prt_printf(out, "hidden:\t\t\t\t%llu\n", - fs_usage->u.b.hidden); - prt_printf(out, "data:\t\t\t\t%llu\n", - fs_usage->u.b.data); - prt_printf(out, "cached:\t\t\t\t%llu\n", - fs_usage->u.b.cached); - prt_printf(out, "reserved:\t\t\t%llu\n", - fs_usage->u.b.reserved); - prt_printf(out, "nr_inodes:\t\t\t%llu\n", - fs_usage->u.b.nr_inodes); - prt_printf(out, "online reserved:\t\t%llu\n", - fs_usage->online_reserved); - - for (i = 0; - i < ARRAY_SIZE(fs_usage->u.persistent_reserved); - i++) { - prt_printf(out, "%u replicas:\n", i + 1); - prt_printf(out, "\treserved:\t\t%llu\n", - fs_usage->u.persistent_reserved[i]); - } - - for (i = 0; i < c->replicas.nr; i++) { - struct bch_replicas_entry_v1 *e = - cpu_replicas_entry(&c->replicas, i); - - prt_printf(out, "\t"); - bch2_replicas_entry_to_text(out, e); - prt_printf(out, ":\t%llu\n", fs_usage->u.replicas[i]); - } -} - static u64 reserve_factor(u64 r) { return r + (round_up(r, (1 << RESERVE_FACTOR)) >> RESERVE_FACTOR); diff --git a/fs/bcachefs/buckets.h b/fs/bcachefs/buckets.h index dfdf1b3ee817..ccf9813c65e7 100644 --- a/fs/bcachefs/buckets.h +++ b/fs/bcachefs/buckets.h @@ -294,9 +294,6 @@ static inline unsigned dev_usage_u64s(void) return sizeof(struct bch_dev_usage) / sizeof(u64); } -void bch2_fs_usage_to_text(struct printbuf *, - struct bch_fs *, struct bch_fs_usage_online *); - u64 bch2_fs_sectors_used(struct bch_fs *, struct bch_fs_usage_online *); struct bch_fs_usage_short From patchwork Sun Feb 25 02:38:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205972 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406416dyb; Sat, 24 Feb 2024 18:41:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUXScUi0m82PTPlH4E+GwL9aqF4DjQ944citTipq0yoM84nG0Pbrsuoh8JZzUgQW5vjIruDo8wEoTNdEPZYrmxC1k6GWA== X-Google-Smtp-Source: AGHT+IE8J1SVVS4YJ+zhEZZPk4PQASC8pNVXyU6g5waMJJqIHrx2rZXc1P4tMeKgQSSoBt4yxZt/ X-Received: by 2002:a05:6402:345a:b0:565:6e57:fa3d with SMTP id l26-20020a056402345a00b005656e57fa3dmr2394330edc.10.1708828893043; Sat, 24 Feb 2024 18:41:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828893; cv=pass; d=google.com; s=arc-20160816; b=guTOi6XixeDUorgfKnAwqA+w/oxJvz0+ZLMc1HupPibrhxU5m/idWwsZF+jeqDUk7b MXLbD6kFJ2xOpcJi8NwuQfBdc+2BBW0XmIPS5GvfPpbhTWfPNDssJFtBHqHmgPFZd+My 084nTxgZtFlNAp5DRW6WqFrxZ0ttc0VriH3DZe1waJzb/6K/q/yVRdbu54p2SknRIYc1 KTJJwif9wrK1m53Wpdm9l0mJwcNmmgAKhC8Qg493IfAB4gKvwV3SMKZYPE0sWryDxhx+ YNpQZYCWeHDwTi+d2zqXPXtZv3rzAXkdsgyTs68ILxeoS1i4/UDUJLnF18vyTDygRMd8 zk2g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=+XxTvZ+w+R//l1/8+X2sA3MHcm6KcV5Vz+RJqp7UJC8=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=Xzct+zp9/CFHdCOVlGfkVahy3jc06sDnR7uwZIF38DXAvSRqsAf7hPONv3DBKYG7Rq 8QRFjCnTqvsY0EgFHYTDygubDBAZbz4MU+IoN4V4WTOztCbk0GRLc5QxoF/6guOnp68i cmlJHswLacI8ZsLl77TG2Wk35Mq6hk5z9av23Iqpx5hcZg7QJvtQwrHgtGkcm68tij0d c21Dg+TVQLOd3mFMITY4WefQtnI1XLP6+m/jyH2/NpdD96XlJNXk7crxV5rjuQSWXVXA 2Teho78jX/fBaxQE6xmR5uIhUN1BNFhRARgdMUAEYGyI88iaPh26gBidam4xuMjdzryh XqJg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=iRFP2ifW; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79941-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79941-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a21-20020aa7cf15000000b00564f1974a0esi909456edy.137.2024.02.24.18.41.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:41:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79941-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=iRFP2ifW; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79941-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79941-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 19C391F21776 for ; Sun, 25 Feb 2024 02:41:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AE3C01804E; Sun, 25 Feb 2024 02:38:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="iRFP2ifW" Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6D3A134A9 for ; Sun, 25 Feb 2024 02:38:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828728; cv=none; b=Jvl+UMWEuCNHFbqv37zbRwxPXaQKG0jCHM4rnAoJlyobW0lC2+NmjhOgj7tSs7NExL9VWtTVnrhVmnuUTyxPZXmoSGBMW3fVP3WqQqE5y9bGqMmqlcsJilR05CElZbWKK3xhwy2+wvCQ9AoG53PUcmOROp6JPPRj8xF9o4d/Bdw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828728; c=relaxed/simple; bh=DkSMbHGXD7jvgfcyN0h8VxzJwADDueaJ+dPGY9kVlEo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gmCkgsI+uOOFQThSN3hjB20YfJppfX/Gw8zGDVQ89te7cvzM2j8hsv0Q/mMMM6FZFLFe6gEs45DvZtCNZg272btDwnfy6xot1axIZDOA3EnIDoHLt6ChMxSJGor0kgfOVUZy69zgs5usEAk+qSowbUAbsckstwhgKKpHtUHp2Vo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=iRFP2ifW; arc=none smtp.client-ip=95.215.58.186 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+XxTvZ+w+R//l1/8+X2sA3MHcm6KcV5Vz+RJqp7UJC8=; b=iRFP2ifW2GoApeZJ1zZOyXzDJTb4hPXB2Bn1jIWeMOr8zpgWXdwf76Iuwyr4tE5SoWJgWj TBRmLrUg3wHfNe1Vd4J6EHDyAKHn7yD/44qN6d2rr0Ro2rh64NN4lRTfppGIturZovj2V5 n0Fog7fhMrzvJqNAvbB89DYQBytzCcQ= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 12/21] bcachefs: Kill fs_usage_online Date: Sat, 24 Feb 2024 21:38:14 -0500 Message-ID: <20240225023826.2413565-13-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791836965076294072 X-GMAIL-MSGID: 1791836965076294072 More dead code deletion. Signed-off-by: Kent Overstreet --- fs/bcachefs/buckets.c | 10 ---------- fs/bcachefs/buckets.h | 12 ------------ fs/bcachefs/buckets_types.h | 5 ----- 3 files changed, 27 deletions(-) diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index c261fa3a0273..5e2b9aa93241 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -37,16 +37,6 @@ static u64 reserve_factor(u64 r) return r + (round_up(r, (1 << RESERVE_FACTOR)) >> RESERVE_FACTOR); } -u64 bch2_fs_sectors_used(struct bch_fs *c, struct bch_fs_usage_online *fs_usage) -{ - return min(fs_usage->u.b.hidden + - fs_usage->u.b.btree + - fs_usage->u.b.data + - reserve_factor(fs_usage->u.b.reserved + - fs_usage->online_reserved), - c->capacity); -} - static struct bch_fs_usage_short __bch2_fs_usage_read_short(struct bch_fs *c) { diff --git a/fs/bcachefs/buckets.h b/fs/bcachefs/buckets.h index ccf9813c65e7..f9d8d7b9fbd1 100644 --- a/fs/bcachefs/buckets.h +++ b/fs/bcachefs/buckets.h @@ -279,23 +279,11 @@ static inline unsigned fs_usage_u64s(struct bch_fs *c) return __fs_usage_u64s(READ_ONCE(c->replicas.nr)); } -static inline unsigned __fs_usage_online_u64s(unsigned nr_replicas) -{ - return sizeof(struct bch_fs_usage_online) / sizeof(u64) + nr_replicas; -} - -static inline unsigned fs_usage_online_u64s(struct bch_fs *c) -{ - return __fs_usage_online_u64s(READ_ONCE(c->replicas.nr)); -} - static inline unsigned dev_usage_u64s(void) { return sizeof(struct bch_dev_usage) / sizeof(u64); } -u64 bch2_fs_sectors_used(struct bch_fs *, struct bch_fs_usage_online *); - struct bch_fs_usage_short bch2_fs_usage_read_short(struct bch_fs *); diff --git a/fs/bcachefs/buckets_types.h b/fs/bcachefs/buckets_types.h index baa7e0924390..570acdf455bb 100644 --- a/fs/bcachefs/buckets_types.h +++ b/fs/bcachefs/buckets_types.h @@ -61,11 +61,6 @@ struct bch_fs_usage { u64 replicas[]; }; -struct bch_fs_usage_online { - u64 online_reserved; - struct bch_fs_usage u; -}; - struct bch_fs_usage_short { u64 capacity; u64 used; From patchwork Sun Feb 25 02:38:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205974 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406473dyb; Sat, 24 Feb 2024 18:41:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVd1b965rRFMTUQvz3V/iFLYD8TLobPdrUDlSqsnjfSHYHGy0SDptgv+rHTGgiK+/6oW2ljLJSf03fK6ZjvuPptAjVBjA== X-Google-Smtp-Source: AGHT+IG+sBjs+RShpS96Zrj57MQHL8N63CC5aP0pX8HXxxrIEv4xwoabyXAR8C6jZYHaTFagkQaF X-Received: by 2002:a17:906:528d:b0:a3e:e9e1:1c08 with SMTP id c13-20020a170906528d00b00a3ee9e11c08mr2377352ejm.66.1708828908197; Sat, 24 Feb 2024 18:41:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828908; cv=pass; d=google.com; s=arc-20160816; b=ukp9L/IwZHs18HkaLLKuNWpHaDpBUffrYBuyHLlMF8l4Ddx0tnEY9B7KUxsGKNDpuz 2gDIXAMyABiY8fqFdcAzMk4DBodNvKzB0Q2PGmBEkm0Bo9SP939zBgmlSzZ7Cvu2R+Ft wcZo0p1NZeH/nZzjAt6gpCn50GmNtwHT82LFOgClChBR+tFpgkiczejr8PLCMfiKZBxb DlCc2OmNFatW/sW5F36/hBUksL1zcpc+aQWiyAry06xKbg10ZFVXEz8jOWlOxYJ05yny WRAsJB4z+c7/wFCYK7oVVwhF8/MYBjYyAPwXxfhaAzPLGgywInVG8aCHSdjLvS3g7zIH 6R5g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=3edXSLQswq3o2Ph2NSZVb78JLMRJ7gBJFLnjH1EUAXg=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=NFYCfUAf6ni5XeFnU2V+BTQIdHZSLuEOyfkdPF+Noku8h+fKSGhBu+AEKScKQh4C/b L5BefPEZFsSA5v5FcAok2WiaCDCjHzVZlUsuKebCutBRRo3x0vR2iWItUgSHm/Pdw4T3 ZYcIIKmP2LsvfVJyR/i5qHAvM4/vKzvvUDiXhr9R3YjY9cB5YVdIeCM2W8Y8Hmn0efhI ypMK3rxMduG5LoYsHFY4rbplcW7TOXp9O3CQoblSRWHe6NCbmxTMC3nbst3nQEfFphYy EWGEe5amyZe1PIOkw/i+bsyeqE7MRz7OtGIrRYX9YbRirLapdXZlM6giTyBYjTduobO5 EpOg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=mQAl7rg9; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79942-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79942-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ga24-20020a170906b85800b00a3f857c876fsi963572ejb.327.2024.02.24.18.41.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:41:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79942-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=mQAl7rg9; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79942-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79942-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A36DA1F21881 for ; Sun, 25 Feb 2024 02:41:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2669F199B8; Sun, 25 Feb 2024 02:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="mQAl7rg9" Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4D0D14290; Sun, 25 Feb 2024 02:38:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828729; cv=none; b=cP7nhWJ0qmYicwVOLYF/Hx8hOb01kDLg0BjHL5v7zx9On3xdZILsRkTRHQ2jDmESOKv+o/ExcP1glDOpZxb9uV7qr5UVff8R2NbObz1lkcwi42zAoTJ0Ke6e84yGb6/FWHxhbLY8i40ZSIRzBD+qJGh7x5Dji99hhU+AOnlbNvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828729; c=relaxed/simple; bh=kMbO4D6+stofxnjriibFLbcNaDrcicjpLGuvPqCK11g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dNYFV971j0KB0OF8iDGjH/lVnoP/0+6B2YTV/VOQkeIBpmWubLLmZwKtF6o6i6rEKJfEdmPzpPOkLAHjj3rwovb7tebRc9B9rE8gNONj4gm9tpYeH6jAAaeFW14Srzq7sGdiehcon2ojrQR/54oXeCB+42OuGIohQHVSho6fz5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=mQAl7rg9; arc=none smtp.client-ip=95.215.58.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828726; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3edXSLQswq3o2Ph2NSZVb78JLMRJ7gBJFLnjH1EUAXg=; b=mQAl7rg9h1+1IHylCVADyGyzkZr/GSbWxQva1XfNkPAt2v8iF8j36ZGPKMZcH3FpO2ZJlV mqAKIe3WpFCaH+SHL9OLToeuVfDRsT+zrbxzLd2tHXiJkI/pe5HnsEWbzu6H0vjzjfiHiD mwcKfh5u+5OFSgvOG5fAeL9IaTyy7HM= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 13/21] bcachefs: Kill replicas_journal_res Date: Sat, 24 Feb 2024 21:38:15 -0500 Message-ID: <20240225023826.2413565-14-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791836981242385142 X-GMAIL-MSGID: 1791836981242385142 More dead code deletion Signed-off-by: Kent Overstreet --- fs/bcachefs/bcachefs.h | 2 -- fs/bcachefs/replicas.c | 34 ---------------------------------- fs/bcachefs/super.c | 21 --------------------- 3 files changed, 57 deletions(-) diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 2e7c4d10c951..22dc455cb436 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -768,9 +768,7 @@ struct bch_fs { struct mutex replicas_gc_lock; struct journal_entry_res btree_root_journal_res; - struct journal_entry_res replicas_journal_res; struct journal_entry_res clock_journal_res; - struct journal_entry_res dev_usage_journal_res; struct bch_disk_groups_cpu __rcu *disk_groups; diff --git a/fs/bcachefs/replicas.c b/fs/bcachefs/replicas.c index 6dca705eaf1f..427dc6711427 100644 --- a/fs/bcachefs/replicas.c +++ b/fs/bcachefs/replicas.c @@ -342,32 +342,6 @@ static int replicas_table_update(struct bch_fs *c, goto out; } -static unsigned reserve_journal_replicas(struct bch_fs *c, - struct bch_replicas_cpu *r) -{ - struct bch_replicas_entry_v1 *e; - unsigned journal_res_u64s = 0; - - /* nr_inodes: */ - journal_res_u64s += - DIV_ROUND_UP(sizeof(struct jset_entry_usage), sizeof(u64)); - - /* key_version: */ - journal_res_u64s += - DIV_ROUND_UP(sizeof(struct jset_entry_usage), sizeof(u64)); - - /* persistent_reserved: */ - journal_res_u64s += - DIV_ROUND_UP(sizeof(struct jset_entry_usage), sizeof(u64)) * - BCH_REPLICAS_MAX; - - for_each_cpu_replicas_entry(r, e) - journal_res_u64s += - DIV_ROUND_UP(sizeof(struct jset_entry_data_usage) + - e->nr_devs, sizeof(u64)); - return journal_res_u64s; -} - noinline static int bch2_mark_replicas_slowpath(struct bch_fs *c, struct bch_replicas_entry_v1 *new_entry) @@ -401,10 +375,6 @@ static int bch2_mark_replicas_slowpath(struct bch_fs *c, ret = bch2_cpu_replicas_to_sb_replicas(c, &new_r); if (ret) goto err; - - bch2_journal_entry_res_resize(&c->journal, - &c->replicas_journal_res, - reserve_journal_replicas(c, &new_r)); } if (!new_r.entries && @@ -974,9 +944,5 @@ void bch2_fs_replicas_exit(struct bch_fs *c) int bch2_fs_replicas_init(struct bch_fs *c) { - bch2_journal_entry_res_resize(&c->journal, - &c->replicas_journal_res, - reserve_journal_replicas(c, &c->replicas)); - return replicas_table_update(c, &c->replicas); } diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index 30b41c8de309..89c481831608 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -221,22 +221,6 @@ struct bch_fs *bch2_uuid_to_fs(__uuid_t uuid) return c; } -static void bch2_dev_usage_journal_reserve(struct bch_fs *c) -{ - unsigned nr = 0, u64s = - ((sizeof(struct jset_entry_dev_usage) + - sizeof(struct jset_entry_dev_usage_type) * BCH_DATA_NR)) / - sizeof(u64); - - rcu_read_lock(); - for_each_member_device_rcu(c, ca, NULL) - nr++; - rcu_read_unlock(); - - bch2_journal_entry_res_resize(&c->journal, - &c->dev_usage_journal_res, u64s * nr); -} - /* Filesystem RO/RW: */ /* @@ -940,7 +924,6 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts) bch2_journal_entry_res_resize(&c->journal, &c->btree_root_journal_res, BTREE_ID_NR * (JSET_KEYS_U64s + BKEY_BTREE_PTR_U64s_MAX)); - bch2_dev_usage_journal_reserve(c); bch2_journal_entry_res_resize(&c->journal, &c->clock_journal_res, (sizeof(struct jset_entry_clock) / sizeof(u64)) * 2); @@ -1680,8 +1663,6 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags) mutex_unlock(&c->sb_lock); up_write(&c->state_lock); - - bch2_dev_usage_journal_reserve(c); return 0; err: if (ca->mi.state == BCH_MEMBER_STATE_rw && @@ -1791,8 +1772,6 @@ int bch2_dev_add(struct bch_fs *c, const char *path) bch2_write_super(c); mutex_unlock(&c->sb_lock); - bch2_dev_usage_journal_reserve(c); - ret = bch2_dev_usage_init(ca); if (ret) goto err_late; From patchwork Sun Feb 25 02:38:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205975 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406553dyb; Sat, 24 Feb 2024 18:42:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWNadlAz2cKS8fJqqnoHJhWNSZnBL96Rt3fzqH1b58Zro4Il55j7Ghhp3Mf1LxWhEPUBtI/M0FfrytcqF5u6rRLuZX5ig== X-Google-Smtp-Source: AGHT+IHpzk7uQmhoIxs3iSLNRnE0bI5jyyj/jVKDMlZvgiF+PXsAeEHCsV69mA/utEodGEnIyS96 X-Received: by 2002:a17:902:e80d:b0:1dc:75ea:8561 with SMTP id u13-20020a170902e80d00b001dc75ea8561mr4779089plg.17.1708828935549; Sat, 24 Feb 2024 18:42:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828935; cv=pass; d=google.com; s=arc-20160816; b=MpurLSYspLJv3qTmAy42X8DV8yOwD9nH5D/vgfh1Yzcm4ZNZHI6wqiLua5VOZhwxA+ GYcUbeW8DzrXTGNx9nsk1nymLADDlPIwltlXvDURGO5lK81gtgyQO9Th/OB6N3xlF7Cr dQ+jGAvVWR8vn6r+W//eNUiz4gfSbKHiGMT3kQGPisV//bXWOgqzOjRb/dpd74DEVXtA kMMNFLdLrZf5dch0fNmgLKq/akTA+b3Ju/UAl5ooTYS3l/2ToLPn0S22KamUoDuy5Oz/ ySpsLzE0JyA6bTWMvZGO3XzHA7NhXdXy+U6gJURjMPhj6zc6vsw3H7bXrXCb7X2u8f99 TEyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=y3FpSQO+5DeuDSgLy4pK3aklIcBNM9sDCfco3eXxsBU=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=f3h3dF8jP09U3upgJI2ihOvY7gzapqOawWrHdcGqDps25RGw8bXJcqR0FcbI8PmAiW 3Ay1f0sAp9FRe069bDOXI2QpJULm/RGTVTqXATw+eDNNvFL+GJ1DKhM/FgrbSfmu3zZF +1SslmLM1K5VDhprLMNYYsl4c4boTd3Tt9auAoDKpLWHHiY8xZlnaCeNIiZat+vcvqTR JfxsSA7R8qynjdwj/RFcK/qxEy2xozrFE0tg8O06ajeYSUmksdmCRtnK5UaffKOM0m0x eThBbVYY8eIQGpF4h1pD5avm/UQQohlaIGWjILLjrVF49gPvBSFbodQDavj3p3OQQKQL N5fw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xf2Xkblz; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79943-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79943-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b12-20020a170902650c00b001dc3c4d18f1si1521271plk.288.2024.02.24.18.42.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:42:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79943-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xf2Xkblz; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79943-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79943-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E4900282271 for ; Sun, 25 Feb 2024 02:42:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 799B3FBEB; Sun, 25 Feb 2024 02:38:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="xf2Xkblz" Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3814017756 for ; Sun, 25 Feb 2024 02:38:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828732; cv=none; b=goeLBd3I6gfBv+ar/1ETvfT37Ekl3UKqdSKWeK9rzixhc8ggmnzhfmuxjrTVW3shYWvbDVuMxkdGTXGRyEs15K5bNdTB+IkLgaji+C3SQ8FvKN8j+TLXKcyoU2liwdYV476f/VB/o7ZJznCDw7G1NIECtg2fSDzJklyFR9gJTl0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828732; c=relaxed/simple; bh=8Dzr04OBJMHQlzrTPGyog2ZCPLnWs2SakI+yYoIZVac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mJyIUkcdrgnTcMGprniKIt0HNThF1cywJ38RhTZoeoDzHOwPtBlhNhRg6Xch7RASXNAMR7sAMyO+ICluQZO0Z8i3yPmbPU+sZorCsmdyfpOdWROHcTSd393qAkNxOqcHe28YmBcn+zSacwZeveCQOyzNbY/A2hBmVD8n8jzbPZs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=xf2Xkblz; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y3FpSQO+5DeuDSgLy4pK3aklIcBNM9sDCfco3eXxsBU=; b=xf2Xkblz2aGS8hwBJXBPOzrrYlK07lSAMxX8n8o5PQQs8pqo7kZxNeCbl8l4YxHUTwjU4D CKMJpJCYI2oY55RXahByj51h/1LiFp8t5V8mhhNFeyU/a55ugr0omICPqdcmsDQRUoc1sW puYGne+ebIvnIdlMhYYEkyM+2zQMIw8= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 15/21] bcachefs: Convert bch2_replicas_gc2() to new accounting Date: Sat, 24 Feb 2024 21:38:17 -0500 Message-ID: <20240225023826.2413565-16-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791837009770560702 X-GMAIL-MSGID: 1791837009770560702 bch2_replicas_gc2() is used for garbage collection superblock replicas entries that are empty - this converts it to the new accounting scheme. Signed-off-by: Kent Overstreet --- fs/bcachefs/replicas.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/fs/bcachefs/replicas.c b/fs/bcachefs/replicas.c index cba5ba44cfd8..18137abb1857 100644 --- a/fs/bcachefs/replicas.c +++ b/fs/bcachefs/replicas.c @@ -2,6 +2,7 @@ #include "bcachefs.h" #include "buckets.h" +#include "disk_accounting.h" #include "journal.h" #include "replicas.h" #include "super-io.h" @@ -425,8 +426,6 @@ int bch2_replicas_gc_start(struct bch_fs *c, unsigned typemask) */ int bch2_replicas_gc2(struct bch_fs *c) { - return 0; -#if 0 struct bch_replicas_cpu new = { 0 }; unsigned i, nr; int ret = 0; @@ -456,20 +455,26 @@ int bch2_replicas_gc2(struct bch_fs *c) struct bch_replicas_entry_v1 *e = cpu_replicas_entry(&c->replicas, i); - if (e->data_type == BCH_DATA_journal || - c->usage_base->replicas[i] || - percpu_u64_get(&c->usage[0]->replicas[i]) || - percpu_u64_get(&c->usage[1]->replicas[i]) || - percpu_u64_get(&c->usage[2]->replicas[i]) || - percpu_u64_get(&c->usage[3]->replicas[i])) + struct disk_accounting_key k = { + .type = BCH_DISK_ACCOUNTING_replicas, + }; + + memcpy(&k.replicas, e, replicas_entry_bytes(e)); + + u64 v = 0; + bch2_accounting_mem_read(c, disk_accounting_key_to_bpos(&k), &v, 1); + + if (e->data_type == BCH_DATA_journal || v) memcpy(cpu_replicas_entry(&new, new.nr++), e, new.entry_size); } bch2_cpu_replicas_sort(&new); - ret = bch2_cpu_replicas_to_sb_replicas(c, &new) ?: - replicas_table_update(c, &new); + ret = bch2_cpu_replicas_to_sb_replicas(c, &new); + + if (!ret) + swap(c->replicas, new); kfree(new.entries); @@ -481,7 +486,6 @@ int bch2_replicas_gc2(struct bch_fs *c) mutex_unlock(&c->sb_lock); return ret; -#endif } /* Replicas tracking - superblock: */ From patchwork Sun Feb 25 02:38:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205976 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406590dyb; Sat, 24 Feb 2024 18:42:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWQmHWilH9efexTpEUDLt/Xx3SAtGQfR9NzfomoLqSPUsJsgWlyBHj2TPW/t0a7dpy0EhRnJMyBlmtbeMv17RuS4BtOXg== X-Google-Smtp-Source: AGHT+IEckS60K8eSq/AOiOOKMpI706OvI0A0H5+b3qCVXYVb+bt3cy+E6CeUxYqxSTy11hSzEz5R X-Received: by 2002:a05:620a:2720:b0:787:cbaa:faad with SMTP id b32-20020a05620a272000b00787cbaafaadmr1316501qkp.8.1708828942708; Sat, 24 Feb 2024 18:42:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828942; cv=pass; d=google.com; s=arc-20160816; b=Uhm/VN2yKVnFSegkVE4L0tRRs0ajOR/Mgry4kZrJi+RONvqBIKriJOhB9dOaNnBr4I dnU7Nj/pIs7dklt6nIGKkW0bpDfFHD82M5ERYjpovuNdCId3tycb6tt+KGMEkk3FqUS3 m7eeNB0xhU0NtQcWV5ucnzB5yf6Hft3KyKxOtTRaDADHMhbcPcunNHNrVLqtAgHZap9X KL99m+GuTD2IiMJ9xQcqQSsPtL7N2XNeLzS8DgxNhLt4wBe+3j/g63ixvN1qOTBYpAyU UlPrwSJKur2XFT4TP4VHJvhF6g4nAfW4EY/2ZdjsLIKNNzQFlwMmo/yX+e9tnLJ5JqwJ kmOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Qtt8N3DTXT8YcoliwHPFpPxKQXIz9TTQtDYUciFTLnM=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=clhYppr1tTCs5MBw3Csm342ZqEpNQbDsXbtST3jKJMLwZ+9YXF8kPThQneQuuxOUbC WytEYf6ArwQz8yno1CrG3ASAzawZZUGNFHvf+MCVuamiU0m4m4oSpRsl2sunSJJYuXGv 3vBKpEDKllp39OjhtAY6M769usu6sJRS7nhU9dstzG4az6+bcr12y1w04bRqubt+fJQV tJ/y0zYNj3Wl8FFfWlEIV0hFHTyG4TJvYqa8QDseiJSHKvzE9rFZyiA9tBg/MDl7bzEU bEsNwqLfHMYmA0uONKOwy7Wv3QtqlmfE6B3tdhw2kpcp4Kv1/idIV1tOZMqaD753qMSp 1Y9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=t5Uq6mW9; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79944-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79944-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j26-20020a37ef1a000000b00785d4e12821si2249006qkk.41.2024.02.24.18.42.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:42:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79944-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=t5Uq6mW9; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79944-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79944-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 723081C20CD3 for ; Sun, 25 Feb 2024 02:42:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0026A168DC; Sun, 25 Feb 2024 02:38:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="t5Uq6mW9" Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF0E317BBB for ; Sun, 25 Feb 2024 02:38:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828732; cv=none; b=aaa47r7CRweTWVCw1cg+Up3mMUj+FvtoBi0dK+lljd0wX3Bsp5YVmGOP2nfBskhk0WdKdCIsRXDmIfSBZfbZLbrDlfhQ3GKn0PudWWUE4xqkJ8Ax75cKIe7gDb0AscvBZig8wUOQBFGHW3IxOyvo3EIC/Ssu4KRD4qnsHYZqEFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828732; c=relaxed/simple; bh=693nN94qUSbbDkqHrUPV8kMgo4OMZv7SWEQcI8AOyfo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HPDPzzRrjxFQG2bayNX7etKnCs0ChDJsEaGuBnXa1I6GOPjZxspUE4QuXiIbxlifzcYgpQI+6OmF0x71YvEiOBPSkYpT1S6G1aRprIFz/xjxVVbsVs+Dw0JiGaok093q8yjevgHwzNy/KYISfOU+B8nYRtQfySClTisrpfjSaic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=t5Uq6mW9; arc=none smtp.client-ip=95.215.58.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qtt8N3DTXT8YcoliwHPFpPxKQXIz9TTQtDYUciFTLnM=; b=t5Uq6mW9GG3Iozxg1JY5qA7lforHDcbj+wg4MIkQsFH4ck90PVZ93xMlSgL4eMlDl2woyi EvPtgsLVWvtMuqILOQqRjhSeb3Dmsvw1RAoitJjHJDyZJ4aMCg5VZlKRoiFlMU1RXMTgZb bE7B3hd9Ir4lBJC32mIPIaOweIf8fqk= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 16/21] bcachefs: bch2_verify_accounting_clean() Date: Sat, 24 Feb 2024 21:38:18 -0500 Message-ID: <20240225023826.2413565-17-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791837017509862779 X-GMAIL-MSGID: 1791837017509862779 Verify that the in-memory accounting verifies the on-disk accounting after a clean shutdown. Signed-off-by: Kent Overstreet --- fs/bcachefs/disk_accounting.c | 27 +++++++++++++++++++++++++++ fs/bcachefs/disk_accounting.h | 4 +++- fs/bcachefs/super.c | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c index 2884615adc1e..8d7b6ab66e71 100644 --- a/fs/bcachefs/disk_accounting.c +++ b/fs/bcachefs/disk_accounting.c @@ -513,6 +513,33 @@ int bch2_dev_usage_init(struct bch_dev *ca, bool gc) return ret; } +void bch2_verify_accounting_clean(struct bch_fs *c) +{ + bch2_trans_run(c, + for_each_btree_key(trans, iter, + BTREE_ID_accounting, POS_MIN, + BTREE_ITER_ALL_SNAPSHOTS, k, ({ + u64 v[BCH_ACCOUNTING_MAX_COUNTERS]; + struct bkey_s_c_accounting a = bkey_s_c_to_accounting(k); + unsigned nr = bch2_accounting_counters(k.k); + + bch2_accounting_mem_read(c, k.k->p, v, nr); + + if (memcmp(a.v->d, v, nr * sizeof(u64))) { + struct printbuf buf = PRINTBUF; + + bch2_bkey_val_to_text(&buf, c, k); + prt_str(&buf, " in mem"); + for (unsigned j = 0; j < nr; j++) + prt_printf(&buf, " %llu", v[j]); + + WARN(1, "accounting mismatch: %s", buf.buf); + printbuf_exit(&buf); + } + 0; + }))); +} + void bch2_accounting_free(struct bch_accounting_mem *acc) { darray_exit(&acc->k); diff --git a/fs/bcachefs/disk_accounting.h b/fs/bcachefs/disk_accounting.h index 70ac67f4a3cb..a0cf7a0b84a7 100644 --- a/fs/bcachefs/disk_accounting.h +++ b/fs/bcachefs/disk_accounting.h @@ -164,7 +164,7 @@ static inline void bch2_accounting_mem_read_counters(struct bch_fs *c, unsigned { memset(v, 0, sizeof(*v) * nr); - struct bch_accounting_mem *acc = &c->accounting[0]; + struct bch_accounting_mem *acc = &c->accounting[gc]; if (unlikely(idx >= acc->k.nr)) return; @@ -194,6 +194,8 @@ int bch2_accounting_read(struct bch_fs *); int bch2_dev_usage_remove(struct bch_fs *, unsigned); int bch2_dev_usage_init(struct bch_dev *, bool); +void bch2_verify_accounting_clean(struct bch_fs *c); + void bch2_accounting_free(struct bch_accounting_mem *); void bch2_fs_accounting_exit(struct bch_fs *); diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index 6617c8912e51..201d7767e478 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -355,6 +355,7 @@ void bch2_fs_read_only(struct bch_fs *c) BUG_ON(atomic_long_read(&c->btree_key_cache.nr_dirty)); BUG_ON(c->btree_write_buffer.inc.keys.nr); BUG_ON(c->btree_write_buffer.flushing.keys.nr); + bch2_verify_accounting_clean(c); bch_verbose(c, "marking filesystem clean"); bch2_fs_mark_clean(c); From patchwork Sun Feb 25 02:38:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205978 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406709dyb; Sat, 24 Feb 2024 18:42:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWkv6mj3VPm1kuNj5URf5G/YKkGHgvIxh9qDHKv+sttdmq5Mu/6UbJAjncXNEtQxIXE952dc915bKvXM8h+/IAehnWuuQ== X-Google-Smtp-Source: AGHT+IE/2BKdEczi7PkZsGccA1QG8Z27UtmGP24/qe8MgafuevqVPbEywgrrAZdsMLw6tpbCCXpZ X-Received: by 2002:a05:6808:1488:b0:3c1:6d6c:2e72 with SMTP id e8-20020a056808148800b003c16d6c2e72mr5113876oiw.43.1708828978514; Sat, 24 Feb 2024 18:42:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828978; cv=pass; d=google.com; s=arc-20160816; b=RM+l+FWHHyA9VZNOToy8Cdvpos4QDK+WoVyQC0KRzL7Yxup9xNHk+mLF6cJLq90r1c xE7Hi2HQDJ7HRRKBgXWOJ5ZQTdNh7wlO3G//m9eC2AT/651+m8YDmnh2jjt/scS4LLk5 tJLriqtLlI9yyZxIiI8Xf+t362HBRNoxlJoo8GJIGxshRKm+VsZRy9ZcgGtT9UjA3k0w DeJ2sudFEUxSbKHKm8OtKb3QJlGO21nR4E1/tQISRTO0B+Wv62nFhNVVJ4pch8MVYhhN gwXJaXggkzewsIPGCtC3icbdvZmwJkuFhFDcFX4ABrVd+XACS02kaaSw5zi9tmzdl8aY Iggg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DZ05Q5mbXYgDagN6r2B0XGx91E8emllsAKskdvguQ3M=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=MNXrjYI9l1BFatVwI8G8YVbt9oKt0blQ7dPlaNISFT5/ZeMEBbwCYRZts7HrNM4tCj 0FnOi3dCfu0jBA7/spIPT54EQsDlGGIDXNk/cyEAQSIq3NX08p4ub90yUNO1wz5PA8Kl hWxByNp2FP2ugATrA2hmCbh8P59vgU7+d1YCYPS+sPHTxqt8G8C831TxzUNfiWWfmz40 bmPdsbvOXEC7TJl4la+VYylsbcYSxQHOn9fuINisXdEKbMTICr/BJrO8WM/KwZt+ptpo 1ctJulKnttKnZG205YT1qT0hXKAoEPrY/P/sIk6PSoMvQjRW92guonoaMuBHKdONJWzp DEIQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=P1ACEzCo; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79946-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79946-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a11-20020a170902eccb00b001db29e3ba29si1599759plh.77.2024.02.24.18.42.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:42:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79946-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=P1ACEzCo; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79946-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79946-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 25746281896 for ; Sun, 25 Feb 2024 02:42:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 447741BC30; Sun, 25 Feb 2024 02:38:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="P1ACEzCo" Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6C3E1805A for ; Sun, 25 Feb 2024 02:38:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828734; cv=none; b=lPuBQpE6jLSUlAlRu1ujxBHZAPCLrF6pg+o7ZH+NQDfROtniHKy65/XVRAjU7kcolynZk+fl8ThgdQ4ty34gaCvJjCCvRdVcjqQOvQS4yXF0/s87ompN4JuFkam1f38axuss/0d9TpT5l3H51/nn6kntqBCySYbFrGEgwcM2VMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828734; c=relaxed/simple; bh=9aDC/MHLqlfI7ZdF71omQwXEoDMiNVdOwQThfvn1sVw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uJ5Eq7O7GcmmxHyz9HTMRzbB/MNwSJK6aUV6RiROo1lkSaaW0Ia9tqNk1o2YTUd8VBLffQWSKzlsGgLC0yir3c7fZKbb598TMMXimLpaHsy/3hYItvMotOrLCb/gW/F1+D5lUZig4A/W7xIE+3NygmxUBKwumFY13PKjJiUHKxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=P1ACEzCo; arc=none smtp.client-ip=95.215.58.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DZ05Q5mbXYgDagN6r2B0XGx91E8emllsAKskdvguQ3M=; b=P1ACEzCotmgZtAdngBcAlZDwiID3fTZ23wEWyAp6dqymLfSg0PrfkPjzlmAqAK6csR0B4E mJVmcwwKGucTeMgN+bOT4aqQmHfnSfYgVYLffQCwjGTHCGwi3erHybuFlhHDg6UBMT/VLD nKLa/tn48WNpIGD2S25xiBzDYmsdnLk= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 17/21] bcachefs: Eytzinger accumulation for accounting keys Date: Sat, 24 Feb 2024 21:38:19 -0500 Message-ID: <20240225023826.2413565-18-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791837055007135419 X-GMAIL-MSGID: 1791837055007135419 The btree write buffer takes as input keys from the journal, sorts them, deduplicates them, and flushes them back to the btree in sorted order. The disk space accounting rewrite is moving accounting to normal btree keys, with update (in this case deltas) accumulated in the write buffer and then flushed to the btree; but this is going to increase the number of keys handled by the write buffer by perhaps as much as a factor of 3x-5x. The overhead from copying around and sorting this many keys would cause a significant performance regression, but: there is huge locality in updates to accounting keys that we can take advantage of. Instead of appending accounting keys to the list of keys to be sorted, this patch adds an eytzinger search tree of recently seen accounting keys. We look up the accounting key in the eytzinger search tree and apply the delta directly, adding it if it doesn't exist, and periodically prune the eytzinger tree of unused entries. Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_write_buffer.c | 54 +++++++++++++++++++++++++- fs/bcachefs/btree_write_buffer.h | 50 ++++++++++++++++++++++-- fs/bcachefs/btree_write_buffer_types.h | 2 + fs/bcachefs/journal_io.c | 13 +++++-- 4 files changed, 110 insertions(+), 9 deletions(-) diff --git a/fs/bcachefs/btree_write_buffer.c b/fs/bcachefs/btree_write_buffer.c index 002a0762fc85..13f5f63e22b7 100644 --- a/fs/bcachefs/btree_write_buffer.c +++ b/fs/bcachefs/btree_write_buffer.c @@ -531,6 +531,29 @@ static void bch2_btree_write_buffer_flush_work(struct work_struct *work) bch2_write_ref_put(c, BCH_WRITE_REF_btree_write_buffer); } +static void wb_accounting_sort(struct btree_write_buffer *wb) +{ + eytzinger0_sort(wb->accounting.data, wb->accounting.nr, + sizeof(wb->accounting.data[0]), + wb_key_cmp, NULL); +} + +int bch2_accounting_key_to_wb_slowpath(struct bch_fs *c, enum btree_id btree, + struct bkey_i_accounting *k) +{ + struct btree_write_buffer *wb = &c->btree_write_buffer; + struct btree_write_buffered_key new = { .btree = btree }; + + bkey_copy(&new.k, &k->k_i); + + int ret = darray_push(&wb->accounting, new); + if (ret) + return ret; + + wb_accounting_sort(wb); + return 0; +} + int bch2_journal_key_to_wb_slowpath(struct bch_fs *c, struct journal_keys_to_wb *dst, enum btree_id btree, struct bkey_i *k) @@ -600,11 +623,35 @@ void bch2_journal_keys_to_write_buffer_start(struct bch_fs *c, struct journal_ke bch2_journal_pin_add(&c->journal, seq, &dst->wb->pin, bch2_btree_write_buffer_journal_flush); + + darray_for_each(wb->accounting, i) + memset(&i->k.v, 0, bkey_val_bytes(&i->k.k)); } -void bch2_journal_keys_to_write_buffer_end(struct bch_fs *c, struct journal_keys_to_wb *dst) +int bch2_journal_keys_to_write_buffer_end(struct bch_fs *c, struct journal_keys_to_wb *dst) { struct btree_write_buffer *wb = &c->btree_write_buffer; + unsigned live_accounting_keys = 0; + int ret = 0; + + darray_for_each(wb->accounting, i) + if (!bch2_accounting_key_is_zero(bkey_i_to_s_c_accounting(&i->k))) { + i->journal_seq = dst->seq; + live_accounting_keys++; + ret = __bch2_journal_key_to_wb(c, dst, i->btree, &i->k); + if (ret) + break; + } + + if (live_accounting_keys * 2 < wb->accounting.nr) { + struct btree_write_buffered_key *dst = wb->accounting.data; + + darray_for_each(wb->accounting, src) + if (!bch2_accounting_key_is_zero(bkey_i_to_s_c_accounting(&src->k))) + *dst++ = *src; + wb->accounting.nr = dst - wb->accounting.data; + wb_accounting_sort(wb); + } if (!dst->wb->keys.nr) bch2_journal_pin_drop(&c->journal, &dst->wb->pin); @@ -617,6 +664,8 @@ void bch2_journal_keys_to_write_buffer_end(struct bch_fs *c, struct journal_keys if (dst->wb == &wb->flushing) mutex_unlock(&wb->flushing.lock); mutex_unlock(&wb->inc.lock); + + return ret; } static int bch2_journal_keys_to_write_buffer(struct bch_fs *c, struct journal_buf *buf) @@ -640,7 +689,7 @@ static int bch2_journal_keys_to_write_buffer(struct bch_fs *c, struct journal_bu buf->need_flush_to_write_buffer = false; spin_unlock(&c->journal.lock); out: - bch2_journal_keys_to_write_buffer_end(c, &dst); + ret = bch2_journal_keys_to_write_buffer_end(c, &dst) ?: ret; return ret; } @@ -672,6 +721,7 @@ void bch2_fs_btree_write_buffer_exit(struct bch_fs *c) BUG_ON((wb->inc.keys.nr || wb->flushing.keys.nr) && !bch2_journal_error(&c->journal)); + darray_exit(&wb->accounting); darray_exit(&wb->sorted); darray_exit(&wb->flushing.keys); darray_exit(&wb->inc.keys); diff --git a/fs/bcachefs/btree_write_buffer.h b/fs/bcachefs/btree_write_buffer.h index eebcd2b15249..828e2deaaa3d 100644 --- a/fs/bcachefs/btree_write_buffer.h +++ b/fs/bcachefs/btree_write_buffer.h @@ -3,6 +3,8 @@ #define _BCACHEFS_BTREE_WRITE_BUFFER_H #include "bkey.h" +#include "disk_accounting.h" +#include static inline bool bch2_btree_write_buffer_should_flush(struct bch_fs *c) { @@ -29,16 +31,45 @@ struct journal_keys_to_wb { u64 seq; }; +static inline int wb_key_cmp(const void *_l, const void *_r) +{ + const struct btree_write_buffered_key *l = _l; + const struct btree_write_buffered_key *r = _r; + + return cmp_int(l->btree, r->btree) ?: bpos_cmp(l->k.k.p, r->k.k.p); +} + +int bch2_accounting_key_to_wb_slowpath(struct bch_fs *, + enum btree_id, struct bkey_i_accounting *); + +static inline int bch2_accounting_key_to_wb(struct bch_fs *c, + enum btree_id btree, struct bkey_i_accounting *k) +{ + struct btree_write_buffer *wb = &c->btree_write_buffer; + struct btree_write_buffered_key search; + search.btree = btree; + search.k.k.p = k->k.p; + + unsigned idx = eytzinger0_find(wb->accounting.data, wb->accounting.nr, + sizeof(wb->accounting.data[0]), + wb_key_cmp, &search); + + if (idx >= wb->accounting.nr) + return bch2_accounting_key_to_wb_slowpath(c, btree, k); + + struct bkey_i_accounting *dst = bkey_i_to_accounting(&wb->accounting.data[idx].k); + bch2_accounting_accumulate(dst, accounting_i_to_s_c(k)); + return 0; +} + int bch2_journal_key_to_wb_slowpath(struct bch_fs *, struct journal_keys_to_wb *, enum btree_id, struct bkey_i *); -static inline int bch2_journal_key_to_wb(struct bch_fs *c, +static inline int __bch2_journal_key_to_wb(struct bch_fs *c, struct journal_keys_to_wb *dst, enum btree_id btree, struct bkey_i *k) { - EBUG_ON(!dst->seq); - if (unlikely(!dst->room)) return bch2_journal_key_to_wb_slowpath(c, dst, btree, k); @@ -51,8 +82,19 @@ static inline int bch2_journal_key_to_wb(struct bch_fs *c, return 0; } +static inline int bch2_journal_key_to_wb(struct bch_fs *c, + struct journal_keys_to_wb *dst, + enum btree_id btree, struct bkey_i *k) +{ + EBUG_ON(!dst->seq); + + return k->k.type == KEY_TYPE_accounting + ? bch2_accounting_key_to_wb(c, btree, bkey_i_to_accounting(k)) + : __bch2_journal_key_to_wb(c, dst, btree, k); +} + void bch2_journal_keys_to_write_buffer_start(struct bch_fs *, struct journal_keys_to_wb *, u64); -void bch2_journal_keys_to_write_buffer_end(struct bch_fs *, struct journal_keys_to_wb *); +int bch2_journal_keys_to_write_buffer_end(struct bch_fs *, struct journal_keys_to_wb *); int bch2_btree_write_buffer_resize(struct bch_fs *, size_t); void bch2_fs_btree_write_buffer_exit(struct bch_fs *); diff --git a/fs/bcachefs/btree_write_buffer_types.h b/fs/bcachefs/btree_write_buffer_types.h index 5f248873087c..d39d163c6ea9 100644 --- a/fs/bcachefs/btree_write_buffer_types.h +++ b/fs/bcachefs/btree_write_buffer_types.h @@ -52,6 +52,8 @@ struct btree_write_buffer { struct btree_write_buffer_keys inc; struct btree_write_buffer_keys flushing; struct work_struct flush_work; + + DARRAY(struct btree_write_buffered_key) accounting; }; #endif /* _BCACHEFS_BTREE_WRITE_BUFFER_TYPES_H */ diff --git a/fs/bcachefs/journal_io.c b/fs/bcachefs/journal_io.c index b37b75ccd602..3ea2be99d411 100644 --- a/fs/bcachefs/journal_io.c +++ b/fs/bcachefs/journal_io.c @@ -1815,7 +1815,8 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w) jset_entry_for_each_key(i, k) { ret = bch2_journal_key_to_wb(c, &wb, i->btree_id, k); if (ret) { - bch2_fs_fatal_error(c, "-ENOMEM flushing journal keys to btree write buffer"); + bch2_fs_fatal_error(c, "error flushing journal keys to btree write buffer: %s", + bch2_err_str(ret)); bch2_journal_keys_to_write_buffer_end(c, &wb); return ret; } @@ -1825,8 +1826,14 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w) } } - if (wb.wb) - bch2_journal_keys_to_write_buffer_end(c, &wb); + if (wb.wb) { + ret = bch2_journal_keys_to_write_buffer_end(c, &wb); + if (ret) { + bch2_fs_fatal_error(c, "error flushing journal keys to btree write buffer: %s", + bch2_err_str(ret)); + return ret; + } + } spin_lock(&c->journal.lock); w->need_flush_to_write_buffer = false; From patchwork Sun Feb 25 02:38:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205977 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406703dyb; Sat, 24 Feb 2024 18:42:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCViB7lIO+VEPQ5o6rXGc8dzY63Rw1DGhW4ZV0FMpnVq4kN6WSuycDreCjF6SkJ+si9b2VvhohXN+Jxv5olt0uZJu7j9XQ== X-Google-Smtp-Source: AGHT+IFXUKUbxGVvE3G2RQARrH0fVFQcbrZQCEeNenio4hTIyT9j/c1y7m0cussan+hapU2pkyXl X-Received: by 2002:aa7:d9d3:0:b0:565:862c:bf85 with SMTP id v19-20020aa7d9d3000000b00565862cbf85mr2573030eds.12.1708828976751; Sat, 24 Feb 2024 18:42:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828976; cv=pass; d=google.com; s=arc-20160816; b=HksqTqqoTIDUJY7SV6DN8rCt2FCkighBBrQKFpxMCgaaYjf+2tnbtxOudW1eRmc+S9 1JjFXYxkd7vkBo6I6tS0YDWgb+eLAo7ZFd/uqT9/PDAHOl2A1FOU3u0NKVJmd5JFmqDg 99N/HgTXpzvMfjzU6D/GZOAJ1LbcgA4WMVEC0IHhhiY6C7CRa48yBRdt7+Xnhu2LkVj0 ChV7OsKgbpKYImwITDNMulSbx5cO7j52ZBRgIiDGdGLikGE0xFfoveYZAgWeht+tI630 5DhxyRKrPzFThuDh81n8wOzwDbVxHjW00VGYrGpP/1UH/90QGNmVzzEkxieZUutY7Kwc O7Cw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=KXqi/mUCPqaAmwNVCa/3pdqBU+XG+a15SZVPhvlslXA=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=ulNZnhauTDWZiYk/bFgA0mFg2Lc7gWB+ENtx0T8RLKhFdISvikWYkFFkIYmVUnN/IX avgggNQaQqpaSK0Rf0CkuvagJMCPtJmKnNMF7ttwsATAorr7ZexrHP95jClbEjeGG22A iGPz4/6jcbHh2nXYJFMXpUq6XzeiZgZKHywEppt7bQyotWDTmf269HjebeAm2y3G6e6i R6y5wTIDwqTsy17YpJmK2kiE5kJS7U7M3cCZaTKRnLinzCr/tO6gHtWFpk3Nim5Kp98Z OHlydaciUvuBiSzUJvxsxhX9Hv2rPGQRY7bXSfBqhvIwuhQPe7fDouO00plNjOW62zg3 cAfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Fjr7jqpM; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79947-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79947-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id f22-20020a50ee96000000b0056535d0a18esi881205edr.492.2024.02.24.18.42.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:42:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79947-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Fjr7jqpM; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79947-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79947-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 605731F21A13 for ; Sun, 25 Feb 2024 02:42:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B3821BC22; Sun, 25 Feb 2024 02:38:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Fjr7jqpM" Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9599C18AE0 for ; Sun, 25 Feb 2024 02:38:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828734; cv=none; b=QdPqLjNS3TcLf2fDJokjw5n95CQIO+hPp7h6oEWDhxBW50lk1L816wWTSnzKQRlNoyNxbJzmYXogHevkfCZXqSYTgpV3rF/ird/wSZ/Od3/Co0MItdlyT/EJS4uKfTb1YTLCVrFHZk1IBd04X+rUv/2Yjgs9/3ZeTnnkpXRD4Sw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828734; c=relaxed/simple; bh=CmRGISWqMl8OiQ/BrO+n0lHBIFvE2WpEgm7l++MU4x8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g6eD9dEd/0VH6o5k3WmfBRWknQ+mmGtpZi6Lnqq0war1rb9tiz9s3Oyf91di5yWbZzi2vUYq4YsBitcBf0cU5ZcVic1qnZU3rfgaq5/JG8l+19KQBEqXfRkVBZXqpRX9ll9GJhILWR9u8r3vJdVIPB18iOCvYV44odaZavU2qCc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Fjr7jqpM; arc=none smtp.client-ip=95.215.58.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828731; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KXqi/mUCPqaAmwNVCa/3pdqBU+XG+a15SZVPhvlslXA=; b=Fjr7jqpM1bfxbQZzfZEw2oEx+fC+2/tR+Hk4GtDWSMFSObqBrFPYCYyAx61DeCqFrB6BZV YN7kJt77NuFYbQv/Gjdssy8I0Qgx7U/GxmGEPG6PLtg35t0Z+WhBuwcXEv2NBjtttB3jDj B90A2do5+NkUf/ZfYL5c0dg/sNAKUlE= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 18/21] bcachefs: bch_acct_compression Date: Sat, 24 Feb 2024 21:38:20 -0500 Message-ID: <20240225023826.2413565-19-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791837053138874189 X-GMAIL-MSGID: 1791837053138874189 This adds per-compression-type accounting of compressed and uncompressed size as well as number of extents - meaning we can now see compression ratio (without walking the whole filesystem). Signed-off-by: Kent Overstreet --- fs/bcachefs/buckets.c | 45 ++++++++++++++++++++++++---- fs/bcachefs/disk_accounting.c | 4 +++ fs/bcachefs/disk_accounting_format.h | 8 ++++- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index 506bb580bff4..6078b67e51cf 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -503,6 +503,7 @@ static int __trigger_extent(struct btree_trans *trans, : BCH_DATA_user; s64 dirty_sectors = 0; int ret = 0; + u64 compression_acct[3] = { 1, 0, 0 }; struct disk_accounting_key acc = { .type = BCH_DISK_ACCOUNTING_replicas, @@ -511,6 +512,10 @@ static int __trigger_extent(struct btree_trans *trans, .replicas.nr_required = 1, }; + struct disk_accounting_key compression_key = { + .type = BCH_DISK_ACCOUNTING_compression, + }; + bkey_for_each_ptr_decode(k.k, ptrs, p, entry) { s64 disk_sectors; ret = bch2_trigger_pointer(trans, btree_id, level, k, p, &disk_sectors, flags); @@ -519,12 +524,13 @@ static int __trigger_extent(struct btree_trans *trans, bool stale = ret > 0; + if (p.ptr.cached && stale) + continue; + if (p.ptr.cached) { - if (!stale) { - ret = bch2_mod_dev_cached_sectors(trans, p.ptr.dev, disk_sectors, gc); - if (ret) - return ret; - } + ret = bch2_mod_dev_cached_sectors(trans, p.ptr.dev, disk_sectors, gc); + if (ret) + return ret; } else if (!p.has_ec) { dirty_sectors += disk_sectors; acc.replicas.devs[acc.replicas.nr_devs++] = p.ptr.dev; @@ -540,6 +546,26 @@ static int __trigger_extent(struct btree_trans *trans, */ acc.replicas.nr_required = 0; } + + if (compression_key.compression.type && + compression_key.compression.type != p.crc.compression_type) { + if (flags & BTREE_TRIGGER_OVERWRITE) + bch2_u64s_neg(compression_acct, 3); + + ret = bch2_disk_accounting_mod(trans, &compression_key, compression_acct, 2, gc); + if (ret) + return ret; + + compression_acct[0] = 1; + compression_acct[1] = 0; + compression_acct[2] = 0; + } + + compression_key.compression.type = p.crc.compression_type; + if (p.crc.compression_type) { + compression_acct[1] += p.crc.uncompressed_size; + compression_acct[2] += p.crc.compressed_size; + } } if (acc.replicas.nr_devs) { @@ -548,6 +574,15 @@ static int __trigger_extent(struct btree_trans *trans, return ret; } + if (compression_key.compression.type) { + if (flags & BTREE_TRIGGER_OVERWRITE) + bch2_u64s_neg(compression_acct, 3); + + ret = bch2_disk_accounting_mod(trans, &compression_key, compression_acct, 3, gc); + if (ret) + return ret; + } + return 0; } diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c index 8d7b6ab66e71..dc020d651d0a 100644 --- a/fs/bcachefs/disk_accounting.c +++ b/fs/bcachefs/disk_accounting.c @@ -5,6 +5,7 @@ #include "btree_update.h" #include "btree_write_buffer.h" #include "buckets.h" +#include "compress.h" #include "disk_accounting.h" #include "error.h" #include "journal_io.h" @@ -91,6 +92,9 @@ void bch2_accounting_key_to_text(struct printbuf *out, struct disk_accounting_ke case BCH_DISK_ACCOUNTING_dev_stripe_buckets: prt_printf(out, "dev=%u", k->dev_stripe_buckets.dev); break; + case BCH_DISK_ACCOUNTING_compression: + bch2_prt_compression_type(out, k->compression.type); + break; } } diff --git a/fs/bcachefs/disk_accounting_format.h b/fs/bcachefs/disk_accounting_format.h index e06a42f0d578..75bfc9bce79f 100644 --- a/fs/bcachefs/disk_accounting_format.h +++ b/fs/bcachefs/disk_accounting_format.h @@ -95,7 +95,8 @@ static inline bool data_type_is_hidden(enum bch_data_type type) x(persistent_reserved, 1) \ x(replicas, 2) \ x(dev_data_type, 3) \ - x(dev_stripe_buckets, 4) + x(dev_stripe_buckets, 4) \ + x(compression, 5) enum disk_accounting_type { #define x(f, nr) BCH_DISK_ACCOUNTING_##f = nr, @@ -120,6 +121,10 @@ struct bch_dev_stripe_buckets { __u8 dev; }; +struct bch_acct_compression { + __u8 type; +}; + struct disk_accounting_key { union { struct { @@ -130,6 +135,7 @@ struct disk_accounting_key { struct bch_replicas_entry_v1 replicas; struct bch_dev_data_type dev_data_type; struct bch_dev_stripe_buckets dev_stripe_buckets; + struct bch_acct_compression compression; }; }; struct bpos _pad; From patchwork Sun Feb 25 02:38:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205981 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406816dyb; Sat, 24 Feb 2024 18:43:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUeYZa68rMoqkWtbPXNourcj5xzqzl+New0dv7wuybOpoQ2xcGUodE/jvF1h+rUMUwx1o56/XqXiezYWOglFnQAfmv7Eg== X-Google-Smtp-Source: AGHT+IH1qkqC1u5hmbfJk22zK9sW5/0zLJGLdayASxHMktm3grvBiWM64eJ37nGMbTOATQtEujLB X-Received: by 2002:a17:906:1b51:b0:a3c:ae0d:793c with SMTP id p17-20020a1709061b5100b00a3cae0d793cmr2164349ejg.20.1708829007871; Sat, 24 Feb 2024 18:43:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708829007; cv=pass; d=google.com; s=arc-20160816; b=Ln3RznCC4ImEtc9HXJuYT/JmgvSx2rCn5iB9h2Ra9Ro/YIpHSerc1ZweJkvqkv5qB9 3oZvy3633y06G0a1VNvprfzWYg4qojXe4gfATUHuIYLeGs2kat8cWE02TKw37UsHPYkl iJVhdRvJEf0ntCtBJkEOGPgYjAZ32mVWWmoNZmIxXjlO+NrJ9f55cRsh5fRA6CITZ0bX KT5FsBZaLVjPxHqWdWsRJU0UvqM/kVWL1YK6YasmyWyB/nI/ojoCNo+14rWlqnwd6U29 1i9iQnK/Fayp9vcZU5tN5trANaX79ZL1/q3I/wH74HoWlj8n+0U8+juujOWp0jkoquX2 X5qw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=weqtx2u84KusAKamrBTKZCBf70EK9pRqL6N4MsvPgW0=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=PGJAPfnAjWEmfg/gAe3RGDYF5av03TNgQNwIDHfR/EpQMUCHhm4iDHTjZ7RVpMippN dCdJosn1PtZrswi1JY38B5UW2yXWETsvNCdcbLlF/mafbZI2e8BT+SwdL3UXM184QGFD MDE1kB6QbJILDfLkZGTODsgSH3IjDcfDLFeA7TTJVckfg8f0KwprR7uwW/7nBUp8o4ac UH6MsTsY/I9UO7mfUgUnHDFhbowbpr0enS5uDmaS6VDYKQ8DskkqrAQOIV+ZOLjFz7vs 1kawcEvZhzb+ft7jLf/xOrco2LBLynXHvuRg+JGvK60+o0qMIP9iUzzzCQdKCd8EXOXR rK+Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=GtMroGI9; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79950-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79950-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z11-20020a1709063acb00b00a4305a11019si529548ejd.174.2024.02.24.18.43.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:43:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79950-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=GtMroGI9; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79950-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79950-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 575D31F2104F for ; Sun, 25 Feb 2024 02:43:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E99F1C28B; Sun, 25 Feb 2024 02:39:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="GtMroGI9" Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96A4E1AADD for ; Sun, 25 Feb 2024 02:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828737; cv=none; b=uHSpJWvLppPfH27zWvWv4jTvwzFxcqgBoDRBwv3MLFn1NUXosVsaknDIs0wtj4iM0kwrb/xvQ6nkB6AhQVuSmXcficRwcq8Tu4/6iEziSsu29o1mgQJ8xQUfQqk1FtDX9aY8P/rkmCu36Hf8WiqKLEgb36hKMv12/dP4nzWNMBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828737; c=relaxed/simple; bh=ZgM0zLMZFwJYqyvB4tXh9kF50cWRp9rLDmexM/GbfvM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K8yU1fKcLEbGn9XDBWPWkIu38RE4zMe6a8SXSZiIwvFM//iKmPd1u68cik4aNQGUplzIHJifeddR5mR0nXr2RC1Q+8UuSD2GXKUmfGnTQ25HEjOk5DZ3vPlw3MVx2TwqqTOXZgH9EyNkmWQqmcBVsp8R06yWlIYDqJEce7bJhuU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=GtMroGI9; arc=none smtp.client-ip=95.215.58.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=weqtx2u84KusAKamrBTKZCBf70EK9pRqL6N4MsvPgW0=; b=GtMroGI9SLS2HtSssDe36Rm8zROfrOV84oqSilqNyQ2mrClrsaF9kMvGGXEIGcdMFQ+4ox yEVdD91npxWvtmF924xIjbT+LsABnJdd8Pk4fMKyoMRA3ZTxdonTPh4BrzJXvRlvxiIqHj JLCJDAQVT9YdZ0xYe8lCVAXTYVeoW0U= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 19/21] bcachefs: Convert bch2_compression_stats_to_text() to new accounting Date: Sat, 24 Feb 2024 21:38:21 -0500 Message-ID: <20240225023826.2413565-20-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791837085367802010 X-GMAIL-MSGID: 1791837085367802010 We no longer have to walk the whole btree to calculate compression stats. Signed-off-by: Kent Overstreet --- fs/bcachefs/sysfs.c | 85 ++++++++++----------------------------------- 1 file changed, 18 insertions(+), 67 deletions(-) diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c index c86a93a8d8fc..287a0bf920db 100644 --- a/fs/bcachefs/sysfs.c +++ b/fs/bcachefs/sysfs.c @@ -22,6 +22,7 @@ #include "buckets.h" #include "clock.h" #include "compress.h" +#include "disk_accounting.h" #include "disk_groups.h" #include "ec.h" #include "inode.h" @@ -256,63 +257,6 @@ static size_t bch2_btree_cache_size(struct bch_fs *c) static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c) { - struct btree_trans *trans; - enum btree_id id; - struct compression_type_stats { - u64 nr_extents; - u64 sectors_compressed; - u64 sectors_uncompressed; - } s[BCH_COMPRESSION_TYPE_NR]; - u64 compressed_incompressible = 0; - int ret = 0; - - memset(s, 0, sizeof(s)); - - if (!test_bit(BCH_FS_started, &c->flags)) - return -EPERM; - - trans = bch2_trans_get(c); - - for (id = 0; id < BTREE_ID_NR; id++) { - if (!btree_type_has_ptrs(id)) - continue; - - ret = for_each_btree_key(trans, iter, id, POS_MIN, - BTREE_ITER_ALL_SNAPSHOTS, k, ({ - struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k); - struct bch_extent_crc_unpacked crc; - const union bch_extent_entry *entry; - bool compressed = false, incompressible = false; - - bkey_for_each_crc(k.k, ptrs, crc, entry) { - incompressible |= crc.compression_type == BCH_COMPRESSION_TYPE_incompressible; - compressed |= crc_is_compressed(crc); - - if (crc_is_compressed(crc)) { - s[crc.compression_type].nr_extents++; - s[crc.compression_type].sectors_compressed += crc.compressed_size; - s[crc.compression_type].sectors_uncompressed += crc.uncompressed_size; - } - } - - compressed_incompressible += compressed && incompressible; - - if (!compressed) { - unsigned t = incompressible ? BCH_COMPRESSION_TYPE_incompressible : 0; - - s[t].nr_extents++; - s[t].sectors_compressed += k.k->size; - s[t].sectors_uncompressed += k.k->size; - } - 0; - })); - } - - bch2_trans_put(trans); - - if (ret) - return ret; - prt_str(out, "type"); printbuf_tabstop_push(out, 12); prt_tab(out); @@ -330,28 +274,35 @@ static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c prt_tab_rjust(out); prt_newline(out); - for (unsigned i = 0; i < ARRAY_SIZE(s); i++) { + for (unsigned i = 1; i < BCH_COMPRESSION_TYPE_NR; i++) { + struct disk_accounting_key a = { + .type = BCH_DISK_ACCOUNTING_compression, + .compression.type = i, + }; + struct bpos p = disk_accounting_key_to_bpos(&a); + u64 v[3]; + bch2_accounting_mem_read(c, p, v, ARRAY_SIZE(v)); + + u64 nr_extents = v[0]; + u64 sectors_uncompressed = v[1]; + u64 sectors_compressed = v[2]; + bch2_prt_compression_type(out, i); prt_tab(out); - prt_human_readable_u64(out, s[i].sectors_compressed << 9); + prt_human_readable_u64(out, sectors_compressed << 9); prt_tab_rjust(out); - prt_human_readable_u64(out, s[i].sectors_uncompressed << 9); + prt_human_readable_u64(out, sectors_uncompressed << 9); prt_tab_rjust(out); - prt_human_readable_u64(out, s[i].nr_extents - ? div_u64(s[i].sectors_uncompressed << 9, s[i].nr_extents) + prt_human_readable_u64(out, nr_extents + ? div_u64(sectors_uncompressed << 9, nr_extents) : 0); prt_tab_rjust(out); prt_newline(out); } - if (compressed_incompressible) { - prt_printf(out, "%llu compressed & incompressible extents", compressed_incompressible); - prt_newline(out); - } - return 0; } From patchwork Sun Feb 25 02:38:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205979 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406753dyb; Sat, 24 Feb 2024 18:43:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXA4ttnBpVAVjIN9KDoxgXm52StS736O1VtaIZlqB1O+Hl1SDA0dKMvoKI8LzXD0S8gHbcktT0NbEv5CZgcdnoZ0pUCUw== X-Google-Smtp-Source: AGHT+IEIlIRiKHDSfkHuQ2thrXsllZsiZaQmjJ4m5lYxuM+i2MqD4tkUbUVI/zjWzW675jisQLoL X-Received: by 2002:ac8:4b70:0:b0:42e:71bf:fb01 with SMTP id g16-20020ac84b70000000b0042e71bffb01mr2902532qts.11.1708828991483; Sat, 24 Feb 2024 18:43:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828991; cv=pass; d=google.com; s=arc-20160816; b=Gpk6kURW/rvnh4F3EBSxrtT97fyZ0nucmYOb4Vz320ROjza0nqFRX6CASHUpUQxN0g woum3rdN4ItRZfZe4gy/HwF6B4whFjAlh9GHwSlO79UQUi/FE3fctaNlrHjgkKbMx6oc sE3pY1aHQ4F3u/Nyx9G2nHxyLxinFvSumpLpjgn9svGRDUjPogATtkGhDQvJE4aZo5cc Go/j7AhL8YSNCfkKsogyc8xYIq2bE+MPdRL9oos2cIbYUBmoilYJ5tSHXJU7ZODPZnEx uUb7PuUNnKBjjVYdXg+Cny5IPYamW8zgAO2By28mDSWzgmEG9D3XTqQJ21kHeKfsdiV4 kyoA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=njdVxTl+tyjYoQarlLc40yxm4EXppgie2qLf5Ju2emw=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=oo7uI2y+XV6c6SeFXqCfNPXLMVBBVl/3BAc6RIhXR4QfhXQ1uQBjmFiM6Gu3y7kQFx IDjHo3Hbi3PFs48kYGKpln9a+pnq1GcMnmXNCezry2wJS5YPnlck+OPmMRE+Qa+UX0vj XTrJoZnec5moPlr4c/BYVBMwjeh/2bfyB9dV8DdFqw2slQKsI1Bb9Rqnw7xd/kz+kBBN jw015mSdXFvboMZS8zVNG2W44zb58sAHmuza+2pUAFrekB4A/mywLZFSDQfuFiAb2+6r yK4pF+2ypj+SOpaEIiFFyU4E+oZ25yiZFpFGDBjjQO8y7aBvqHqFD1OfQ2NYz4yiyYla YHWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=dFpkOyJp; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79948-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79948-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id xz20-20020a05620a5e1400b00787b430b36bsi2183644qkn.724.2024.02.24.18.43.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:43:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79948-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=dFpkOyJp; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79948-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79948-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 47E1F1C20ACC for ; Sun, 25 Feb 2024 02:43:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02A411BDCF; Sun, 25 Feb 2024 02:38:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="dFpkOyJp" Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3948F5256 for ; Sun, 25 Feb 2024 02:38:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828736; cv=none; b=T+csMglcWtcULjv8IjuQZ3wbJkVi/3sW1gVtk3uLdGarQZNFMGDi9qcaz2x6H0kl7MlZcl7f4DD/ztCWTK6yzI798d4yWaRo4Wa494VosLOWU/e0IQXFH29yWon08i+bK2gw9iPEe7PYlg5kwRhioqSZkJphxHiKhbtB2CNI8Vg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828736; c=relaxed/simple; bh=d8WYXNqXDWpZE4u+quG0FNl5y/ZGCmEc/dORUsz9M60=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ibvo9H8HwoFwj+SxxnoXCwWpmu87ojTXMgztXW4YULMRbcEuZvHut7ZBkZbBwJCrUe5v1+k3/qrt+ZXiQOzBbc1d3J+yQKe1sFyl1+URBaCaxx9wKhujT9inSnbLEVmo9qh4/raUEdxcrdeL55/tLZpvOjECESK15LK9H9RP2DA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=dFpkOyJp; arc=none smtp.client-ip=95.215.58.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828732; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=njdVxTl+tyjYoQarlLc40yxm4EXppgie2qLf5Ju2emw=; b=dFpkOyJpE+vAWCrCeqjmgO4KjuyA+cNXR4K91DVMXSDUhtYjTvtg6YwMCkRtaUGjncIAsx KVLX5Brz3u8mgYUCbdcLe11heCjIT0PwXC0u2vfVqvnYCX5qsnu+oB+a9z3fHp9fGTSoyx WNE/5CtIf30n9gMB+JkKbtfWeKAW9Nc= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 20/21] bcachefs: bch2_fs_accounting_to_text() Date: Sat, 24 Feb 2024 21:38:22 -0500 Message-ID: <20240225023826.2413565-21-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791837068201031832 X-GMAIL-MSGID: 1791837068201031832 Helper to show raw accounting in sysfs, mainly for debugging. Signed-off-by: Kent Overstreet --- fs/bcachefs/disk_accounting.c | 26 ++++++++++++++++++++++++++ fs/bcachefs/disk_accounting.h | 1 + fs/bcachefs/sysfs.c | 5 +++++ 3 files changed, 32 insertions(+) diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c index dc020d651d0a..9d6ca2ea307b 100644 --- a/fs/bcachefs/disk_accounting.c +++ b/fs/bcachefs/disk_accounting.c @@ -286,6 +286,32 @@ int bch2_fs_replicas_usage_read(struct bch_fs *c, darray_char *usage) return ret; } +void bch2_fs_accounting_to_text(struct printbuf *out, struct bch_fs *c) +{ + struct bch_accounting_mem *acc = &c->accounting[0]; + + percpu_down_read(&c->mark_lock); + out->atomic++; + + eytzinger0_for_each(i, acc->k.nr) { + struct disk_accounting_key acc_k; + bpos_to_disk_accounting_key(&acc_k, acc->k.data[i].pos); + + bch2_accounting_key_to_text(out, &acc_k); + + u64 v[BCH_ACCOUNTING_MAX_COUNTERS]; + bch2_accounting_mem_read_counters(c, i, v, ARRAY_SIZE(v), false); + + prt_str(out, ":"); + for (unsigned j = 0; j < acc->k.data[i].nr_counters; j++) + prt_printf(out, " %llu", v[j]); + prt_newline(out); + } + + --out->atomic; + percpu_up_read(&c->mark_lock); +} + static int accounting_write_key(struct btree_trans *trans, struct bpos pos, u64 *v, unsigned nr_counters) { struct bkey_i_accounting *a = bch2_trans_kmalloc(trans, sizeof(*a) + sizeof(*v) * nr_counters); diff --git a/fs/bcachefs/disk_accounting.h b/fs/bcachefs/disk_accounting.h index a0cf7a0b84a7..c4a8b9cce6ba 100644 --- a/fs/bcachefs/disk_accounting.h +++ b/fs/bcachefs/disk_accounting.h @@ -186,6 +186,7 @@ static inline void bch2_accounting_mem_read(struct bch_fs *c, struct bpos p, } int bch2_fs_replicas_usage_read(struct bch_fs *, darray_char *); +void bch2_fs_accounting_to_text(struct printbuf *, struct bch_fs *); int bch2_accounting_gc_done(struct bch_fs *); diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c index 287a0bf920db..10470cef30f0 100644 --- a/fs/bcachefs/sysfs.c +++ b/fs/bcachefs/sysfs.c @@ -204,6 +204,7 @@ read_attribute(disk_groups); read_attribute(has_data); read_attribute(alloc_debug); +read_attribute(accounting); #define x(t, n, ...) read_attribute(t); BCH_PERSISTENT_COUNTERS() @@ -413,6 +414,9 @@ SHOW(bch2_fs) if (attr == &sysfs_disk_groups) bch2_disk_groups_to_text(out, c); + if (attr == &sysfs_accounting) + bch2_fs_accounting_to_text(out, c); + return 0; } @@ -625,6 +629,7 @@ struct attribute *bch2_fs_internal_files[] = { &sysfs_internal_uuid, &sysfs_disk_groups, + &sysfs_accounting, NULL }; From patchwork Sun Feb 25 02:38:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 205980 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1406800dyb; Sat, 24 Feb 2024 18:43:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVbyUHg4UJdNIB66zTd0jWlGnQRy/GmlMUjiFUZbp+NozAeHNFL/mNVJFW9ekW8mRXiZPT+mHusGrLq/8qZJY+RAhce0g== X-Google-Smtp-Source: AGHT+IGeF5JUNiR4EAEhw7Jdq74K04Pf2BeGUBkpSqyuvQUj/gM4sK6GEerKlps9+Y3SWvFVjSIc X-Received: by 2002:a17:902:ecc8:b0:1d9:c367:205d with SMTP id a8-20020a170902ecc800b001d9c367205dmr4972787plh.53.1708829005128; Sat, 24 Feb 2024 18:43:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708829005; cv=pass; d=google.com; s=arc-20160816; b=oDOFF9NrHRJsKZtLtISVZbg7YYws1dfPmUt7UEjZyt0IHeFKgTo0etGNVvLJSYNoj0 7v0WmxqmG6E2sUivYBfgoazlk+XE+FTPoGwU+29nQbtotPPKSDRcU9ddld2bQ6xuccxF JvEz23tBDqnIS5Wj1VuuW9HY/bHgsHxENI1piCRzLARuNfeckox9oOLuzLgxTzcyXJ1b WeyUpH4DiuxnxMRZ/yV7Lzqr6mpbCZ0hzyAzAl60OFlrUIGwJlX3igJwvANujpAAAciM f0a8gl3rpwF3okIbXz879wgUXd3ZwhQdXFvp9VLKFcPNjksB/EQNsNw8PEPt7a+VhAj/ eXUQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=R05PvZLs8g3ZOV6GSh50wBEFv8JbV+JIgM3xfyBtfwY=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=ivrQMvSHW4ZOtvA8RH0lxtS5LzPfuytr9K2dXObr+glIGCz+T9tYg6mfpmJT4ptkca xDRa/M65DIn9p3OKl4D1qgQHNXmE5cgb9b1Ifb6nuoLCGARNO8wbzxUsfCzoDxYdYrFr NfIHcPw6+FWzyYRlc3P0iOprKOCTLv3ItLg3ystWOh5clzWVYt4T/44+Lh2M/vb3LgKP D2eMXCtGemTMghXZyCxEIVR+STXQgV6D1489b2cAKG0vsmpHPRwP5r5tdX72ddk4ihJl Qkxmo6m021Zg0i+J/wdogucnngnZVz7a1BoWc0RgdFGCADs8yLaSVsu2Q7P2arJSgTdh mR1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ABOfH9pg; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79949-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79949-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e15-20020a170902784f00b001dc879b3af9si1273642pln.55.2024.02.24.18.43.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:43:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79949-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ABOfH9pg; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79949-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79949-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 8570AB20E37 for ; Sun, 25 Feb 2024 02:43:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF8A51BF44; Sun, 25 Feb 2024 02:38:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ABOfH9pg" Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56ED8DDAD for ; Sun, 25 Feb 2024 02:38:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828737; cv=none; b=OiDg+RUw5hItsuZG5UpjNvFwHS3+YWGaYjZVUdpKcFY7GZVGCdEQ4whF5azB6AEDhulLv+prQsBS7t5sOCtiiQmcshVIaEDXjSrolQKb7Y7PI9yJkRwS9oKqfAVLNN9qbQVYeh0Nsh6GrHGIhK43LG93fuydIAcIpLrDVJtccgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828737; c=relaxed/simple; bh=DfA9FVN9BLpGyKYVyfilqkfCwE9P2RiMXuov2SLCyRQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bafr9GcwVPQwgu0ZPjxVC1jvFBY+WgOFGf4SefzrFTzOegpk7BZMYjuqumfGoiENJMT5rtI5SXVGEXauTAHmHW8shBkM3IQvoEvJW2bMjFsx0Hq1lO2jCXcme9pNJnYb0BVBODuEW4525x+4/IpnK/yUqNr6DMQ30RyJDabzSns= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ABOfH9pg; arc=none smtp.client-ip=95.215.58.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828733; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R05PvZLs8g3ZOV6GSh50wBEFv8JbV+JIgM3xfyBtfwY=; b=ABOfH9pgrb1Dn5VORYxI5KNr7K0saesLc8gSTUBUt1urNenkobzD64qE8QGOxt8XhmFwp6 4uk5NdJ08DMgkYwbothiJa4mlww9zk2RIBSiZLMd4iLL9u6pQlTm16HgnAv8jPtQmxAjCS IkUZ+qEOfB/dlGkaO9MjJJfoP/JeWWc= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 21/21] bcachefs: bch2_fs_usage_base_to_text() Date: Sat, 24 Feb 2024 21:38:23 -0500 Message-ID: <20240225023826.2413565-22-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791837082730879098 X-GMAIL-MSGID: 1791837082730879098 Helper to show raw accounting in sysfs, mainly for debugging. Signed-off-by: Kent Overstreet --- fs/bcachefs/sysfs.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c index 10470cef30f0..27aca70cb385 100644 --- a/fs/bcachefs/sysfs.c +++ b/fs/bcachefs/sysfs.c @@ -205,6 +205,7 @@ read_attribute(disk_groups); read_attribute(has_data); read_attribute(alloc_debug); read_attribute(accounting); +read_attribute(usage_base); #define x(t, n, ...) read_attribute(t); BCH_PERSISTENT_COUNTERS() @@ -329,6 +330,20 @@ static void bch2_btree_wakeup_all(struct bch_fs *c) seqmutex_unlock(&c->btree_trans_lock); } +static void bch2_fs_usage_base_to_text(struct printbuf *out, struct bch_fs *c) +{ + struct bch_fs_usage_base b = {}; + + acc_u64s_percpu(&b.hidden, &c->usage->hidden, sizeof(b) / sizeof(u64)); + + prt_printf(out, "hidden:\t\t%llu\n", b.hidden); + prt_printf(out, "btree:\t\t%llu\n", b.btree); + prt_printf(out, "data:\t\t%llu\n", b.data); + prt_printf(out, "cached:\t%llu\n", b.cached); + prt_printf(out, "reserved:\t\t%llu\n", b.reserved); + prt_printf(out, "nr_inodes:\t%llu\n", b.nr_inodes); +} + SHOW(bch2_fs) { struct bch_fs *c = container_of(kobj, struct bch_fs, kobj); @@ -417,6 +432,9 @@ SHOW(bch2_fs) if (attr == &sysfs_accounting) bch2_fs_accounting_to_text(out, c); + if (attr == &sysfs_usage_base) + bch2_fs_usage_base_to_text(out, c); + return 0; } @@ -630,6 +648,7 @@ struct attribute *bch2_fs_internal_files[] = { &sysfs_disk_groups, &sysfs_accounting, + &sysfs_usage_base, NULL };