Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp382560ybe; Mon, 2 Sep 2019 03:12:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6EoUPlGH+2A18nWB9LSolxYmFnAC6pYlx6pn9dDJgY7foBsb480vTvIIHs3kDELLnL1I5 X-Received: by 2002:a17:90a:8981:: with SMTP id v1mr12188263pjn.136.1567419171252; Mon, 02 Sep 2019 03:12:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567419171; cv=none; d=google.com; s=arc-20160816; b=BHAVMBQ2AdQr8uaNHr+yo2ZZ48u400BT75peqw/CpZ477rVqIoio6LC2k3eIS3AyZ5 fuHk6OM5sgE216qXHBb3NiBK4NWKRkkXnNha/p3yG8RQBR8/miMSx0TfsTIbx+nsTmnc /Pr2qIsUTAop+KlLTcxosW6tvm5SfCXhhDORcG5KIrRzhhP8ZE2V7Lrrn2I73VI4gMqs eJZx0NzsdxeuZ7K53EVq6S6o81fGz/yFVvoDOZJ3kD9AbzGsh39GpaD3idZZ12NWHHQH KIbdoa680B/9BxcSqM+sQuc5eDtV3fLtwy5mCHuPLXES8vDMnWn910yXn8OHHreJicy8 8Y8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=FIg6uiWtPBwhoQ1t5Tu2bXjhKM5G69Sawqqe5VIRUTg=; b=gsFpwJl05XI8vEBwSyRxUE4ehBh/XAiv2fNS2yUJFEfFO0jkuP5OW3POJTkD5Oxn8n xHtSPgG8cjmY0kHVBLqx4yIf713JHNV3sZowbv5/TqhJDIFVnnKdMl7OTB9FXrX4HnkU 9mNLhlBn+08Jf7bInGiGXwJH2FExlU18IY/hIXYUNaeUo5+ggwOIqEGxWm3gyhW4JVKj hxHbv3zFT7gVwZxsdaUBlPJ9CADktxJxW6yxSIGMcHWvDLx1UC97IGm0z0CQL64WFIq5 4EufDCnt34OBVoNgnWj4uQoNuUZpc3s9D2VmzaDYzXgRGZcetg6x+r9ZQpNDy85Ue8e1 WjZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a190si10872287pge.4.2019.09.02.03.12.36; Mon, 02 Sep 2019 03:12:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730511AbfIBIiR (ORCPT + 99 others); Mon, 2 Sep 2019 04:38:17 -0400 Received: from mx2.suse.de ([195.135.220.15]:34852 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729408AbfIBIiR (ORCPT ); Mon, 2 Sep 2019 04:38:17 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id CD795B7A8; Mon, 2 Sep 2019 08:38:14 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 011111E406C; Mon, 2 Sep 2019 10:38:12 +0200 (CEST) Date: Mon, 2 Sep 2019 10:38:12 +0200 From: Jan Kara To: Tejun Heo Cc: Jan Kara , Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH block/for-next] writeback: add tracepoints for cgroup foreign writebacks Message-ID: <20190902083812.GA14207@quack2.suse.cz> References: <20190829224701.GX2263813@devbig004.ftw2.facebook.com> <20190830154023.GC25069@quack2.suse.cz> <20190830154921.GZ2263813@devbig004.ftw2.facebook.com> <20190830164211.GD25069@quack2.suse.cz> <20190830170903.GB2263813@devbig004.ftw2.facebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190830170903.GB2263813@devbig004.ftw2.facebook.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Tejun, On Fri 30-08-19 10:09:03, Tejun Heo wrote: > On Fri, Aug 30, 2019 at 06:42:11PM +0200, Jan Kara wrote: > > Well, but if you look at __set_page_dirty_nobuffers() it is careful. It > > does: > > > > struct address_space *mapping = page_mapping(page); > > > > if (!mapping) { > > bail > > } > > ... use mapping > > > > Exactly because page->mapping can become NULL under your hands if you don't > > hold page lock. So I think you either need something similar in your > > tracepoint or handle this in the caller. > > So, account_page_dirtied() is called from two places. > > __set_page_dirty() and __set_page_dirty_nobuffers(). The following is > from the latter. > > lock_page_memcg(page); > if (!TestSetPageDirty(page)) { > struct address_space *mapping = page_mapping(page); > ... > > if (!mapping) { > unlock_page_memcg(page); > return 1; > } > > xa_lock_irqsave(&mapping->i_pages, flags); > BUG_ON(page_mapping(page) != mapping); > WARN_ON_ONCE(!PagePrivate(page) && !PageUptodate(page)); > account_page_dirtied(page, mapping); > ... > > If I'm reading it right, it's saying that at this point if mapping > exists after setting page dirty, it must not change while locking > i_pages. Correct __set_page_dirty_nobuffers() is supposed to be called serialized with truncation either through page lock or other means. At least the comment says so and the code looks like that. > > __set_page_dirty_nobuffers() is more brief but seems to be making the > same assumption. I suppose you mean __set_page_dirty() here. > xa_lock_irqsave(&mapping->i_pages, flags); > if (page->mapping) { /* Race with truncate? */ > WARN_ON_ONCE(warn && !PageUptodate(page)); > account_page_dirtied(page, mapping); > __xa_set_mark(&mapping->i_pages, page_index(page), > PAGECACHE_TAG_DIRTY); > } > xa_unlock_irqrestore(&mapping->i_pages, flags); > > Both are clearly assuming that once i_pages is locked, mapping can't > change. So, inside account_page_dirtied(), mapping clearly can't > change. The TP in question - track_foreign_dirty - is invoked from > mem_cgroup_track_foreign_dirty() which is only called from > account_page_dirty(), so I'm failing to see how mapping would change > there. I'm not sure where we depend here on page->mapping not getting cleared. The point is even if page->mapping is getting cleared while we work on the page, we have 'mapping' stored locally so we just account everything against the original mapping. I've researched this a bit more and commit 2d6d7f982846 "mm: protect set_page_dirty() from ongoing truncation" introduced the idea that __set_page_dirty_nobuffers() should be only called synchronized with truncation. Now I know for a fact that this is not always the case (e.g. various RDMA drivers calling set_page_dirty() without a lock or any other protection against truncate) but let's consider this a bug in the caller of set_page_dirty(). So in the end I agree that you're fine with relying on page_mapping() not changing under you. Honza -- Jan Kara SUSE Labs, CR