From patchwork Wed Apr 6 20:36:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 12804040 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 DDE1CC433EF for ; Wed, 6 Apr 2022 20:37:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 072056B0071; Wed, 6 Apr 2022 16:37:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 022A56B0073; Wed, 6 Apr 2022 16:37:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2BD76B0074; Wed, 6 Apr 2022 16:37:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0052.hostedemail.com [216.40.44.52]) by kanga.kvack.org (Postfix) with ESMTP id D2DDB6B0071 for ; Wed, 6 Apr 2022 16:37:02 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 96E368248D52 for ; Wed, 6 Apr 2022 20:36:52 +0000 (UTC) X-FDA: 79327613064.22.AE51EAF Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf13.hostedemail.com (Postfix) with ESMTP id 2DB6E20002 for ; Wed, 6 Apr 2022 20:36:51 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id h23-20020a17090a051700b001c9c1dd3acbso3972745pjh.3 for ; Wed, 06 Apr 2022 13:36:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DQvsUndMBXLZ9P0WFv493Kg/11ZIG/MRb7/8NJpzXMg=; b=x+1rB1Y4F2Mvt3/oR+trYBgal1IctnCC+eUGo1O5FY0oz+/9viJvJJdPbPeGd5W/4a DoxPo78gIxPxHQc8Szl4XtCBNJOKnvzKYywZ13Ru2nUKAdd/GNuF+1Tob9IZRwMmLvmw 1MMPT1k9WKgXEE0umUYUwNa+UZvRLCUW1qUo4pMCIi4b7+dhnterYDGL52EPeT6nVq5V 3hR7q+9Wkn1ceDEA58dvPrXJKUh8PlWg1y043lKQyOPylm61plp9oTCdqU04L/daZJPQ Mr+QoY0klUB+qXwCoL7sfZHA+mxeh+1e/zw/ThTG5lD07vnhGnnXvpTA9Ohbr8F8YGFA 1Zjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DQvsUndMBXLZ9P0WFv493Kg/11ZIG/MRb7/8NJpzXMg=; b=cpFYwjb2FNdOOIArcTk8ZalcHYBTynZmgv1tDpCAz4aKKdKnx6aD9IwIUN7QBG2NR0 Ek2YwVz/wv2ZMsusG00nNT03Mo1g9CnmRDZp6zfolKVctUKsIpMQRJpRpmInPIF0Ljqo MiIQhikL3TrZHmIJSfP9GXkp83XmyukqJI30avIcvDHahJ1yi6XYTH2/InuRnTHt7g8V kina/SuQ+aAaBVM2aEW4dsxzpiG1w0ct0xAOgXXVs8g+RMDik14QOLoK4CJYvM6PSXrQ a2Ps8rNz2rT9I+ee9W2VRonRGcX/vqBUBpEYJ8umAiK8aVKE5Rolfq+Ew1BFRk0a6uKk ZQhQ== X-Gm-Message-State: AOAM530LKOrKcm8Tji2wm5I4742TBqPqduYQUaCyGgsXKzXXXMbYowZd t2H41s8vwkSo4yN6SC2Fb6lkYN3AUCGkjQ== X-Google-Smtp-Source: ABdhPJyJaRphrkg76dgWpDDP6DYq+3AaQdm6IM8IPcFohSv3rFOyiYFXl+8wUafMAATojYv6u0iQsA== X-Received: by 2002:a17:902:e94f:b0:14f:1636:c8a8 with SMTP id b15-20020a170902e94f00b0014f1636c8a8mr10349760pll.130.1649277410507; Wed, 06 Apr 2022 13:36:50 -0700 (PDT) Received: from relinquished.tfbnw.net ([2620:10d:c090:400::5:4964]) by smtp.gmail.com with ESMTPSA id bv8-20020a056a00414800b004fafb37f293sm18353060pfb.209.2022.04.06.13.36.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 13:36:49 -0700 (PDT) From: Omar Sandoval To: linux-mm@kvack.org, kexec@lists.infradead.org, Andrew Morton Cc: Uladzislau Rezki , Christoph Hellwig , Baoquan He , x86@kernel.org, kernel-team@fb.com Subject: [PATCH v2] mm/vmalloc: fix spinning drain_vmap_work after reading from /proc/vmcore Date: Wed, 6 Apr 2022 13:36:36 -0700 Message-Id: <52f819991051f9b865e9ce25605509bfdbacadcd.1649277321.git.osandov@fb.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: iabcy93dgx1gq1iktnybnpydgc6i35rp Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=osandov-com.20210112.gappssmtp.com header.s=20210112 header.b=x+1rB1Y4; spf=none (imf13.hostedemail.com: domain of osandov@osandov.com has no SPF policy when checking 209.85.216.42) smtp.mailfrom=osandov@osandov.com; dmarc=none X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2DB6E20002 X-HE-Tag: 1649277411-57954 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Omar Sandoval Commit 3ee48b6af49c ("mm, x86: Saving vmcore with non-lazy freeing of vmas") introduced set_iounmap_nonlazy(), which sets vmap_lazy_nr to lazy_max_pages() + 1, ensuring that any future vunmaps() immediately purge the vmap areas instead of doing it lazily. Commit 690467c81b1a ("mm/vmalloc: Move draining areas out of caller context") moved the purging from the vunmap() caller to a worker thread. Unfortunately, set_iounmap_nonlazy() can cause the worker thread to spin (possibly forever). For example, consider the following scenario: 1. Thread reads from /proc/vmcore. This eventually calls __copy_oldmem_page() -> set_iounmap_nonlazy(), which sets vmap_lazy_nr to lazy_max_pages() + 1. 2. Then it calls free_vmap_area_noflush() (via iounmap()), which adds 2 pages (one page plus the guard page) to the purge list and vmap_lazy_nr. vmap_lazy_nr is now lazy_max_pages() + 3, so the drain_vmap_work is scheduled. 3. Thread returns from the kernel and is scheduled out. 4. Worker thread is scheduled in and calls drain_vmap_area_work(). It frees the 2 pages on the purge list. vmap_lazy_nr is now lazy_max_pages() + 1. 5. This is still over the threshold, so it tries to purge areas again, but doesn't find anything. 6. Repeat 5. If the system is running with only one CPU (which is typicial for kdump) and preemption is disabled, then this will never make forward progress: there aren't any more pages to purge, so it hangs. If there is more than one CPU or preemption is enabled, then the worker thread will spin forever in the background. (Note that if there were already pages to be purged at the time that set_iounmap_nonlazy() was called, this bug is avoided.) This can be reproduced with anything that reads from /proc/vmcore multiple times. E.g., vmcore-dmesg /proc/vmcore. It turns out that improvements to vmap() over the years have obsoleted the need for this "optimization". I benchmarked `dd if=/proc/vmcore of=/dev/null` with 4k and 1M read sizes on a system with a 32GB vmcore. The test was run on 5.17, 5.18-rc1 with a fix that avoided the hang, and 5.18-rc1 with set_iounmap_nonlazy() removed entirely: |5.17 |5.18+fix|5.18+removal 4k|40.86s| 40.09s| 26.73s 1M|24.47s| 23.98s| 21.84s The removal was the fastest (by a wide margin with 4k reads). This patch removes set_iounmap_nonlazy(). Signed-off-by: Omar Sandoval Reviewed-by: Christoph Hellwig Reviewed-by: Uladzislau Rezki (Sony) Acked-by: Chris Down --- Changes from v1: - Remove set_iounmap_nonlazy() entirely instead of fixing it. arch/x86/include/asm/io.h | 2 -- arch/x86/kernel/crash_dump_64.c | 1 - mm/vmalloc.c | 11 ----------- 3 files changed, 14 deletions(-) diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h index f6d91ecb8026..e9736af126b2 100644 --- a/arch/x86/include/asm/io.h +++ b/arch/x86/include/asm/io.h @@ -210,8 +210,6 @@ void __iomem *ioremap(resource_size_t offset, unsigned long size); extern void iounmap(volatile void __iomem *addr); #define iounmap iounmap -extern void set_iounmap_nonlazy(void); - #ifdef __KERNEL__ void memcpy_fromio(void *, const volatile void __iomem *, size_t); diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c index a7f617a3981d..97529552dd24 100644 --- a/arch/x86/kernel/crash_dump_64.c +++ b/arch/x86/kernel/crash_dump_64.c @@ -37,7 +37,6 @@ static ssize_t __copy_oldmem_page(unsigned long pfn, char *buf, size_t csize, } else memcpy(buf, vaddr + offset, csize); - set_iounmap_nonlazy(); iounmap((void __iomem *)vaddr); return csize; } diff --git a/mm/vmalloc.c b/mm/vmalloc.c index e163372d3967..0b17498a34f1 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1671,17 +1671,6 @@ static DEFINE_MUTEX(vmap_purge_lock); /* for per-CPU blocks */ static void purge_fragmented_blocks_allcpus(void); -#ifdef CONFIG_X86_64 -/* - * called before a call to iounmap() if the caller wants vm_area_struct's - * immediately freed. - */ -void set_iounmap_nonlazy(void) -{ - atomic_long_set(&vmap_lazy_nr, lazy_max_pages()+1); -} -#endif /* CONFIG_X86_64 */ - /* * Purges all lazily-freed vmap areas. */