From patchwork Sat Jul 2 15:43:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 12904037 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 A93C4C43334 for ; Sat, 2 Jul 2022 15:43:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3A16D6B0071; Sat, 2 Jul 2022 11:43:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 351606B0073; Sat, 2 Jul 2022 11:43:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23FD96B0074; Sat, 2 Jul 2022 11:43:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 15C3A6B0071 for ; Sat, 2 Jul 2022 11:43:36 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D618910AB for ; Sat, 2 Jul 2022 15:43:35 +0000 (UTC) X-FDA: 79642579590.19.0B29962 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf07.hostedemail.com (Postfix) with ESMTP id 5640240050 for ; Sat, 2 Jul 2022 15:43:35 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id q140so5040371pgq.6 for ; Sat, 02 Jul 2022 08:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:content-language:from :subject:to:cc:content-transfer-encoding; bh=6pcExMdaIoQ/5n/nafB5a6CGS2J/3aXjlpFz5616I1g=; b=HkZMn3ZKScjLpfW/TrLgyB54yn3To5iFLyJSmyiS0n5orMeQGPyqjaFRJKLNKqTkpS 3zFc004uEOhVzZJS9FtuPizdX1cGjm6brKw608wc1EbX9suF6pdfWdh3Kh7LU8SC8uFw OmCHEJSxoKL9JrghXryWM+xe6XVHRDfCYFyv+iiF1V3PoAwoeUMVTw7KvUBgrwOeTryb vAPXWlVNVSQx/CMOFwgONhFLKolF/ri51tgGH9u6VNA5yCYkzKkGWvNxmmjhKvq68KHi +zFTfnQ086GIO89uDn4ou6KXxQk9O7JdCcFKcb09sQv2d1P91OHYahj6YW5OM+DqIJdB TtbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:from:subject:to:cc:content-transfer-encoding; bh=6pcExMdaIoQ/5n/nafB5a6CGS2J/3aXjlpFz5616I1g=; b=dRVburDt7HyIRwkg9SVgjE7SJ5/gzFk5hMkt5jRBZFBeYPP9Y7orI7xGd9lUkhIlWe 2N3eUk3ujdWmHlTRAexEQYgKX6epv42LNNL0GpRUlQyVXuFzW2jwby7g+kRcVkE6+5vZ DI0UvKVhyD5goHw6a7tVt6kTvnoMABFfwJRVzoQN42nxy06fFKzcA2HbLdrle3/C7u+z fxIACAprLs04aschUWZ8VIBe0lBYtOMYLQ2zckZD3WvPAApcNhuY2uNll7Z0B8EMbrXt ee7yIaJaUi1xbr/3GgjXgTzXeeDIPfir7G8PFKyLqIyENVXIzFSFRnSURNhbfSrNcoth 0q2w== X-Gm-Message-State: AJIora+CCxaDUwE1bptnxRWmOqbXtLjglJf9Rkm7Y3rxbOo0iqLoCRJI dkJXF6GSujbR1XlT8pYSL+pang== X-Google-Smtp-Source: AGRyM1tT+2Py1UpWEkqxc+T0Jgoa7eR4Q65vfknk/3vG+NTk/ILup7mCpl8fnJN3pbm52WjCtVYnLg== X-Received: by 2002:a05:6a00:f0e:b0:528:1b63:c9be with SMTP id cr14-20020a056a000f0e00b005281b63c9bemr12734202pfb.61.1656776614048; Sat, 02 Jul 2022 08:43:34 -0700 (PDT) Received: from [192.168.1.100] ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id mr8-20020a17090b238800b001ef76dbae28sm1164557pjb.36.2022.07.02.08.43.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 02 Jul 2022 08:43:33 -0700 (PDT) Message-ID: Date: Sat, 2 Jul 2022 09:43:32 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Content-Language: en-US From: Jens Axboe Subject: [PATCH v2] mm: honor FGP_NOWAIT for page cache page allocation To: Matthew Wilcox , linux-mm@kvack.org, Shakeel Butt Cc: Stefan Roesch ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=HkZMn3ZK; spf=pass (imf07.hostedemail.com: domain of axboe@kernel.dk designates 209.85.215.173 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656776615; 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:dkim-signature; bh=6pcExMdaIoQ/5n/nafB5a6CGS2J/3aXjlpFz5616I1g=; b=QekoUDNOVdQdiLe7AQsQyoq8uGA/WigVqiPFl8/SvFiWVf+iNPMRR0Xk0JJUOHWn+EWcyZ NFUYC/QDUcJ68VNbIdlWle51xMAjkQw1nDKWO+4EK8xsl8+lkoRIQhKRyzskul16dKocwq thegDWo7+4vZZwkiRQCrMp76MAI6GLw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656776615; a=rsa-sha256; cv=none; b=f/K6jezXMCgcbaIwEkNHobAlzPplP2FUU6xvbmNieO0OOsUaIRZrgReOAXD1jQONiQJ5YY QXaHFKhkeGJ9180hw+sIq39PYoxStZgbi8DwlcHUSQcdheybzAlz3Z4SwgWYF3Hfe4gA+U 9qHkGkC5adGuQMGIbT3DzdAbuQF5SUM= X-Stat-Signature: 4kpecy4bmcofkf7tsyts1zj3zq6ksmnu X-Rspamd-Queue-Id: 5640240050 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel-dk.20210112.gappssmtp.com header.s=20210112 header.b=HkZMn3ZK; spf=pass (imf07.hostedemail.com: domain of axboe@kernel.dk designates 209.85.215.173 as permitted sender) smtp.mailfrom=axboe@kernel.dk; dmarc=none X-Rspamd-Server: rspam12 X-Rspam-User: X-HE-Tag: 1656776615-599999 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: If we're creating a page cache page with FGP_CREAT but FGP_NOWAIT is set, we should dial back the gfp flags to avoid frivolous blocking which is trivial to hit in low memory conditions: [ 10.117661] __schedule+0x8c/0x550 [ 10.118305] schedule+0x58/0xa0 [ 10.118897] schedule_timeout+0x30/0xdc [ 10.119610] __wait_for_common+0x88/0x114 [ 10.120348] wait_for_completion+0x1c/0x24 [ 10.121103] __flush_work.isra.0+0x16c/0x19c [ 10.121896] flush_work+0xc/0x14 [ 10.122496] __drain_all_pages+0x144/0x218 [ 10.123267] drain_all_pages+0x10/0x18 [ 10.123941] __alloc_pages+0x464/0x9e4 [ 10.124633] __folio_alloc+0x18/0x3c [ 10.125294] __filemap_get_folio+0x17c/0x204 [ 10.126084] iomap_write_begin+0xf8/0x428 [ 10.126829] iomap_file_buffered_write+0x144/0x24c [ 10.127710] xfs_file_buffered_write+0xe8/0x248 [ 10.128553] xfs_file_write_iter+0xa8/0x120 [ 10.129324] io_write+0x16c/0x38c [ 10.129940] io_issue_sqe+0x70/0x1cc [ 10.130617] io_queue_sqe+0x18/0xfc [ 10.131277] io_submit_sqes+0x5d4/0x600 [ 10.131946] __arm64_sys_io_uring_enter+0x224/0x600 [ 10.132752] invoke_syscall.constprop.0+0x70/0xc0 [ 10.133616] do_el0_svc+0xd0/0x118 [ 10.134238] el0_svc+0x78/0xa0 Clear IO, FS, and reclaim flags and mark the allocation as GFP_NOWAIT and add __GFP_NOWARN to avoid polluting dmesg with pointless allocations failures. A caller with FGP_NOWAIT must be expected to handle the resulting -EAGAIN return and retry from a suitable context without NOWAIT set. Signed-off-by: Jens Axboe Reviewed-by: Shakeel Butt --- V2: - Improve commit message - Add GFP_NOWAIT to allow kswapd wakeup mm/filemap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/filemap.c b/mm/filemap.c index ffdfbc8b0e3c..254931a6e3ed 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1988,6 +1988,10 @@ struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index, gfp |= __GFP_WRITE; if (fgp_flags & FGP_NOFS) gfp &= ~__GFP_FS; + if (fgp_flags & FGP_NOWAIT) { + gfp &= ~GFP_KERNEL; + gfp |= GFP_NOWAIT | __GFP_NOWARN; + } folio = filemap_alloc_folio(gfp, 0); if (!folio)