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=-2.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no 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 1B09DC4361B for ; Sat, 19 Dec 2020 00:32:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BE18E23B99 for ; Sat, 19 Dec 2020 00:32:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BE18E23B99 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 3BB2C6B005C; Fri, 18 Dec 2020 19:32:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 342C16B005D; Fri, 18 Dec 2020 19:32:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BCA96B0068; Fri, 18 Dec 2020 19:32:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id F3ACA6B005C for ; Fri, 18 Dec 2020 19:32:35 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B85554DBC for ; Sat, 19 Dec 2020 00:32:35 +0000 (UTC) X-FDA: 77608155870.30.heart81_2907ecf27441 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 95B8D180D511F for ; Sat, 19 Dec 2020 00:32:35 +0000 (UTC) X-HE-Tag: heart81_2907ecf27441 X-Filterd-Recvd-Size: 6249 Received: from mail-il1-f180.google.com (mail-il1-f180.google.com [209.85.166.180]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Sat, 19 Dec 2020 00:32:35 +0000 (UTC) Received: by mail-il1-f180.google.com with SMTP id p5so3803706iln.8 for ; Fri, 18 Dec 2020 16:32:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=JitJkpTV7wl8VuDaQVYn0aa0uVhFO5sQBwVgoYVnyaU=; b=EoIrf+fAqP4bq73P7dx0uRYKhuSFnNrbh1V1wdoor8DAFaSGqhsdhx5VxKiaHFoopi ETZEwHQqlM08+pYLmZDtwcuUADxnGmCc8OImoRyuGGrBOmL/66NQkQFJP6KHJTY38tkB TGA1GmYVNKUkfCU6I9Xt3/7/P4/QuqFBPCEos+g+Zsr8iZ3zyfQVKmNaaOl7kfhAaguT NYul5WXE/9m7GtPz8hR8w8rTaSA7zJn2zLPR9C48JOIcdpP2FdnsLPzvn6AIUPmM90dI itr43/LbBzmkAOjH2LLZh9CdOaeIYtCCV69Jk6DqooG4cb3+O3nuAUOJKVSjEm1o72YU Htwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=JitJkpTV7wl8VuDaQVYn0aa0uVhFO5sQBwVgoYVnyaU=; b=APe4CDXjWQoyhQR7jYKXBRprImBBFRsHYEIlTHpc6XFBlsB4Iva05Rf4jxACevJ47y NZzIOFNBOFYwLEywhcEAu9aM89fUZOn+qBbbBN41sGvYFkYgTq9Jfm/rJzxBQkSzLqwH ElDEfLi6iv3MvuN112NWOngGUHcRW30PaJhuz7IyeH0ugj4kBrT/ycc7K2dYqUchn1eQ 3sLubzBSnVBNXgYbXD3MdG7O6KstJaNNSmMv15283BxxN2auoe1RGo1LWRGDkrrLOlym Mqz8v/MhuOsbTJUBKnLqPg+qJtXIJsdOsa817MPlRaUxNUNRUZ6CJGevmffQj8mHknx5 rZmA== X-Gm-Message-State: AOAM532/qiEbKctCI5pORBbMfWPjj3zTQg8u3voclowcn/OQgDkLccfr FNNJ7QhRtyfyRyxvYdOtV5aU4PzFL9dXOk58ihQ= X-Google-Smtp-Source: ABdhPJzBhTlloThFSbngFUSOPAeYALZjLbpAe0za2X9hBcKTdxptneepWBoejNXqYFr1PxGnGFPWlotevXhOJRLtZRY= X-Received: by 2002:a05:6e02:c32:: with SMTP id q18mr6716194ilg.203.1608337954743; Fri, 18 Dec 2020 16:32:34 -0800 (PST) MIME-Version: 1.0 References: <20201217011157.92549-1-laoar.shao@gmail.com> <20201217011157.92549-4-laoar.shao@gmail.com> <20201217221509.GQ632069@dread.disaster.area> <20201217230627.GB6911@magnolia> <20201218000705.GR632069@dread.disaster.area> In-Reply-To: <20201218000705.GR632069@dread.disaster.area> From: Yafang Shao Date: Sat, 19 Dec 2020 08:31:58 +0800 Message-ID: Subject: Re: [PATCH v13 3/4] xfs: refactor the usage around xfs_trans_context_{set,clear} To: Dave Chinner Cc: "Darrick J. Wong" , Matthew Wilcox , Christoph Hellwig , Michal Hocko , Andrew Morton , David Howells , jlayton@redhat.com, linux-fsdevel@vger.kernel.org, linux-cachefs@redhat.com, linux-xfs@vger.kernel.org, Linux MM , Christoph Hellwig Content-Type: text/plain; charset="UTF-8" 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 Fri, Dec 18, 2020 at 8:07 AM Dave Chinner wrote: > > On Thu, Dec 17, 2020 at 03:06:27PM -0800, Darrick J. Wong wrote: > > On Fri, Dec 18, 2020 at 09:15:09AM +1100, Dave Chinner wrote: > > > The obvious solution: we've moved the saved process state to a > > > different context, so it is no longer needed for the current > > > transaction we are about to commit. So How about just clearing the > > > saved state from the original transaction when swappingi like so: > > > > > > static inline void > > > xfs_trans_context_swap(struct xfs_trans *tp, struct xfs_trans *ntp) > > > { > > > ntp->t_pflags = tp->t_pflags; > > > tp->t_flags = 0; > > > } > > > > > > And now, when we go to clear the transaction context, we can simply > > > do this: > > > > > > static inline void > > > xfs_trans_context_clear(struct xfs_trans *tp) > > > { > > > if (tp->t_pflags) > > > memalloc_nofs_restore(tp->t_pflags); > > > } > > > > > > and the problem is solved. The NOFS state will follow the active > > > transaction and not be reset until the entire transaction chain is > > > completed. > > > > Er... correct me if I'm wrong, but I thought t_pflags stores the old > > state of current->flags from before we call xfs_trans_alloc? So if we > > call into xfs_trans_alloc with current->flags==0 and we commit the > > transaction having not rolled, we won't unset the _NOFS state, and exit > > back to userspace with _NOFS set. > > Minor thinko. > > tp->t_pflags only stores a single bit of information w.r.t > PF_MEMALLOC_NOFS state, not the entire set of current task flags: > whether it should be cleared or not on a call to > memalloc_nofs_restore(). See memalloc_nofs_save(): > > static inline unsigned int memalloc_nofs_save(void) > { > unsigned int flags = current->flags & PF_MEMALLOC_NOFS; > current->flags |= PF_MEMALLOC_NOFS; > return flags; > } > > So, yeah, I got the t_pflags logic the wrong way around here - zero > means clear it, non-zero means don't clear it. IOWs, swap: > > ntp->t_pflags = tp->t_pflags; > tp->t_flags = -1; > > and clear: > > if (!tp->t_flags) > memalloc_nofs_restore(tp->t_pflags); > > This should only be temporary code, anyway. The next patch should > change this state clearing check to use current->journal_info, then > we aren't dependent on process flags state at all. > > > I think the logic is correct here -- we transfer the old pflags value > > from @tp to @ntp, which effectively puts @ntp in charge of restoring the > > old pflags value; and then we set tp->t_pflags to current->flags, which > > means that @tp will "restore" the current pflags value into pflags, which > > is a nop. > > That's pretty much what the current logic guarantees. Once the > wrappers provide this same guarantee, we can greatly simply the the > transaction context state management (i.e. set on alloc, swap on > dup, clear on free). And thread handoffs can just use clear/set > appropriately. > Make sense to me. -- Thanks Yafang