From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-147.mta0.migadu.com [91.218.175.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0939C29B8E1 for ; Tue, 18 Aug 2026 13:50:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.147 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787061046; cv=none; b=sJwpdmgrIOc7mQHDd1rIpzbA5Sz6DLJ6GquDRSXjRprRWthnVz21CCXtH16Xe0MdG3GsGExEZDj4gF/q0v5wxuPUL3htBkglIGuOZtTvuMZgPFvGKhJX+i93XWV6jj+pMWRqyNIwQw6E4L3F6tvNut8g8HKgzDZA6ocqJM4AdGE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787061046; c=relaxed/simple; bh=5lteGfeaZGevr99SSHzPdRpl1YSem2xNMOC+8df4tBc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=o8JiM/piolUtN2TNiAkxJ18zuqnXKTYkiBuu3N5o8Yh3af6yFRd7uggE15vxWeyJrIbXGJyQxBqR5Z6l4oRW5rAO3UdiVW8LmJ4NlK2opK4bOGm/Py4epM/dHEFLTh1wMDkX02OK9jbfGKg+QkYxdzlMdwMUCGro/3xko3UevVQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=p+qNV7ME; arc=none smtp.client-ip=91.218.175.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="p+qNV7ME" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=5lteGfeaZGevr99SSHzPdRpl1YSem2xNMOC+8df4tBc=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787061042; v=1; x=1787665842; b=p+qNV7ME6nOGizR9xJQH+7rwtVDkFwLsA0WqPjYow0jxtTe9V4/pXXv5B3eo1ZUJAYxxhRGe FamWdx8CWkrO1jnwe7eJl35Zhdrih5ZDtgK/b5YniK1o4yqBSFp87x1I1OfQs/y6eXLxqaWnLRF K5Iln39XqGpLUaMV7mG+U728= X-Envelope-To: linux-kernel@vger.kernel.org Received: from .linux.dev (117.20.149.64) by smtp.migadu.com with ESMTPS id c8b153e7028ed696; Tue, 18 Aug 2026 13:50:41 +0000 X-Migadu-Flow: FLOW_OUT From: Leon Hwang To: linux-mm@kvack.org Cc: Muchun Song , Oscar Salvador , David Hildenbrand , Andrew Morton , linux-kernel@vger.kernel.org, Leon Hwang , Lance Yang Subject: [PATCH] hugetlb: add cond_resched() to __unmap_hugepage_range() Date: Tue, 18 Aug 2026 21:50:29 +0800 Message-ID: <20260818135029.93288-1-leon.hwang@linux.dev> X-Mailer: git-send-email 2.55.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Packet receive timeouts were traced to sparse HugeTLB unmapping in production. A task unmapping a sparse 2.5 TiB HugeTLB mapping could remain in kernel context for over 40 ms without reaching a scheduling point while walking empty huge PTEs. Although hard IRQs could still be handled, the per-CPU ksoftirqd thread and other runnable tasks could not run during that interval, delaying NET_RX softirq work queued to ksoftirqd. Add cond_resched() at the beginning of the hugepage loop so ksoftirqd and other runnable tasks can run between iterations. Testing with PREEMPT_NONE showed that the maximum interval between scheduling points fell from over 40 ms to below 2.5 ms. Total time spent in __unmap_hugepage_range() remained about 36 ms. Reported-by: Lance Yang Tested-by: Lance Yang Signed-off-by: Leon Hwang --- mm/hugetlb.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index dded1768193a..0a91aac2369f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5233,6 +5233,8 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma, last_addr_mask = hugetlb_mask_last_page(h); address = start; for (; address < end; address += sz) { + cond_resched(); + ptep = hugetlb_walk(vma, address, sz); if (!ptep) { address |= last_addr_mask; -- 2.55.0