From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 443C6C41535 for ; Fri, 22 Dec 2023 06:27:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BFE076B0085; Fri, 22 Dec 2023 01:27:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BAE196B0087; Fri, 22 Dec 2023 01:27:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A76076B0088; Fri, 22 Dec 2023 01:27:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 93D2A6B0085 for ; Fri, 22 Dec 2023 01:27:54 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6E4E51A07AB for ; Fri, 22 Dec 2023 06:27:54 +0000 (UTC) X-FDA: 81593473668.04.24E9EDE Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by imf30.hostedemail.com (Postfix) with ESMTP id BCAA280002 for ; Fri, 22 Dec 2023 06:27:51 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=kiXTZefW; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf30.hostedemail.com: domain of qiuxu.zhuo@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=qiuxu.zhuo@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703226472; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=HUZEApLLzcjVxzk3pgioryx1/9aUysaudpMOQ/HjEGU=; b=gAPGMO+1CMrlnBCitiv/CSS1TyhK/HGVacD6CbbJGSCVjG67wC64qCP7Eun3RgI3G7oVVL FPGK4WvwXTbvfec9azv9XcloFgJ/1scDkQQPwO7pAXgS/OBjO4KfI45eduP/B+0lxrSRVK ZqlDIJRTBhIxVBzDWp4g1skJxyTlIEA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=kiXTZefW; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf30.hostedemail.com: domain of qiuxu.zhuo@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=qiuxu.zhuo@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703226472; a=rsa-sha256; cv=none; b=4jc3uWlaK945IiiggrVnJtsopF9Xqj9RfchjZTgv9MirV0eyjsS5ESWH8sd+glr0XHRhSM mtYT6lddlofT24l9QKN/WS+/Mp7qbVgu4UjDnJCntTgBICI+UkClrQCB7GYbmn7jexKQM7 p9YmdQLdlBOsNJkHaB4XcqLs2cG9ZIc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703226471; x=1734762471; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=hJZ0EKv2QD33t/EPcdMXeHcn3tCCkT2bruiT8sdwzJI=; b=kiXTZefWMdIpkxjzqeF/zejrF6guBzcLJ8Y6H41Q9h+pG/8fnCDhzAXf Bb/4Q6qEwJoQCxb/JybmscwIM4DE0XsEQPX0Urq4RAqyFkR/ZQy1K+TDN ZJtVKdyzb83wCbkOGJiyZ+TSYnGKZ3WgAy+69xNDVUKDZ1/3IwCimbgz7 NBubIOYYmArOWejNwymwseZsO4v6Jk6rHDoAlr7dT4QQPPU0SrAXI8fff IEpUhqh6OceQXhestRbskvcxzoGa+rRSf06b9A541dA8YWdqM8P0MUMRx msB1/Ls6GRJhu5P26UWYliAbP7JkGCoOP116DdWDiY64aJbeqGhWbvv6U w==; X-IronPort-AV: E=McAfee;i="6600,9927,10931"; a="462520000" X-IronPort-AV: E=Sophos;i="6.04,294,1695711600"; d="scan'208";a="462520000" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2023 22:27:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10931"; a="847362650" X-IronPort-AV: E=Sophos;i="6.04,294,1695711600"; d="scan'208";a="847362650" Received: from qiuxu-clx.sh.intel.com ([10.239.53.109]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2023 22:27:45 -0800 From: Qiuxu Zhuo 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 Message-Id: <20231222062706.5221-1-qiuxu.zhuo@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231215081204.8802-1-qiuxu.zhuo@intel.com> References: <20231215081204.8802-1-qiuxu.zhuo@intel.com> X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: BCAA280002 X-Stat-Signature: xyfhmdp17g7jj1tdemd75h1c9so9uzkj X-HE-Tag: 1703226471-210556 X-HE-Meta: U2FsdGVkX1/utgUpxGm8Pc4MaW04gEYRtkgfb7nIMYG/gmk0fu7qJwxX3zq1leWYT/H8fB3Y3y6zSlzUg0sp24SP0bK63pVUQCz89OfTrCLeIRiFEpQ7AyugxQndS+MHPo3AtU5Q+CDwXK1EJVu8F2V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ulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 --- 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