Here are 5 patches to make sysfs O(log n) and improve performance on
operations with many block devices.
Patch 1 changes synchronize_rcu() to synchronize_rcu_expedited(), it
causes massive speedup when deleting many block devices.
Patch 2 fixes inefficient i_nlink calculation in sysfs.
Patch 3 makes name lookups use rb-tree.
Patch 4 removes s_sibling hack (it has no effect on performance).
Patch 5 makes inode number lookups use rb-tree --- thus making all types
of sysfs directory operations O(log n).
Performance testing --- 10000 dm devices created with dmsetup:
The numbers are time in seconds to perform these operations:
1. create 10000 devices
2. ls -la /sys/block
3. ls -al /sys/block after a cache flush (echo 3 >/proc/sys/vm/drop_caches)
4. dmsetup remove_all
+ if (sysfs_type(sd) == SYSFS_DIR)
+ parent_sd->s_dir.subdirs++;
+
/* Store directory entries in order by ino. This allows
* readdir to properly restart without having to add a
* cursor into the s_dir.children list.
@@ -73,6 +76,9 @@ static void sysfs_unlink_sibling(struct
{
struct sysfs_dirent **pos;
- for (sd = parent_sd->s_dir.children; sd; sd = sd->s_sibling) {
- if (ns && sd->s_ns && (sd->s_ns != ns))
- continue;
- if (!strcmp(sd->s_name, name))
- return sd;
+ while (p) {
+ int c;
+#define node rb_entry(p, struct sysfs_dirent, name_node)
+ c = strcmp(name, node->s_name);
+ if (c < 0) {
+ p = node->name_node.rb_left;
+ } else if (c > 0) {
+ p = node->name_node.rb_right;
+ } else {
+ return node;
+ }
+#undef node
}
+
return NULL;
}
sysfs: remove s_sibling hacks
s_sibling was used for three different purposes:
1) as a linked list of entries in the directory
2) as a linked list of entries to be deleted
3) as a pointer to "struct completion"
This patch removes the hack and introduces new union u which
holds pointers for cases 2) and 3).
This change is needed for the following patch that removes s_sibling at all
and replaces it with a rb tree.
rwsem_acquire(&sd->dep_map, 0, 0, _RET_IP_);
/* atomic_add_return() is a mb(), put_active() will always see
- * the updated sd->s_sibling.
+ * the updated sd->u.completion.
*/
v = atomic_add_return(SD_DEACTIVATED_BIAS, &sd->s_active);
+ union {
+ struct completion *completion;
+ struct sysfs_dirent *removed_list;
+ } u;
+
const void *s_ns; /* namespace tag */
union {
struct sysfs_elem_dir s_dir;
sysfs: use rb-tree for inode number lookup
This patch makes sysfs use red-black tree for inode number lookup.
Together with a previous patch to use red-black tree for name lookup,
this patch makes all sysfs lookups to have O(log n) complexity.
union {
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
07-21-2011, 08:34 AM
Joe Thornber
improve sysfs performance, make it O(log n)
On Wed, Jul 20, 2011 at 06:56:50PM -0400, Mikulas Patocka wrote:
> Performance testing --- 10000 dm devices created with dmsetup:
>
> The numbers are time in seconds to perform these operations:
> 1. create 10000 devices
> 2. ls -la /sys/block
> 3. ls -al /sys/block after a cache flush (echo 3 >/proc/sys/vm/drop_caches)
> 4. dmsetup remove_all
>
> no patches 109 9.8 12 1624
> patch 1 109 9.1 12 15
> patches 1,2 120 0.19 3.0 16
> patches 1,2,3 68 0.17 0.47 12
> patches 1,2,3,4 68 0.15 0.48 11
> all patches 37 0.16 0.46 3.3
Fantastic improvement Mikulas!
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
07-21-2011, 04:31 PM
Greg KH
improve sysfs performance, make it O(log n)
On Wed, Jul 20, 2011 at 06:56:50PM -0400, Mikulas Patocka wrote:
> Hi
>
> Here are 5 patches to make sysfs O(log n) and improve performance on
> operations with many block devices.
Very nice job.
But can you please resend these, one per email, so that they could be
applied to the tree (Documentation/SubmittingPatches describes this
requirement).
Also note that it is past the merge window time for patches to be
accepted for 3.1, so this will remain in my "to-apply" queue until after
3.1-rc1 is out for the 3.2 merge.
thanks,
greg k-h
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel