+ /* 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 > 72) {
+ 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 > 8TB assume average file size 1MB */
+ if (device_sz >= (8ULL << 30))
+ bytes_per_inode = 1024 * 1024;
+ /* OST > 1TB assume average file size 256kB */
+ else if (device_sz >= (1ULL << 30))
+ bytes_per_inode = 256 * 1024;
+ /* OST > 100GB assume average file size 64kB,
+ * plus a bit so that inodes will fit into a
+ * 256x flex_bg without overflowing */
+ else if (device_sz >= (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));
+ }
+ }
+