From patchwork Sat Aug 1 15:46:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11696131 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 68EDF912 for ; Sat, 1 Aug 2020 15:47:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 35BF92071E for ; Sat, 1 Aug 2020 15:47:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pCTnwJf3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 35BF92071E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D5E4F8D0091; Sat, 1 Aug 2020 11:47:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D0CE98D0081; Sat, 1 Aug 2020 11:47:09 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFF988D0091; Sat, 1 Aug 2020 11:47:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0199.hostedemail.com [216.40.44.199]) by kanga.kvack.org (Postfix) with ESMTP id AB8F08D0081 for ; Sat, 1 Aug 2020 11:47:09 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6F1F43626 for ; Sat, 1 Aug 2020 15:47:09 +0000 (UTC) X-FDA: 77102428578.17.jar29_5205f2a26f8d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 36F84180D0181 for ; Sat, 1 Aug 2020 15:47:09 +0000 (UTC) X-Spam-Summary: 1,0,0,c52085822e456a6b,d41d8cd98f00b204,laoar.shao@gmail.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3353:3865:3868:3870:3872:4321:4605:5007:6261:6653:7576:8660:9413:9592:10004:11026:11473:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12679:12895:13069:13148:13230:13255:13311:13357:14096:14130:14181:14384:14394:14687:14721:21080:21444:21451:21627:21666:21939:21990:30054:30064:30069:30070,0,RBL:209.85.214.196:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100;04yrmg7xpenyku8xdbt3e8mk56iscyp99u1u59ut8i5wbkms13y5i4wkpeef8oi.oxwum76re4cxcwwpqr5whgebntnyxz6m8kq1pixo6n6j3jsdazobjwb6zr4mgxw.a-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: jar29_5205f2a26f8d X-Filterd-Recvd-Size: 4790 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Sat, 1 Aug 2020 15:47:08 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id r4so8088223pls.2 for ; Sat, 01 Aug 2020 08:47:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Mntg9taWes2IQ/63EyCAMBFQrt4r0EuOq++DeO6vhCU=; b=pCTnwJf3v3CtEPpkp/TmvlpTE5l3PmW5NUc45HZbvb18erR72HOH9vChUUZ3YypEyO pOEn+Y6kYFg12fDAXLjxmkkbrloT5baTLdylazRVuGcWyWbHNplhBTFGsHBS3CfSY+2K ZBbY7lcT6b3XDrGT6F4ErIzfUi1DslpZzJhhJT80tMKqGOFgZq3fHliRCoxY3j0MTrwH xaHWwOOL97SXN96TpJXkBVLs1QileWyBIrDM2KDZMp70zWezI8KETWo+zVKFUctCfd7M ZN07e0MHPDGZyxiugOuJhANAGjWuw5kdtYehMPA6KE05ot7lAQKCMW9zrb812vnxcSZF qKiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Mntg9taWes2IQ/63EyCAMBFQrt4r0EuOq++DeO6vhCU=; b=dy6fntXBJKt3zD+f8hYwBXI0ThADg7+fnhmpxfpyI/PzXQr3mHnlDUk+Tcp8wFfdd7 DsqCTuoJhvdc1Z34MxCU4xRdqJ+mqpi0V75cb11h4qZAFIJAkACbQeZdoxL4jFep33Dp UB1tU2M4itaekKW2iiqwFPADMsGpgpvwBb0gHR6wfcVXBxydvYbUmaePI7OacidTObjL Til9apTqn7P1OI10MuwJG0libDx9OVjNHEoE/uvNU2NYlpZkR4n7veJ/iNu8K+4umckn BJtJehuUVuTWxZxvDOu568GGLVkj+t8Nt6fjoX4uptO+OPMAI/UFc1CpJaRCsUZf8Z/y jXDw== X-Gm-Message-State: AOAM533XP9ofhsPdJcLg0EGky+llJU0/MnTzT3AA3oGvG2IXD7PNqtjt h0zLQ6PFcQ8iBcUlbUsrgD0mDqMxktc= X-Google-Smtp-Source: ABdhPJzMVdJHi1GV+1Q4tvZMc/xr8ImvgRh9hFVdynekX3JhUv9ic2u08w6+W3V3yISXmtC/v+MQDw== X-Received: by 2002:a17:902:8bc3:: with SMTP id r3mr8070864plo.112.1596296828074; Sat, 01 Aug 2020 08:47:08 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id j26sm13717331pfe.200.2020.08.01.08.47.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Aug 2020 08:47:07 -0700 (PDT) From: Yafang Shao To: david@fromorbit.com, hch@infradead.org, darrick.wong@oracle.com, mhocko@kernel.org, willy@infradead.org Cc: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Yafang Shao Subject: [PATCH v4 1/2] xfs: avoid double restore PF_MEMALLOC_NOFS if transaction reservation fails Date: Sat, 1 Aug 2020 11:46:31 -0400 Message-Id: <20200801154632.866356-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20200801154632.866356-1-laoar.shao@gmail.com> References: <20200801154632.866356-1-laoar.shao@gmail.com> X-Rspamd-Queue-Id: 36F84180D0181 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: Yafang Shao In xfs_trans_alloc(), if xfs_trans_reserve() fails, it will call xfs_trans_cancel(), in which it will restore the flag PF_MEMALLOC_NOFS. However this flags has been restored in xfs_trans_reserve(). Although this behavior doesn't introduce any obvious issue, we'd better improve it. Signed-off-by: Yafang Shao Cc: Dave Chinner Cc: Christoph Hellwig Cc: Michal Hocko Cc: Darrick J. Wong Cc: Matthew Wilcox Signed-off-by: Matthew Wilcox (Oracle) --- fs/xfs/xfs_trans.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index 3c94e5ff4316..9ff41970d0c7 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -162,10 +162,9 @@ xfs_trans_reserve( */ if (blocks > 0) { error = xfs_mod_fdblocks(mp, -((int64_t)blocks), rsvd); - if (error != 0) { - current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); + if (error != 0) return -ENOSPC; - } + tp->t_blk_res += blocks; } @@ -240,8 +239,6 @@ xfs_trans_reserve( tp->t_blk_res = 0; } - current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); - return error; } @@ -972,6 +969,7 @@ xfs_trans_roll( struct xfs_trans **tpp) { struct xfs_trans *trans = *tpp; + struct xfs_trans *tp; struct xfs_trans_res tres; int error; @@ -1005,5 +1003,10 @@ xfs_trans_roll( * the prior and the next transactions. */ tres.tr_logflags = XFS_TRANS_PERM_LOG_RES; - return xfs_trans_reserve(*tpp, &tres, 0, 0); + tp = *tpp; + error = xfs_trans_reserve(tp, &tres, 0, 0); + if (error) + current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); + + return error; }