<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On Thu, Nov 3, 2016 at 1:05 AM, Dilger, Andreas <span dir="ltr">&lt;<a href="mailto:andreas.dilger@intel.com" target="_blank">andreas.dilger@intel.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Oct 25, 2016, at 10:47, Aya Mahfouz &lt;<a href="mailto:mahfouz.saif.elyazal@gmail.com">mahfouz.saif.elyazal@gmail.<wbr>com</a>&gt; wrote:<br>
&gt;<br>
&gt; On Mon, Oct 17, 2016 at 10:38:31PM +0000, Dilger, Andreas wrote:<br>
&gt;&gt; On Oct 17, 2016, at 15:46, Aya Mahfouz &lt;<a href="mailto:mahfouz.saif.elyazal@gmail.com">mahfouz.saif.elyazal@gmail.<wbr>com</a>&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; class_devno_max is an inline function that returns<br>
&gt;&gt;&gt; MAX_OBD_DEVICES. Replace all calls to the function<br>
&gt;&gt;&gt; by MAX_OBD_DEVICES.<br>
&gt;&gt;<br>
&gt;&gt; Thanks for your patch, but unfortunately it can&#39;t be accepted.<br>
&gt;&gt;<br>
&gt;&gt; This function was added in preparation of being able to tune the maximum<br>
&gt;&gt; number of storage devices dynamically, rather than having to hard code it<br>
&gt;&gt; to the maximum possible number of servers that a client can possibly<br>
&gt;&gt; connect to.<br>
&gt;&gt;<br>
&gt;&gt; While the current maximum of 8192 servers has been enough for current<br>
&gt;&gt; filesystems, I&#39;d rather move in the direction of dynamically handling this<br>
&gt;&gt; limit rather than re-introducing a hard-coded constant throughout the code.<br>
&gt;&gt;<br>
&gt; Hello,<br>
&gt;<br>
&gt; I would like to proceed with implementing the function if possible.<br>
&gt; Kindly direct me to some starting pointers.<br>
<br>
</span>Hi Aya,<br>
thanks for offering to look into this.<br>
<br>
There are several ways to approach this problem  to make the allocation<br>
of the obd_devs[] array dynamic.  In most cases, there isn&#39;t any value<br>
to dynamically shrink this array, since the filesystem(s) will typically<br>
be mounted until the node is rebooted, and it is only in the tens of KB<br>
size range, so this will not affect ongoing operations, and that simplifies<br>
the implementation.<br>
<br>
The easiest way would be to have a dynamically-sized obd_devs[] array that<br>
is reallocated in class_newdev() in PAGE_SIZE chunks whenever the current<br>
array has no more free slots and copied to the new array, using obd_dev_lock<br>
to protect the array while it is being reallocated and copied.  In most<br>
cases, this would save memory over the static array (not many filesystems<br>
have so many servers), but for the few sites that have 10000+ servers they<br>
don&#39;t need to change the source to handle this.  Using libcfs_kvzalloc()<br>
would avoid issues with allocating large chunks of memory.<br>
<br>
There are a few places where obd_devs[] is accessed outside obd_dev_lock<br>
that would need to be fixed now that this array may be changed at runtime.<br>
<br>
A second approach that may scale better is to change obd_devs from an array<br>
to a doubly linked list (using standard list_head helpers).  In many cases<br>
the whole list is seached linearly, and most of the uses of class_num2obd()<br>
are just used to walk that list in order, which could be replaced with<br>
list_for_each_entry() list traversal.  The class_name2dev() function should<br>
be changed to return the pointer to the obd_device structure, and a new<br>
helper class_dev2num() would just return the obd_minor number from the<br>
obd_device struct for the one use in class_resolve_dev_name().  Using a<br>
linked list has the advantage that there is no need to search for free slots<br>
in the array, since devices would be removed from the list when it is freed.<br>
<br>
Cheers, Andreas<br>
<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div>Thanks Andreas! Will start looking into it.<br><br>--<br></div><div>Kind Regards,<br></div><div>Aya Saif El-yazal Mahfouz<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">
&gt;&gt; One comment inline below, if you still want to submit a patch.<br>
&gt;&gt;<br>
&gt;&gt;&gt; Signed-off-by: Aya Mahfouz &lt;<a href="mailto:mahfouz.saif.elyazal@gmail.com">mahfouz.saif.elyazal@gmail.<wbr>com</a>&gt;<br>
&gt;&gt;&gt; ---<br>
&gt;&gt;&gt; drivers/staging/lustre/lustre/<wbr>obdclass/class_obd.c |  6 +++---<br>
&gt;&gt;&gt; drivers/staging/lustre/lustre/<wbr>obdclass/genops.c    | 22 +++++++++++-----------<br>
&gt;&gt;&gt; .../lustre/lustre/obdclass/<wbr>linux/linux-module.c    |  6 +++---<br>
&gt;&gt;&gt; 3 files changed, 17 insertions(+), 17 deletions(-)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; diff --git a/drivers/staging/lustre/<wbr>lustre/obdclass/class_obd.c b/drivers/staging/lustre/<wbr>lustre/obdclass/class_obd.c<br>
&gt;&gt;&gt; index 2b21675..b775c74 100644<br>
&gt;&gt;&gt; --- a/drivers/staging/lustre/<wbr>lustre/obdclass/class_obd.c<br>
&gt;&gt;&gt; +++ b/drivers/staging/lustre/<wbr>lustre/obdclass/class_obd.c<br>
&gt;&gt;&gt; @@ -345,7 +345,7 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)<br>
&gt;&gt;&gt;                     goto out;<br>
&gt;&gt;&gt;             }<br>
&gt;&gt;&gt;             obd = class_name2obd(data-&gt;ioc_<wbr>inlbuf4);<br>
&gt;&gt;&gt; -   } else if (data-&gt;ioc_dev &lt; class_devno_max()) {<br>
&gt;&gt;&gt; +   } else if (data-&gt;ioc_dev &lt; MAX_OBD_DEVICES) {<br>
&gt;&gt;&gt;             obd = class_num2obd(data-&gt;ioc_dev);<br>
&gt;&gt;&gt;     } else {<br>
&gt;&gt;&gt;             CERROR(&quot;OBD ioctl: No device\n&quot;);<br>
&gt;&gt;&gt; @@ -498,7 +498,7 @@ static int __init obdclass_init(void)<br>
&gt;&gt;&gt;     }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     /* This struct is already zeroed for us (static global) */<br>
&gt;&gt;&gt; -   for (i = 0; i &lt; class_devno_max(); i++)<br>
&gt;&gt;&gt; +   for (i = 0; i &lt; MAX_OBD_DEVICES; i++)<br>
&gt;&gt;&gt;             obd_devs[i] = NULL;<br>
&gt;&gt;<br>
&gt;&gt; This block can just be removed entirely.  It used to do something useful,<br>
&gt;&gt; but through a series of changes it has become useless.<br>
&gt;&gt;<br>
&gt;&gt; Cheers, Andreas<br>
&gt;&gt;<br>
&gt;&gt;&gt;     /* Default the dirty page cache cap to 1/2 of system memory.<br>
&gt;&gt;&gt; @@ -548,7 +548,7 @@ static void obdclass_exit(void)<br>
&gt;&gt;&gt;     lustre_unregister_fs();<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     misc_deregister(&amp;obd_psdev);<br>
&gt;&gt;&gt; -   for (i = 0; i &lt; class_devno_max(); i++) {<br>
&gt;&gt;&gt; +   for (i = 0; i &lt; MAX_OBD_DEVICES; i++) {<br>
&gt;&gt;&gt;             struct obd_device *obd = class_num2obd(i);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;             if (obd &amp;&amp; obd-&gt;obd_set_up &amp;&amp;<br>
&gt;&gt;&gt; diff --git a/drivers/staging/lustre/<wbr>lustre/obdclass/genops.c b/drivers/staging/lustre/<wbr>lustre/obdclass/genops.c<br>
&gt;&gt;&gt; index 99c2da6..af4fc58 100644<br>
&gt;&gt;&gt; --- a/drivers/staging/lustre/<wbr>lustre/obdclass/genops.c<br>
&gt;&gt;&gt; +++ b/drivers/staging/lustre/<wbr>lustre/obdclass/genops.c<br>
&gt;&gt;&gt; @@ -290,7 +290,7 @@ struct obd_device *class_newdev(const char *type_name, const char *name)<br>
&gt;&gt;&gt;     LASSERT(newdev-&gt;obd_magic == OBD_DEVICE_MAGIC);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     write_lock(&amp;obd_dev_lock);<br>
&gt;&gt;&gt; -   for (i = 0; i &lt; class_devno_max(); i++) {<br>
&gt;&gt;&gt; +   for (i = 0; i &lt; MAX_OBD_DEVICES; i++) {<br>
&gt;&gt;&gt;             struct obd_device *obd = class_num2obd(i);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;             if (obd &amp;&amp; (strcmp(name, obd-&gt;obd_name) == 0)) {<br>
&gt;&gt;&gt; @@ -322,9 +322,9 @@ struct obd_device *class_newdev(const char *type_name, const char *name)<br>
&gt;&gt;&gt;     }<br>
&gt;&gt;&gt;     write_unlock(&amp;obd_dev_lock);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; -   if (!result &amp;&amp; i &gt;= class_devno_max()) {<br>
&gt;&gt;&gt; +   if (!result &amp;&amp; i &gt;= MAX_OBD_DEVICES) {<br>
&gt;&gt;&gt;             CERROR(&quot;all %u OBD devices used, increase MAX_OBD_DEVICES\n&quot;,<br>
&gt;&gt;&gt; -                  class_devno_max());<br>
&gt;&gt;&gt; +                  MAX_OBD_DEVICES);<br>
&gt;&gt;&gt;             result = ERR_PTR(-EOVERFLOW);<br>
&gt;&gt;&gt;             goto out;<br>
&gt;&gt;&gt;     }<br>
&gt;&gt;&gt; @@ -372,7 +372,7 @@ int class_name2dev(const char *name)<br>
&gt;&gt;&gt;             return -1;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     read_lock(&amp;obd_dev_lock);<br>
&gt;&gt;&gt; -   for (i = 0; i &lt; class_devno_max(); i++) {<br>
&gt;&gt;&gt; +   for (i = 0; i &lt; MAX_OBD_DEVICES; i++) {<br>
&gt;&gt;&gt;             struct obd_device *obd = class_num2obd(i);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;             if (obd &amp;&amp; strcmp(name, obd-&gt;obd_name) == 0) {<br>
&gt;&gt;&gt; @@ -397,7 +397,7 @@ struct obd_device *class_name2obd(const char *name)<br>
&gt;&gt;&gt; {<br>
&gt;&gt;&gt;     int dev = class_name2dev(name);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; -   if (dev &lt; 0 || dev &gt; class_devno_max())<br>
&gt;&gt;&gt; +   if (dev &lt; 0 || dev &gt; MAX_OBD_DEVICES)<br>
&gt;&gt;&gt;             return NULL;<br>
&gt;&gt;&gt;     return class_num2obd(dev);<br>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt; @@ -408,7 +408,7 @@ int class_uuid2dev(struct obd_uuid *uuid)<br>
&gt;&gt;&gt;     int i;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     read_lock(&amp;obd_dev_lock);<br>
&gt;&gt;&gt; -   for (i = 0; i &lt; class_devno_max(); i++) {<br>
&gt;&gt;&gt; +   for (i = 0; i &lt; MAX_OBD_DEVICES; i++) {<br>
&gt;&gt;&gt;             struct obd_device *obd = class_num2obd(i);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;             if (obd &amp;&amp; obd_uuid_equals(uuid, &amp;obd-&gt;obd_uuid)) {<br>
&gt;&gt;&gt; @@ -435,7 +435,7 @@ struct obd_device *class_num2obd(int num)<br>
&gt;&gt;&gt; {<br>
&gt;&gt;&gt;     struct obd_device *obd = NULL;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; -   if (num &lt; class_devno_max()) {<br>
&gt;&gt;&gt; +   if (num &lt; MAX_OBD_DEVICES) {<br>
&gt;&gt;&gt;             obd = obd_devs[num];<br>
&gt;&gt;&gt;             if (!obd)<br>
&gt;&gt;&gt;                     return NULL;<br>
&gt;&gt;&gt; @@ -463,7 +463,7 @@ struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,<br>
&gt;&gt;&gt;     int i;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     read_lock(&amp;obd_dev_lock);<br>
&gt;&gt;&gt; -   for (i = 0; i &lt; class_devno_max(); i++) {<br>
&gt;&gt;&gt; +   for (i = 0; i &lt; MAX_OBD_DEVICES; i++) {<br>
&gt;&gt;&gt;             struct obd_device *obd = class_num2obd(i);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;             if (!obd)<br>
&gt;&gt;&gt; @@ -496,13 +496,13 @@ struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid, int *next)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     if (!next)<br>
&gt;&gt;&gt;             i = 0;<br>
&gt;&gt;&gt; -   else if (*next &gt;= 0 &amp;&amp; *next &lt; class_devno_max())<br>
&gt;&gt;&gt; +   else if (*next &gt;= 0 &amp;&amp; *next &lt; MAX_OBD_DEVICES)<br>
&gt;&gt;&gt;             i = *next;<br>
&gt;&gt;&gt;     else<br>
&gt;&gt;&gt;             return NULL;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     read_lock(&amp;obd_dev_lock);<br>
&gt;&gt;&gt; -   for (; i &lt; class_devno_max(); i++) {<br>
&gt;&gt;&gt; +   for (; i &lt; MAX_OBD_DEVICES; i++) {<br>
&gt;&gt;&gt;             struct obd_device *obd = class_num2obd(i);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;             if (!obd)<br>
&gt;&gt;&gt; @@ -533,7 +533,7 @@ int class_notify_sptlrpc_conf(<wbr>const char *fsname, int namelen)<br>
&gt;&gt;&gt;     LASSERT(namelen &gt; 0);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     read_lock(&amp;obd_dev_lock);<br>
&gt;&gt;&gt; -   for (i = 0; i &lt; class_devno_max(); i++) {<br>
&gt;&gt;&gt; +   for (i = 0; i &lt; MAX_OBD_DEVICES; i++) {<br>
&gt;&gt;&gt;             obd = class_num2obd(i);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;             if (!obd || obd-&gt;obd_set_up == 0 || obd-&gt;obd_stopping)<br>
&gt;&gt;&gt; diff --git a/drivers/staging/lustre/<wbr>lustre/obdclass/linux/linux-<wbr>module.c b/drivers/staging/lustre/<wbr>lustre/obdclass/linux/linux-<wbr>module.c<br>
&gt;&gt;&gt; index 33342bf..ca5b466 100644<br>
&gt;&gt;&gt; --- a/drivers/staging/lustre/<wbr>lustre/obdclass/linux/linux-<wbr>module.c<br>
&gt;&gt;&gt; +++ b/drivers/staging/lustre/<wbr>lustre/obdclass/linux/linux-<wbr>module.c<br>
&gt;&gt;&gt; @@ -228,7 +228,7 @@ static ssize_t health_show(struct kobject *kobj, struct attribute *attr,<br>
&gt;&gt;&gt;             return sprintf(buf, &quot;LBUG\n&quot;);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     read_lock(&amp;obd_dev_lock);<br>
&gt;&gt;&gt; -   for (i = 0; i &lt; class_devno_max(); i++) {<br>
&gt;&gt;&gt; +   for (i = 0; i &lt; MAX_OBD_DEVICES; i++) {<br>
&gt;&gt;&gt;             struct obd_device *obd;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;             obd = class_num2obd(i);<br>
&gt;&gt;&gt; @@ -326,7 +326,7 @@ static struct attribute *lustre_attrs[] = {<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; static void *obd_device_list_seq_start(<wbr>struct seq_file *p, loff_t *pos)<br>
&gt;&gt;&gt; {<br>
&gt;&gt;&gt; -   if (*pos &gt;= class_devno_max())<br>
&gt;&gt;&gt; +   if (*pos &gt;= MAX_OBD_DEVICES)<br>
&gt;&gt;&gt;             return NULL;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     return pos;<br>
&gt;&gt;&gt; @@ -339,7 +339,7 @@ static void obd_device_list_seq_stop(<wbr>struct seq_file *p, void *v)<br>
&gt;&gt;&gt; static void *obd_device_list_seq_next(<wbr>struct seq_file *p, void *v, loff_t *pos)<br>
&gt;&gt;&gt; {<br>
&gt;&gt;&gt;     ++*pos;<br>
&gt;&gt;&gt; -   if (*pos &gt;= class_devno_max())<br>
&gt;&gt;&gt; +   if (*pos &gt;= MAX_OBD_DEVICES)<br>
&gt;&gt;&gt;             return NULL;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;     return pos;<br>
&gt;&gt;&gt; --<br>
&gt;&gt;&gt; 2.5.0<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; --<br>
&gt;&gt;&gt; Kind Regards,<br>
&gt;&gt;&gt; Aya Saif El-yazal Mahfouz<br>
&gt;&gt;&gt; ______________________________<wbr>_________________<br>
&gt;&gt;&gt; lustre-devel mailing list<br>
&gt;&gt;&gt; <a href="mailto:lustre-devel@lists.lustre.org">lustre-devel@lists.lustre.org</a><br>
&gt;&gt;&gt; <a href="http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org" rel="noreferrer" target="_blank">http://lists.lustre.org/<wbr>listinfo.cgi/lustre-devel-<wbr>lustre.org</a><br>
&gt;&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Kind Regards,<br>
&gt; Aya Saif El-yazal Mahfouz<br>
&gt; ______________________________<wbr>_________________<br>
&gt; lustre-devel mailing list<br>
&gt; <a href="mailto:lustre-devel@lists.lustre.org">lustre-devel@lists.lustre.org</a><br>
&gt; <a href="http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org" rel="noreferrer" target="_blank">http://lists.lustre.org/<wbr>listinfo.cgi/lustre-devel-<wbr>lustre.org</a><br>
<br>
</div></div></blockquote></div><br></div></div>