From patchwork Fri Apr 26 11:29:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13644645 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 F03B4C4345F for ; Fri, 26 Apr 2024 11:04:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4AA6D6B0082; Fri, 26 Apr 2024 07:04:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45A066B0083; Fri, 26 Apr 2024 07:04:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34A576B0087; Fri, 26 Apr 2024 07:04:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1D0E46B0082 for ; Fri, 26 Apr 2024 07:04:02 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D04B64086B for ; Fri, 26 Apr 2024 11:04:01 +0000 (UTC) X-FDA: 82051398282.26.66C5172 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf28.hostedemail.com (Postfix) with ESMTP id D412DC001C for ; Fri, 26 Apr 2024 11:03:58 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714129439; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=s5CoyeSj4xjd8f5jkamu1bukrK61/8EoYfalhmtIr9o=; b=T7pINfg+oHngrs8JxWgN0jDyXzPOrgN1FTWQy/CdDSm5vc7Ix51u7fQP5qqIKzQqdCSaNZ 9GKAY/01donkKnrqL5bZFsWXFw5jEdgHEo3vLb3hpz0KC+iITd9icy+EHUzO7HWU+DJ2tw 228VEUuYsp0Oj7nwWIgQWUDrDvwHPlE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714129439; a=rsa-sha256; cv=none; b=WOgwrw6NDS0TiikKe3xMPTVrGJegmNfVwvcLMCMSxi2UYVl54keJEKka2uYzSWPqPB0kRb Knaz7byyrQoNfPMKRs7O8yrX1Hi/EQ2/ibwRHwFqz4ycsmI52GvhA96QSaIBcE2zEj1bPx sxaygfDBsgwG+JPzICIQ2jzeBjPvcQ8= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VQqX150ZMzvPrN; Fri, 26 Apr 2024 19:00:49 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 085E418005C; Fri, 26 Apr 2024 19:03:54 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Fri, 26 Apr 2024 19:03:53 +0800 From: Kefeng Wang To: Andrew Morton CC: "Matthew Wilcox (Oracle)" , , , Kefeng Wang , zhangyi Subject: [PATCH] mm: use memalloc_nofs_save() in page_cache_ra_order() Date: Fri, 26 Apr 2024 19:29:38 +0800 Message-ID: <20240426112938.124740-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D412DC001C X-Rspam-User: X-Stat-Signature: 3jpj5emxji4yek6hcfe47jgjeakmoeyj X-HE-Tag: 1714129438-81597 X-HE-Meta: U2FsdGVkX18/Jy3deh0e9jrDt1D66eKetM/EeFbzZ26m30+RzRG3DXwtdN/TweiVr4D3anDLL5ZXEeupF5VpDhmaUW3Wvd1fJEnDQJn1sQZDjGdtUv7qNPzuO0NcXPQH2omKhQ+rcadHYKHMmYMZJFuE0M6QT+lTjvP3ly94dE6gB91K1lJNrGcfGwDMMDWQk+pVnFwKgUNLru/vv/8pNk6b8m1HDbnaLKuLE/VbqJQBJw5EC43n3WqjIqVL4UpYA7WgXKddkFXnyRa+iqxUby2k6AYAYj8gq31CBu4Z1GzBINMgTjoIFOgTdTA0xUMz51AKvCpGHdNUEDR4S98cAfQNc8P7TJHz0aPBKm3/ctbYL8VNADMAsBvKDj6X4U4R11o02i0HqltRT/Bb/5Xwwq2ffR7IVWWexhrNlGEXbM+Q0pBzZ50NUSnRd9F+3zB+aoihOkJvP0HxKfHLco2cN8fUWY2h/fKIYxhsPBdI11i7qBMXf4boM/nZv6YHPLYBGDike4apho+SXip2MAlkLxW+FuxI4TaxbZBZUBpWH4ykxl/m3cQLtFNgc0xjshVaNpIvqMcKb9Ot6igPY3v0icIGIegVOIma78Qu7gyXDAas2NTF7wYy6TKVQ24uyOWoSElKF0+XtFrVm/G+UKE/DHXTYxkdLzAVNFj6yYE77Zl7bzCH2hOM0wIoilqgQNB/CJNCa4ahur9p1K1hIHuTDdscyKm0JpfZ+6c0Vg7yBOHZh1XI2hpsglyAhu8Vsxm7rljYJp0cqCc6gyI4MA+mwpkcP7GbXrUpmR4FoTJYhRknSnavwkSz4VMwuaKCtVMMxlsytYX76E+hYcBXeudOz+PjoDokJr5ypClxYCD8UDydYwULAPseZyhmYAUPa1Qe1/LEVJFnlMcSEYCnqolM2rnlMgaokn/w7jY73GMENhlOZk+PGKfVQHLIVYRwx0GplqdA9/gkjzUz/kTIoDu 1tV1DFVF GuHHRjopYEtI0Jtx118c7MERHRPPXayB3TAqMMr6olbqZRc0a62jYiHPU8DONvW+q6G3tzQ6tHcLtHEHQOd7F/06W4Dv3ABopGAnjbm8aSxpxUon7QRlsYr+ENCPsokZW3EVp7qifG0TfwDXiuN8cgUcyeHN5eQqoGKx1PmzjdgskpMC53wyECauKOijM59q6SQV6 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: List-Subscribe: List-Unsubscribe: See commit f2c817bed58d ("mm: use memalloc_nofs_save in readahead path"), ensure that page_cache_ra_order() do not attempt to reclaim file-backed pages too, or it leads to a deadlock, found issue when test ext4 large folio. INFO: task DataXceiver for:7494 blocked for more than 120 seconds. "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. task:DataXceiver for state:D stack:0 pid:7494 ppid:1 flags:0x00000200 Call trace: __switch_to+0x14c/0x240 __schedule+0x82c/0xdd0 schedule+0x58/0xf0 io_schedule+0x24/0xa0 __folio_lock+0x130/0x300 migrate_pages_batch+0x378/0x918 migrate_pages+0x350/0x700 compact_zone+0x63c/0xb38 compact_zone_order+0xc0/0x118 try_to_compact_pages+0xb0/0x280 __alloc_pages_direct_compact+0x98/0x248 __alloc_pages+0x510/0x1110 alloc_pages+0x9c/0x130 folio_alloc+0x20/0x78 filemap_alloc_folio+0x8c/0x1b0 page_cache_ra_order+0x174/0x308 ondemand_readahead+0x1c8/0x2b8 page_cache_async_ra+0x68/0xb8 filemap_readahead.isra.0+0x64/0xa8 filemap_get_pages+0x3fc/0x5b0 filemap_splice_read+0xf4/0x280 ext4_file_splice_read+0x2c/0x48 [ext4] vfs_splice_read.part.0+0xa8/0x118 splice_direct_to_actor+0xbc/0x288 do_splice_direct+0x9c/0x108 do_sendfile+0x328/0x468 __arm64_sys_sendfile64+0x8c/0x148 invoke_syscall+0x4c/0x118 el0_svc_common.constprop.0+0xc8/0xf0 do_el0_svc+0x24/0x38 el0_svc+0x4c/0x1f8 el0t_64_sync_handler+0xc0/0xc8 el0t_64_sync+0x188/0x190 Cc: zhangyi (F) Signed-off-by: Kefeng Wang --- mm/readahead.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/readahead.c b/mm/readahead.c index 63d6000103f0..c1b23989d9ca 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -494,6 +494,7 @@ void page_cache_ra_order(struct readahead_control *ractl, pgoff_t index = readahead_index(ractl); pgoff_t limit = (i_size_read(mapping->host) - 1) >> PAGE_SHIFT; pgoff_t mark = index + ra->size - ra->async_size; + unsigned int nofs; int err = 0; gfp_t gfp = readahead_gfp_mask(mapping); @@ -508,6 +509,8 @@ void page_cache_ra_order(struct readahead_control *ractl, new_order = min_t(unsigned int, new_order, ilog2(ra->size)); } + /* See comment in page_cache_ra_unbounded() */ + nofs = memalloc_nofs_save(); filemap_invalidate_lock_shared(mapping); while (index <= limit) { unsigned int order = new_order; @@ -531,6 +534,7 @@ void page_cache_ra_order(struct readahead_control *ractl, read_pages(ractl); filemap_invalidate_unlock_shared(mapping); + memalloc_nofs_restore(nofs); /* * If there were already pages in the page cache, then we may have