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: 13365911 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2575EC71133 for ; Fri, 25 Aug 2023 14:03:43 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qZXPa-0004wh-BR; Fri, 25 Aug 2023 14:03:42 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qZXPY-0004wb-Qv for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 14:03:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=T6ViUZBPx7ad0ZahN3iXc6h6e/WwSaru8OskP5bAugQ=; b=XDpXzr5v8+yc8ZGQp5Im4B6W91 f0nGvHB4Wdl/mJhAd35lu9t/ARRP6wP8qNLECGy+SfTBeNHSn0pROynuDt21hgm6zk7ahCMvGGTHx ccMwxjTrQIum0we+SrrhNy8Q7w8Papf3JfVeQSUXxZJJbv3NJEU8n+/jWiwXoGCgQKR4=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=T6ViUZBPx7ad0ZahN3iXc6h6e/WwSaru8OskP5bAugQ=; b=GvYbfQ6dsrbuvY4WrQq0c2QfXU xNVbq3GFGi88NzquVlADKMoq8wGLhr35zCtQl44hDK3Bi2Z/a5wCHVdW8YUm5ODmcgneZ1DXDLWRs B+9bEz16sBH4EWGKsCpap+zQx8wEdt15a/0GKxFhFgbskHX1Yfj3vHNsHwLMpTenvIpU=; Received: from out-243.mta1.migadu.com ([95.215.58.243]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1qZXPY-0007gI-GW for linux-f2fs-devel@lists.sourceforge.net; Fri, 25 Aug 2023 14:03:41 +0000 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 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-Headers-End: 1qZXPY-0007gI-GW Subject: [f2fs-dev] [PATCH 20/29] xfs: distinguish error type of memory allocation failure for nowait case X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wanpeng Li , "Darrick J . Wong" , Dominique Martinet , Dave Chinner , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Stefan Roesch , Clay Harris , linux-s390@vger.kernel.org, linux-nilfs@vger.kernel.org, codalist@coda.cs.cmu.edu, cluster-devel@redhat.com, linux-cachefs@redhat.com, linux-ext4@vger.kernel.org, devel@lists.orangefs.org, linux-cifs@vger.kernel.org, ecryptfs@vger.kernel.org, linux-nfs@vger.kernel.org, linux-block@vger.kernel.org, Alexander Viro , Christian Brauner , netdev@vger.kernel.org, samba-technical@lists.samba.org, linux-unionfs@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mtd@lists.infradead.org, bpf@vger.kernel.org, Pavel Begunkov , linux-btrfs@vger.kernel.org Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net 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;