- /* Bytes_per_inode: disk size / num inodes */
- if (strstr(mop->mo_mkfsopts, "-i") == NULL &&
- strstr(mop->mo_mkfsopts, "-N") == NULL) {
- long bytes_per_inode = 0;
-
- /* Allocate more inodes on MDT devices. There is
- * no data stored on the MDT, and very little extra
- * metadata beyond the inode. It could go down as
- * low as 1024 bytes, but this is conservative.
- * Account for external EA blocks for wide striping. */
- if (IS_MDT(&mop->mo_ldd)) {
- bytes_per_inode = inode_size + 1536;
-
- if (mop->mo_stripe_count > 59) {
- int extra = mop->mo_stripe_count * 24;
- extra = ((extra - 1) | 4095) + 1;
- bytes_per_inode += extra;
- }
- }
-
- /* Allocate fewer inodes on large OST devices. Most
- * filesystems can be much more aggressive than even
- * this, but it is impossible to know in advance. */
- if (IS_OST(&mop->mo_ldd)) {
- /* OST > 16TB assume average file size 1MB */
- if (device_kb > (16ULL << 30))
- bytes_per_inode = 1024 * 1024;
- /* OST > 4TB assume average file size 512kB */
- else if (device_kb > (4ULL << 30))
- bytes_per_inode = 512 * 1024;
- /* OST > 1TB assume average file size 256kB */
- else if (device_kb > (1ULL << 30))
- bytes_per_inode = 256 * 1024;
- /* OST > 10GB assume average file size 64kB,
- * plus a bit so that inodes will fit into a
- * 256x flex_bg without overflowing */
- else if (device_kb > (10ULL << 20))
- bytes_per_inode = 69905;
- }
-
- if (bytes_per_inode > 0) {
- sprintf(buf, " -i %ld", bytes_per_inode);
- strscat(mop->mo_mkfsopts, buf,
- sizeof(mop->mo_mkfsopts));
- }
+ /*
+ * The inode size is constituted by following elements
+ * (assuming all files are in composite layout and has
+ * 3 components):
+ *
+ * ldiskfs inode size: 160
+ * MDT extended attributes size, including:
+ * ext4_xattr_header: 32
+ * LOV EA size: 32(lov_comp_md_v1) +
+ * 3 * 40(lov_comp_md_entry_v1) +
+ * 3 * 32(lov_mds_md) +
+ * stripes * 24(lov_ost_data) +
+ * 16(xattr_entry) + 4("lov")
+ * LMA EA size: 24(lustre_mdt_attrs) +
+ * 16(xattr_entry) + 4("lma")
+ * SOM EA size: 24(lustre_som_attrs) +
+ * 16(xattr_entry) + 4("som")
+ * link EA size: 24(link_ea_header) + 18(link_ea_entry) +
+ * 16(filename) + 16(xattr_entry) + 4("link")
+ * and some margin for 4-byte alignment, ACLs and other EAs.
+ *
+ * If we say the average filename length is about 32 bytes,
+ * the calculation looks like:
+ * 160 + 32 + (32+3*(40+32)+24*stripes+20) + (24+20) + (24+20) +
+ * (24+20) + (~42+16+20) + other <= 512*2^m, {m=0,1,2,3}
+ */
+ if (strstr(mop->mo_mkfsopts, "-I") == NULL) {
+ if (IS_MDT(&mop->mo_ldd)) {
+ if (mop->mo_stripe_count > 59)
+ inode_size = 512; /* bz 7241 */
+ /* see also "-i" below for EA blocks */
+ else if (mop->mo_stripe_count > 16)
+ inode_size = 2048;
+ else
+ inode_size = 1024;
+ } else if (IS_OST(&mop->mo_ldd)) {
+ /* We store MDS FID and necessary composite
+ * layout information in the OST object EA:
+ * ldiskfs inode size: 160
+ * OST extended attributes size, including:
+ * ext4_xattr_header: 32
+ * LMA EA size: 24(lustre_mdt_attrs) +
+ * 16(xattr_entry) + 4("lma")
+ * FID EA size: 52(filter_fid) +
+ * 16(xattr_entry) + 4("fid")
+ * 160 + 32 + (24+20) + (52+20) = 308
+ */
+ inode_size = 512;