[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [linux-2.6.18-xen] gntdev: fix multi-page slot allocation


  • To: xen-changelog@xxxxxxxxxxxxxxxxxxx
  • From: Xen patchbot-linux-2.6.18-xen <patchbot@xxxxxxx>
  • Date: Mon, 14 May 2012 16:29:46 +0000
  • Delivery-date: Mon, 14 May 2012 16:29:50 +0000
  • List-id: "Change log for Mercurial \(receive only\)" <xen-changelog.lists.xen.org>

# HG changeset patch
# User Jan Beulich <jbeulich@xxxxxxxx>
# Date 1336749460 -7200
# Node ID c0e1133a1fc113be9c756c80167f8f55613d1ac9
# Parent  456451e35eca858a0ec0ae6d47febcb7038e0493
gntdev: fix multi-page slot allocation

Any range with the first slot available would have got considered
usable, as range_length never got reset when encountering an in-use
slot.

Additionally fold the two almost identical loops into a single
instance, at once avoiding to go through both loops when start_index
was zero even for the first one.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---


diff -r 456451e35eca -r c0e1133a1fc1 drivers/xen/gntdev/gntdev.c
--- a/drivers/xen/gntdev/gntdev.c       Fri May 11 17:13:17 2012 +0200
+++ b/drivers/xen/gntdev/gntdev.c       Fri May 11 17:17:40 2012 +0200
@@ -285,35 +285,27 @@ static void compress_free_list(gntdev_fi
 static int find_contiguous_free_range(gntdev_file_private_data_t *private_data,
                                      uint32_t num_slots) 
 {
-       uint32_t i, start_index = private_data->next_fit_index;
-       uint32_t range_start = 0, range_length;
+       /* First search from next_fit_index to the end of the array. */
+       uint32_t start_index = private_data->next_fit_index;
+       uint32_t end_index = private_data->grants_size;
 
-       /* First search from the start_index to the end of the array. */
-       range_length = 0;
-       for (i = start_index; i < private_data->grants_size; ++i) {
-               if (private_data->grants[i].state == GNTDEV_SLOT_INVALID) {
-                       if (range_length == 0) {
-                               range_start = i;
-                       }
-                       ++range_length;
-                       if (range_length == num_slots) {
-                               return range_start;
-                       }
+       for (;;) {
+               uint32_t i, range_start = 0, range_length = 0;
+
+               for (i = start_index; i < end_index; ++i) {
+                       if (private_data->grants[i].state == 
GNTDEV_SLOT_INVALID) {
+                               if (range_length == 0)
+                                       range_start = i;
+                               if (++range_length == num_slots)
+                                       return range_start;
+                       } else
+                               range_length = 0;
                }
-       }
-       
-       /* Now search from the start of the array to the start_index. */
-       range_length = 0;
-       for (i = 0; i < start_index; ++i) {
-               if (private_data->grants[i].state == GNTDEV_SLOT_INVALID) {
-                       if (range_length == 0) {
-                               range_start = i;
-                       }
-                       ++range_length;
-                       if (range_length == num_slots) {
-                               return range_start;
-                       }
-               }
+               /* Now search from the start of the array to next_fit_index. */
+               if (!start_index)
+                       break;
+               end_index = start_index;
+               start_index = 0;
        }
        
        return -ENOMEM;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.