From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8FA0C433FE for ; Tue, 8 Dec 2020 21:53:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 33B97206FC for ; Tue, 8 Dec 2020 21:53:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 33B97206FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 566276B0036; Tue, 8 Dec 2020 16:53:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F2196B005D; Tue, 8 Dec 2020 16:53:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B7A76B0068; Tue, 8 Dec 2020 16:53:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id 20A2F6B0036 for ; Tue, 8 Dec 2020 16:53:38 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 679653629 for ; Tue, 8 Dec 2020 21:53:37 +0000 (UTC) X-FDA: 77571467274.28.desk26_1f17d75273ea Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 34A0D6C06 for ; Tue, 8 Dec 2020 21:53:37 +0000 (UTC) X-HE-Tag: desk26_1f17d75273ea X-Filterd-Recvd-Size: 8608 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Dec 2020 21:53:36 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B8Itcot067615; Tue, 8 Dec 2020 19:04:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2020-01-29; bh=YE92bN7r4nI4cSyniMgLVv6+hx1QX2z+MpDPaN7/eIU=; b=ClUCLxncm7WWX1knajl/HpT8tSAwEE7h4lN71yIPmtVqU2GFOubR2FDxtRxJ9+OfbIK+ GsFKFR3jfdk7NTvzjkP6WANw84tGcxrchkCFjsMfVvl2i93oqYhZJMv4QcmfzBPK8rxs gPs6nhbulOHSH9RzhSD9QpSsgrBCnWaw8LT7zDTxX53VM3OK2MKFI10wZ6HFn8Zn7AVt NOkvOMCtVmVM2D1q32Z0Ad5HhbheGe0AOfvof+lyDSk/wqO0jtI3R/LfShY5tfl8YqmV 9vwhnQDIUQWoP7wFjHmaUnzLnrulP5evnKKdK9ei9tTzPxl3a3OnB2QoPbQdIhhqynlk rw== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 35825m4h13-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 08 Dec 2020 19:04:58 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0B8Ismhj150107; Tue, 8 Dec 2020 19:02:58 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 358ksp0d65-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 08 Dec 2020 19:02:58 +0000 Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0B8J2uWR021934; Tue, 8 Dec 2020 19:02:56 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 08 Dec 2020 11:02:56 -0800 Date: Tue, 8 Dec 2020 11:02:54 -0800 From: "Darrick J. Wong" To: Yafang Shao Cc: willy@infradead.org, david@fromorbit.com, hch@infradead.org, mhocko@kernel.org, akpm@linux-foundation.org, dhowells@redhat.com, jlayton@redhat.com, linux-fsdevel@vger.kernel.org, linux-cachefs@redhat.com, linux-xfs@vger.kernel.org, linux-mm@kvack.org, Christoph Hellwig Subject: Re: [PATCH v11 2/4] xfs: use memalloc_nofs_{save,restore} in xfs transaction Message-ID: <20201208190254.GE1943235@magnolia> References: <20201208122824.16118-1-laoar.shao@gmail.com> <20201208122824.16118-3-laoar.shao@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201208122824.16118-3-laoar.shao@gmail.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9829 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=5 bulkscore=0 malwarescore=0 phishscore=0 mlxscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012080115 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9829 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=5 adultscore=0 bulkscore=0 phishscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 mlxscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012080115 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: On Tue, Dec 08, 2020 at 08:28:22PM +0800, Yafang Shao wrote: > Introduce a new API to mark the start and end of XFS transactions. > For now, just save and restore the memalloc_nofs flags. > > The new helpers as follows, > - xfs_trans_context_set > Mark the start of XFS transactions > - xfs_trans_context_clear > Mark the end of XFS transactions > > Cc: Darrick J. Wong > Cc: Matthew Wilcox (Oracle) > Cc: Christoph Hellwig > Cc: Dave Chinner > Cc: Michal Hocko > Signed-off-by: Yafang Shao > --- > fs/xfs/xfs_aops.c | 4 ++-- > fs/xfs/xfs_linux.h | 4 ---- > fs/xfs/xfs_trans.c | 13 +++++++------ > fs/xfs/xfs_trans.h | 12 ++++++++++++ > 4 files changed, 21 insertions(+), 12 deletions(-) > > diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c > index 4304c6416fbb..2371187b7615 100644 > --- a/fs/xfs/xfs_aops.c > +++ b/fs/xfs/xfs_aops.c > @@ -62,7 +62,7 @@ xfs_setfilesize_trans_alloc( > * We hand off the transaction to the completion thread now, so > * clear the flag here. > */ > - current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); > + xfs_trans_context_clear(tp); > return 0; > } > > @@ -125,7 +125,7 @@ xfs_setfilesize_ioend( > * thus we need to mark ourselves as being in a transaction manually. > * Similarly for freeze protection. > */ > - current_set_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); > + xfs_trans_context_set(tp); > __sb_writers_acquired(VFS_I(ip)->i_sb, SB_FREEZE_FS); > > /* we abort the update if there was an IO error */ > diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h > index 5b7a1e201559..6ab0f8043c73 100644 > --- a/fs/xfs/xfs_linux.h > +++ b/fs/xfs/xfs_linux.h > @@ -102,10 +102,6 @@ typedef __u32 xfs_nlink_t; > #define xfs_cowb_secs xfs_params.cowb_timer.val > > #define current_cpu() (raw_smp_processor_id()) > -#define current_set_flags_nested(sp, f) \ > - (*(sp) = current->flags, current->flags |= (f)) > -#define current_restore_flags_nested(sp, f) \ > - (current->flags = ((current->flags & ~(f)) | (*(sp) & (f)))) > > #define NBBY 8 /* number of bits per byte */ > > diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c > index c94e71f741b6..11d390f0d3f2 100644 > --- a/fs/xfs/xfs_trans.c > +++ b/fs/xfs/xfs_trans.c > @@ -154,7 +154,7 @@ xfs_trans_reserve( > bool rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0; > > /* Mark this thread as being in a transaction */ > - current_set_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); > + xfs_trans_context_set(tp); > > /* > * Attempt to reserve the needed disk blocks by decrementing > @@ -164,7 +164,7 @@ 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); > + xfs_trans_context_clear(tp); > return -ENOSPC; > } > tp->t_blk_res += blocks; > @@ -241,7 +241,7 @@ xfs_trans_reserve( > tp->t_blk_res = 0; > } > > - current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); > + xfs_trans_context_clear(tp); > > return error; > } > @@ -878,7 +878,7 @@ __xfs_trans_commit( > > xfs_log_commit_cil(mp, tp, &commit_lsn, regrant); > > - current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); > + xfs_trans_context_clear(tp); > xfs_trans_free(tp); > > /* > @@ -910,7 +910,8 @@ __xfs_trans_commit( > xfs_log_ticket_ungrant(mp->m_log, tp->t_ticket); > tp->t_ticket = NULL; > } > - current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); > + > + xfs_trans_context_clear(tp); > xfs_trans_free_items(tp, !!error); > xfs_trans_free(tp); > > @@ -971,7 +972,7 @@ xfs_trans_cancel( > } > > /* mark this thread as no longer being in a transaction */ > - current_restore_flags_nested(&tp->t_pflags, PF_MEMALLOC_NOFS); > + xfs_trans_context_clear(tp); > > xfs_trans_free_items(tp, dirty); > xfs_trans_free(tp); > diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h > index 084658946cc8..44b11c64a15e 100644 > --- a/fs/xfs/xfs_trans.h > +++ b/fs/xfs/xfs_trans.h > @@ -268,4 +268,16 @@ xfs_trans_item_relog( > return lip->li_ops->iop_relog(lip, tp); > } > > +static inline void > +xfs_trans_context_set(struct xfs_trans *tp) > +{ > + tp->t_pflags = memalloc_nofs_save(); > +} > + > +static inline void > +xfs_trans_context_clear(struct xfs_trans *tp) > +{ > + memalloc_nofs_restore(tp->t_pflags); It's a little strange to add the wrappers and convert the current->flags modification macros to the memalloc_nofs_* functions in one patch, but whatever, I'm more concerned about the things I complained about in the next two patches. Reviewed-by: Darrick J. Wong --D > +} > + > #endif /* __XFS_TRANS_H__ */ > -- > 2.18.4 >