seq_file: don't call bitmap_scnprintf_len()
PATCH 1/4 seq_file: don't call bitmap_scnprintf_len()
"m->count + len < m->size" is true commonly, so bitmap_scnprintf() is commonly called. this fix saves a call to bitmap_scnprintf_len().
---
fs/seq_file.c +8 -7
@@ -452,17 +452,18 @@ int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc)int seq_bitmap (struct seq_file *m,unsigned long *bits,unsigned int nr_bits) { -size_t len =bitmap_scnprintf_len (nr_bits); - -if (m->count + len < m->size) { -bitmap_scnprintf (m->buf + m->count, m->size - m->count, - bits, nr_bits); - m->count += len; -return 0 ; +if (m->count < m->size) { +int len =bitmap_scnprintf (m->buf + m->count, + m->size - m->count, bits, nr_bits); +if (m->count + len < m->size) { + m->count += len; +return 0 ; + } } m->count = m->size;return -1 ; } +EXPORT_SYMBOL (seq_bitmap);static void *single_start (struct seq_file *p,loff_t *pos) {
Quoted 2 lines · Lai Jiangshan
"
m->count+ len <m->size" is true commonly, sobitmap_scnprintf()is commonly called. this fix saves a call tobitmap_scnprintf_len().
This saves a call if seq buffer is already full which is not a common situation, so you're optimising for rare situations and adding branch for common ones.
Quoted 15 lines
fs/seq_file.c +2
-7@@ -452,17 +452,18 @@ int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc)int seq_bitmap (struct seq_file *m,unsigned long *bits,unsigned int nr_bits) { -size_t len =bitmap_scnprintf_len (nr_bits); - -if (m->count + len < m->size) { -bitmap_scnprintf (m->buf + m->count, m->size - m->count, - bits, nr_bits); - m->count += len; -return 0 ; +if (m->count < m->size) { + int len = bitmap_scnprintf(m->buf + m->count,
fs/seq_file.c int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc) · line 466
Quoted 10 lines
fs/seq_file.c +6
-0+ m->size - m->count, bits, nr_bits); +if (m->count + len < m->size) { + m->count += len; +return 0 ; + } } m->count = m->size;return -1 ; } +EXPORT_SYMBOL (seq_bitmap);
Modular users, where are they?
Quoted 7 lines · Alexey Dobriyan
Quoted 2 lines · Lai Jiangshan
"
m->count+ len <m->size" is true commonly, sobitmap_scnprintf()is commonly called. this fix saves a call tobitmap_scnprintf_len().This saves a call if seq buffer is already full which is not a common situation, so you're optimising for rare situations and adding branch for common ones.
Hi Alexey
I think this saves a call if seq buffer is _not_ full after called.
since calling bitmap_scnprintf() is the common situation. so we use the return value of bitmap_scnprintf() instead of bitmap_scnprintf_len().
In old code bitmap_scnprintf_len() and bitmap_scnprintf() must be called commonly.
Thanks Lai.
Quoted 31 lines
Quoted 16 lines
fs/seq_file.c +2
-7@@ -452,17 +452,18 @@ int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc)int seq_bitmap (struct seq_file *m,unsigned long *bits,unsigned int nr_bits) { -size_t len =bitmap_scnprintf_len (nr_bits); - -if (m->count + len < m->size) { -bitmap_scnprintf (m->buf + m->count, m->size - m->count, - bits, nr_bits); - m->count += len; -return 0 ; +if (m->count < m->size) { + int len = bitmap_scnprintf(m->buf + m->count,fs/seq_file.c int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc) · line 466
Quoted 10 lines
fs/seq_file.c +6
-0+ m->size - m->count, bits, nr_bits); +if (m->count + len < m->size) { + m->count += len; +return 0 ; + } } m->count = m->size;return -1 ; } +EXPORT_SYMBOL (seq_bitmap);Modular users, where are they?
Quoted 12 lines · Lai Jiangshan
Quoted 6 lines · Alexey Dobriyan
Quoted 2 lines · Lai Jiangshan
"
m->count+ len <m->size" is true commonly, sobitmap_scnprintf()is commonly called. this fix saves a call tobitmap_scnprintf_len().This saves a call if seq buffer is already full which is not a common situation, so you're optimising for rare situations and adding branch for common ones.
Hi Alexey
I think this saves a call if seq buffer is _not_ full after called.
Quoted 7 lines
since calling
bitmap_scnprintf()is the common situation. so we use the return value ofbitmap_scnprintf()instead ofbitmap_scnprintf_len().In old code
bitmap_scnprintf_len()andbitmap_scnprintf()must be called commonly.Thanks Lai.
Hi, Alexey,
Have noticed this comment? I hold my ground, ;-)
And seq_cpumask_list(), seq_nodemask_list() are needed for print mask safely, Should I send independent patches for them if we can't make an agreement about this fix.
Lai
Quoted 32 lines
Quoted 30 lines
Quoted 16 lines
fs/seq_file.c +2
-7@@ -452,17 +452,18 @@ int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc)int seq_bitmap (struct seq_file *m,unsigned long *bits,unsigned int nr_bits) { -size_t len =bitmap_scnprintf_len (nr_bits); - -if (m->count + len < m->size) { -bitmap_scnprintf (m->buf + m->count, m->size - m->count, - bits, nr_bits); - m->count += len; -return 0 ; +if (m->count < m->size) { + int len = bitmap_scnprintf(m->buf + m->count,fs/seq_file.c int seq_dentry(struct seq_file *m, struct dentry *dentry, char *esc) · line 466
Quoted 10 lines
fs/seq_file.c +6
-0+ m->size - m->count, bits, nr_bits); +if (m->count + len < m->size) { + m->count += len; +return 0 ; + } } m->count = m->size;return -1 ; } +EXPORT_SYMBOL (seq_bitmap);Modular users, where are they?