linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
To: naoya.horiguchi@nec.com
Cc: linmiaohe@huawei.com, akpm@linux-foundation.org,
	tony.luck@intel.com, ying.huang@intel.com, fengwei.yin@intel.com,
	qiuxu.zhuo@intel.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/2] mm: memory-failure: Make memory_failure_queue_delayed() helper
Date: Fri, 22 Dec 2023 14:27:05 +0800	[thread overview]
Message-ID: <20231222062706.5221-1-qiuxu.zhuo@intel.com> (raw)
In-Reply-To: <20231215081204.8802-1-qiuxu.zhuo@intel.com>

Introduce the memory_failure_queue_delayed() helper for deferred handling
of memory failure tasks. This prepares for later re-splitting of a
hardware-poisoned huge page.

Signed-off-by: Qiuxu Zhuo <qiuxu.zhuo@intel.com>
---
Prepares for the patch 2.

 mm/memory-failure.c | 51 +++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 23 deletions(-)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 660c21859118..8f2c11863bae 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -2385,28 +2385,12 @@ struct memory_failure_cpu {
 	DECLARE_KFIFO(fifo, struct memory_failure_entry,
 		      MEMORY_FAILURE_FIFO_SIZE);
 	spinlock_t lock;
-	struct work_struct work;
+	struct delayed_work work;
 };
 
 static DEFINE_PER_CPU(struct memory_failure_cpu, memory_failure_cpu);
 
-/**
- * memory_failure_queue - Schedule handling memory failure of a page.
- * @pfn: Page Number of the corrupted page
- * @flags: Flags for memory failure handling
- *
- * This function is called by the low level hardware error handler
- * when it detects hardware memory corruption of a page. It schedules
- * the recovering of error page, including dropping pages, killing
- * processes etc.
- *
- * The function is primarily of use for corruptions that
- * happen outside the current execution context (e.g. when
- * detected by a background scrubber)
- *
- * Can run in IRQ context.
- */
-void memory_failure_queue(unsigned long pfn, int flags)
+static void memory_failure_queue_delayed(unsigned long pfn, int flags, unsigned long delay)
 {
 	struct memory_failure_cpu *mf_cpu;
 	unsigned long proc_flags;
@@ -2418,13 +2402,34 @@ void memory_failure_queue(unsigned long pfn, int flags)
 	mf_cpu = &get_cpu_var(memory_failure_cpu);
 	spin_lock_irqsave(&mf_cpu->lock, proc_flags);
 	if (kfifo_put(&mf_cpu->fifo, entry))
-		schedule_work_on(smp_processor_id(), &mf_cpu->work);
+		schedule_delayed_work_on(smp_processor_id(), &mf_cpu->work, delay);
 	else
 		pr_err("buffer overflow when queuing memory failure at %#lx\n",
 		       pfn);
 	spin_unlock_irqrestore(&mf_cpu->lock, proc_flags);
 	put_cpu_var(memory_failure_cpu);
 }
+
+/**
+ * memory_failure_queue - Schedule handling memory failure of a page.
+ * @pfn: Page Number of the corrupted page
+ * @flags: Flags for memory failure handling
+ *
+ * This function is called by the low level hardware error handler
+ * when it detects hardware memory corruption of a page. It schedules
+ * the recovering of error page, including dropping pages, killing
+ * processes etc.
+ *
+ * The function is primarily of use for corruptions that
+ * happen outside the current execution context (e.g. when
+ * detected by a background scrubber)
+ *
+ * Can run in IRQ context.
+ */
+void memory_failure_queue(unsigned long pfn, int flags)
+{
+	memory_failure_queue_delayed(pfn, flags, 0);
+}
 EXPORT_SYMBOL_GPL(memory_failure_queue);
 
 static void memory_failure_work_func(struct work_struct *work)
@@ -2434,7 +2439,7 @@ static void memory_failure_work_func(struct work_struct *work)
 	unsigned long proc_flags;
 	int gotten;
 
-	mf_cpu = container_of(work, struct memory_failure_cpu, work);
+	mf_cpu = container_of(work, struct memory_failure_cpu, work.work);
 	for (;;) {
 		spin_lock_irqsave(&mf_cpu->lock, proc_flags);
 		gotten = kfifo_get(&mf_cpu->fifo, &entry);
@@ -2457,8 +2462,8 @@ void memory_failure_queue_kick(int cpu)
 	struct memory_failure_cpu *mf_cpu;
 
 	mf_cpu = &per_cpu(memory_failure_cpu, cpu);
-	cancel_work_sync(&mf_cpu->work);
-	memory_failure_work_func(&mf_cpu->work);
+	cancel_delayed_work_sync(&mf_cpu->work);
+	memory_failure_work_func(&mf_cpu->work.work);
 }
 
 static int __init memory_failure_init(void)
@@ -2470,7 +2475,7 @@ static int __init memory_failure_init(void)
 		mf_cpu = &per_cpu(memory_failure_cpu, cpu);
 		spin_lock_init(&mf_cpu->lock);
 		INIT_KFIFO(mf_cpu->fifo);
-		INIT_WORK(&mf_cpu->work, memory_failure_work_func);
+		INIT_DELAYED_WORK(&mf_cpu->work, memory_failure_work_func);
 	}
 
 	register_sysctl_init("vm", memory_failure_table);
-- 
2.17.1



  parent reply	other threads:[~2023-12-22  6:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-15  8:12 [PATCH 1/1] mm: memory-failure: Re-split hw-poisoned huge page on -EAGAIN Qiuxu Zhuo
2023-12-19  2:17 ` Naoya Horiguchi
2023-12-20  8:44   ` Zhuo, Qiuxu
2023-12-19 11:50 ` Miaohe Lin
2023-12-20  8:56   ` Zhuo, Qiuxu
2023-12-22  6:27 ` Qiuxu Zhuo [this message]
2023-12-22  6:27   ` [PATCH v2 2/2] " Qiuxu Zhuo
2023-12-22 19:42     ` Andrew Morton
2024-01-02  2:41       ` Zhuo, Qiuxu
2024-01-03  2:47         ` Miaohe Lin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231222062706.5221-1-qiuxu.zhuo@intel.com \
    --to=qiuxu.zhuo@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=fengwei.yin@intel.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=naoya.horiguchi@nec.com \
    --cc=tony.luck@intel.com \
    --cc=ying.huang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox