Now that we have a dedicated kthread in place to perform targeted region
evacuation, add and export a mechanism to queue work to the kthread.

Adding work to kmempowerd is very simple: just set the bits corresponding
to the region numbers that we want to evacuate, and queue the work item
to the kthread.

Signed-off-by: Srivatsa S. Bhat <srivatsa.b...@linux.vnet.ibm.com>
---

 mm/compaction.c |   26 ++++++++++++++++++++++++++
 mm/internal.h   |    3 +++
 2 files changed, 29 insertions(+)

diff --git a/mm/compaction.c b/mm/compaction.c
index 0511eae..b56be89 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -1271,6 +1271,32 @@ int evacuate_mem_region(struct zone *z, struct 
zone_mem_region *zmr)
 #define nr_zone_region_bits    MAX_NR_ZONE_REGIONS
 static DECLARE_BITMAP(mpwork_mask, nr_zone_region_bits);
 
+void queue_mempower_work(struct pglist_data *pgdat, struct zone *zone,
+                        int region_id)
+{
+       struct mempower_work *mpwork;
+       unsigned long flags;
+
+       mpwork = &zone->mempower_work;
+       spin_lock_irqsave(&mpwork->lock, flags);
+       set_bit(region_id, mpwork->mempower_mask);
+       spin_unlock_irqrestore(&mpwork->lock, flags);
+
+       /*
+        * The kmempowerd kthread will never miss the work we assign it,
+        * due to the way queue_kthread_work() and kthread_worker_fn()
+        * synchronize with each other. If the work is currently executing,
+        * it gets requeued; but if it is pending, the kthread will naturally
+        * process it in the future. Eitherway, it will notice and process
+        * all the work submitted to it, and won't prematurely go to sleep.
+        *
+        * Note: The bits set in the mempower_mask represent the actual
+        * "work" for the kthread. The work-struct is just a container used
+        * to communicate that work to the kthread.
+        */
+       queue_kthread_work(&pgdat->mempower_worker, &mpwork->work);
+}
+
 static void kmempowerd(struct kthread_work *work)
 {
        struct mempower_work *mpwork;
diff --git a/mm/internal.h b/mm/internal.h
index acb50f8..3fbc9f6 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -181,6 +181,9 @@ int compact_range(struct compact_control *cc, struct 
aggression_control *ac,
                  struct free_page_control *fc, unsigned long start,
                  unsigned long end);
 
+void queue_mempower_work(struct pglist_data *pgdat, struct zone *zone,
+                        int region_id);
+
 #endif
 
 /*

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to