[issue1773] patch: Add variable sleep time to vm_zeroidle

Venkatesh Srinivas (via DragonFly issue tracker) sinknull at leaf.dragonflybsd.org
Wed May 26 15:25:58 PDT 2010


New submission from Venkatesh Srinivas <me at acm.jhu.edu>:

--- vm_zeroidle.c.orig  2010-05-26 15:09:26 -0700
+++ vm_zeroidle.c       2010-05-26 15:12:50 -0700
@@ -90,6 +90,9 @@
        STATE_RELEASE_PAGE
 };

+#define DEFAULT_SLEEP_TIME     (hz / 10)
+#define LONG_SLEEP_TIME        (hz * 10)
+
 static int zero_state;

 /*
@@ -112,6 +115,20 @@
        return (1);
 }

+/*
+ * vm_pagezero should sleep for a long time when idlezero is disabled or when
+ * there is an excess of zeroed pages.
+ */
+static int
+vm_page_zero_time(void)
+{
+       if (idlezero_enable == 0)
+               return (LONG_SLEEP_TIME);
+       if (vm_page_zero_count >= ZIDLE_HI(vmstats.v_free_count))
+               return (LONG_SLEEP_TIME);
+       return (DEFAULT_SLEEP_TIME);
+}
+
 static void
 vm_pagezero(void __unused *arg)
 {
@@ -120,6 +137,7 @@
        enum zeroidle_state state = STATE_IDLE;
        char *pg = NULL;
        int npages = 0;
+       int sleep_time;
        int i = 0;

        /*
@@ -132,6 +150,7 @@
        rel_mplock();
        lwkt_setpri_self(TDPRI_IDLE_WORK);
        lwkt_setcpu_self(globaldata_find(ncpus - 1));
+       sleep_time = DEFAULT_SLEEP_TIME;

        /*
         * Loop forever
@@ -142,9 +161,10 @@
                        /*
                         * Wait for work.
                         */
-                       tsleep(&zero_state, 0, "pgzero", hz / 10);
+                       tsleep(&zero_state, 0, "pgzero", sleep_time);
                        if (vm_page_zero_check())
                                npages = idlezero_rate / 10;
+                       sleep_time = vm_page_zero_time();
                        if (npages)
                                state = STATE_GET_PAGE; /* Fallthrough */
                        break;
@@ -198,7 +218,8 @@
                        }
                        break;
                }
-               lwkt_switch();
+               if (lwkt_check_resched(curthread))
+                       lwkt_switch();
        }
 }


=================================

The patch above should cause vm_zeroidle to sleep for longer periods of time (hz 
* 10) when it is disabled or when there are a lot of pages. Longer sleep times 
would be better when there're no pages to zero.

It also conditionalizes the lwkt_switch(); I think this is worth doing, since 
lwkt_check_resched() is cheaper than lwkt_switch(). This may or may not be worth 
doing.

-- vs

----------
messages: 8623
nosy: vsrinivas
status: unread
title: patch: Add variable sleep time to vm_zeroidle

_____________________________________________________
DragonFly issue tracker <bugs at lists.dragonflybsd.org>
<http://bugs.dragonflybsd.org/issue1773>
_____________________________________________________






More information about the Bugs mailing list