From: Liang Zhen Date: Tue, 10 Jan 2012 17:18:52 +0000 (+0800) Subject: LU-822 osd: use bitmask to calculate seq hash X-Git-Tag: 2.1.55~18 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=b4b479dace076bed6210f78b498309038aeeb4a2;ds=sidebyside LU-822 osd: use bitmask to calculate seq hash We are using mod to hash seq to different OI files, which is not allowed on 32-bit arch because seq is 64-bit. It can be resolved by limit oi_count to power2 and use bitmask to calculate seq hash. This patch also renamed modparameter osd_oi_num to osd_oi_count. Signed-off-by: Liang Zhen Change-Id: I61c1fac65a33c78b5b5196d2b2d6fd5519deffda Reviewed-on: http://review.whamcloud.com/1941 Tested-by: Hudson Reviewed-by: Mikhail Pershin Reviewed-by: Andreas Dilger Tested-by: Maloo --- diff --git a/lustre/osd-ldiskfs/osd_internal.h b/lustre/osd-ldiskfs/osd_internal.h index a9450a4..abb5c49 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -402,7 +402,9 @@ osd_fid2oi(struct osd_device *osd, const struct lu_fid *fid) return NULL; LASSERT(osd->od_oi_table != NULL && osd->od_oi_count >= 1); - return &osd->od_oi_table[fid->f_seq % osd->od_oi_count]; + /* It can work even od_oi_count equals to 1 although it's unexpected, + * the only reason we set it to 1 is for performance measurement */ + return &osd->od_oi_table[fid->f_seq & (osd->od_oi_count - 1)]; } #endif /* __KERNEL__ */ diff --git a/lustre/osd-ldiskfs/osd_oi.c b/lustre/osd-ldiskfs/osd_oi.c index bcad98e..1548eb4 100644 --- a/lustre/osd-ldiskfs/osd_oi.c +++ b/lustre/osd-ldiskfs/osd_oi.c @@ -77,8 +77,8 @@ #define OSD_OI_FID_NR (1UL << OSD_OI_FID_OID_BITS) #define OSD_OI_FID_NR_MAX (1UL << OSD_OI_FID_OID_BITS_MAX) -static unsigned int osd_oi_num = OSD_OI_FID_NR; -CFS_MODULE_PARM(osd_oi_num, "i", int, 0444, +static unsigned int osd_oi_count = OSD_OI_FID_NR; +CFS_MODULE_PARM(osd_oi_count, "i", int, 0444, "Number of Object Index containers to be created, " "it's only valid for new filesystem."); @@ -275,18 +275,20 @@ int osd_oi_init(struct osd_thread_info *info, } /* create OI objects */ - rc = osd_oi_table_create(info, dev, mdev, osd_oi_num); + rc = osd_oi_table_create(info, dev, mdev, osd_oi_count); if (rc != 0) goto out; - rc = osd_oi_table_open(info, dev, oi, osd_oi_num, 0); - LASSERT(rc == osd_oi_num || rc < 0); + rc = osd_oi_table_open(info, dev, oi, osd_oi_count, 0); + LASSERT(rc == osd_oi_count || rc < 0); out: - if (rc < 0) + if (rc < 0) { OBD_FREE(oi, sizeof(*oi) * OSD_OI_FID_NR_MAX); - else + } else { + LASSERT((rc & (rc - 1)) == 0); *oi_table = oi; + } cfs_mutex_unlock(&oi_init_lock); return rc; @@ -380,8 +382,14 @@ int osd_oi_delete(struct osd_thread_info *info, int osd_oi_mod_init() { - if (osd_oi_num == 0 || osd_oi_num > OSD_OI_FID_NR_MAX) - osd_oi_num = OSD_OI_FID_NR; + if (osd_oi_count == 0 || osd_oi_count > OSD_OI_FID_NR_MAX) + osd_oi_count = OSD_OI_FID_NR; + + if ((osd_oi_count & (osd_oi_count - 1)) != 0) { + LCONSOLE_WARN("Round up oi_count %d to power2 %d\n", + osd_oi_count, size_roundup_power2(osd_oi_count)); + osd_oi_count = size_roundup_power2(osd_oi_count); + } cfs_mutex_init(&oi_init_lock); return 0;