From patchwork Fri Aug 25 13:54:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13365924 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 665E8C7EE2C for ; Fri, 25 Aug 2023 14:03:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 003692800D5; Fri, 25 Aug 2023 10:03:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF5F12800D0; Fri, 25 Aug 2023 10:03:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DBE002800D5; Fri, 25 Aug 2023 10:03:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CC89B2800D0 for ; Fri, 25 Aug 2023 10:03:37 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 98737B26B8 for ; Fri, 25 Aug 2023 14:03:37 +0000 (UTC) X-FDA: 81162794874.14.8FDDFEE Received: from out-246.mta1.migadu.com (out-246.mta1.migadu.com [95.215.58.246]) by imf17.hostedemail.com (Postfix) with ESMTP id 7EB2340018 for ; Fri, 25 Aug 2023 14:03:35 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ES2TiCn9; spf=pass (imf17.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.246 as permitted sender) smtp.mailfrom=hao.xu@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692972215; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=T6ViUZBPx7ad0ZahN3iXc6h6e/WwSaru8OskP5bAugQ=; b=5oPTzUg580bcdkOoL9lBWUIpASQAxaNsgFG7GKSjpm90XSKZJ0vjyjEbt5uixHcoN0nvXI yGwC9i61z9y5FQrUiDUjEtIeRKmzR88ZW3QBTQgfwmIrB/9td+MxYjIfJ28ooD2zjA9iG1 qK32iqS6PceLWShUE0XsmM80Xf9xw6Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692972215; a=rsa-sha256; cv=none; b=s6n5rA2e23MPZ7kGrMrDf6bI9hscI4lJ21qftJxmoyh/GZCeSern3W2+mZsgNfhK1rhpZW 9oahAVa7LK7n7+MZvC3f/lWwj+b+9026YnG7k7+oPu4/cGv2gdhjtN/LfQiP3rEa3pK4KD bUxHp36tbZWit7c3NyU0HSMThl15cqg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ES2TiCn9; spf=pass (imf17.hostedemail.com: domain of hao.xu@linux.dev designates 95.215.58.246 as permitted sender) smtp.mailfrom=hao.xu@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1692972214; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T6ViUZBPx7ad0ZahN3iXc6h6e/WwSaru8OskP5bAugQ=; b=ES2TiCn948OXPBoEBgWTcBO0RS4z23ivDrdXlTdAtaw6PThdxWDWOdUDMqwN5Zn7WD+dyR mB9Bpqj2y+SXbSPXBOj6qNtlf9PRruM/6AA9li5Lcnl6yPomOz6TlD4q7SN/nyqOvAgxMU ufKXd8FiPwyCFvbnzPL8RetLQf6iEEM= From: Hao Xu To: io-uring@vger.kernel.org, Jens Axboe Cc: Dominique Martinet , Pavel Begunkov , Christian Brauner , Alexander Viro , Stefan Roesch , Clay Harris , Dave Chinner , "Darrick J . Wong" , linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-cachefs@redhat.com, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-unionfs@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org, codalist@coda.cs.cmu.edu, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-mm@kvack.org, linux-nilfs@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-mtd@lists.infradead.org, Wanpeng Li Subject: [PATCH 20/29] xfs: distinguish error type of memory allocation failure for nowait case Date: Fri, 25 Aug 2023 21:54:22 +0800 Message-Id: <20230825135431.1317785-21-hao.xu@linux.dev> In-Reply-To: <20230825135431.1317785-1-hao.xu@linux.dev> References: <20230825135431.1317785-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: 4xb3u96to3cqwo7fpkjk4gu9ied6nr1e X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 7EB2340018 X-Rspam-User: X-HE-Tag: 1692972215-801269 X-HE-Meta: U2FsdGVkX1/U/jFMfPzeYGsXHYE+0re3L+FYNevdzT1gdGco4MQI5DpY3+VDIRXfBSchO93QlJgeyaFcbqVWcxJQ1h5hZvEp+5ZMNMPHMBMYxt4Lh3v2tDjhZvzM6cBWIlEDw+zDliqKIhLTgBehfEeVojrIb/2R8EA52Vf4j2XMfJfQNOi9KCKQSll63O9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ulk X-Loop: owner-majordomo@kvack.org List-ID: From: Hao Xu Previously, if we fail to get the memory we need, -ENOMEM is returned. It can be -EAGAIN now since we support nowait now. Return the latter when it is the case. Involved functions are: _xfs_buf_map_pages(), xfs_buf_get_maps(), xfs_buf_alloc_kmem() and xfs_buf_alloc_pages(). Signed-off-by: Hao Xu --- fs/xfs/xfs_buf.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index 8b800ce28996..a6e6e64ff940 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -192,7 +192,7 @@ xfs_buf_get_maps( bp->b_maps = kmem_zalloc(map_count * sizeof(struct xfs_buf_map), KM_NOFS); if (!bp->b_maps) - return -ENOMEM; + return bp->b_flags & XBF_NOWAIT ? -EAGAIN : -ENOMEM; return 0; } @@ -339,7 +339,7 @@ xfs_buf_alloc_kmem( bp->b_addr = kmem_alloc(size, kmflag_mask); if (!bp->b_addr) - return -ENOMEM; + return flags & XBF_NOWAIT ? -EAGAIN : -ENOMEM; if (((unsigned long)(bp->b_addr + size - 1) & PAGE_MASK) != ((unsigned long)bp->b_addr & PAGE_MASK)) { @@ -363,6 +363,7 @@ xfs_buf_alloc_pages( { gfp_t gfp_mask = __GFP_NOWARN; long filled = 0; + bool nowait = flags & XBF_NOWAIT; if (flags & XBF_READ_AHEAD) gfp_mask |= __GFP_NORETRY; @@ -377,7 +378,7 @@ xfs_buf_alloc_pages( bp->b_pages = kzalloc(sizeof(struct page *) * bp->b_page_count, gfp_mask); if (!bp->b_pages) - return -ENOMEM; + return nowait ? -EAGAIN : -ENOMEM; } bp->b_flags |= _XBF_PAGES; @@ -451,7 +452,7 @@ _xfs_buf_map_pages( memalloc_nofs_restore(nofs_flag); if (!bp->b_addr) - return -ENOMEM; + return flags & XBF_NOWAIT ? -EAGAIN : -ENOMEM; } return 0;