Received: by 10.213.65.68 with SMTP id h4csp3437326imn; Tue, 3 Apr 2018 05:05:32 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/4fTa0Ptk1KWH873M9GUl4xFsXaLv23sGbZl+5Bx/RfwKInPv1iZzqxHmFDgvWvWtWvDTh X-Received: by 10.98.244.6 with SMTP id r6mr10261757pff.242.1522757132410; Tue, 03 Apr 2018 05:05:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522757132; cv=none; d=google.com; s=arc-20160816; b=c+VJ+BqkbXNhgcbUX9cbHnp+xWuNU0Rh7X/6IQUiyrsQZNw+KwG0X6LY4TBGM4nFLK 7DUBBpuf60Iy/P/uNzP0O/usx9atgTavAfLBexEr9ZC+YwOzFblg+KxJYD56DaG3ZmI4 qjIi+raY+ZoY6dBp8GhJ9QUpUUFzq4fE377k4v0aZDsfj8HDfLQORXz5B5pOWLmqPMN6 twkgDMwMVLMMSzVDFz4MxO44Bz9gL5yxuS5ZjtysmCAoMXoe2ANsTZWYQzXqhCS63MrM dM4cfNc69VSnP9i0RcrVsII+IyjK4yWkIvSpCCVbsioj7MzLeV+JUPDpSa/drLPoXpEE 4NWA== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=pI2U88AfiMkChrWHXosuKpxNlTGZcfoZHoZ3GjDu6FE=; b=u0CvOO+EqnWjh2gIXOVz7U7RjSosbuKpMzRKS4gL89xbrpPNYEUdwC4bUyCxjvupeT RiMJPZc0gVzD/4HDEyhXjgZaamgbW8bzFt5lpd4CgQEMtSuOTwSpU87hm0hg8ej1V2mp 4YkxTAFU0UQR1h0Oz9z2ZYEYeT70ZPA1PziiDdbWZlkV905XmtZ4grO3VR5PE6XqK9Du t1kS9lV4mKM634BFyim7MVUFzQaLQnB/vC/D0klGWGC6U4ZMB4F2G6AGshJo9cWG9531 JlnAE5YVAeRUIO/hr+pjs5FNsawOGdjSJrri9BM8O/rp+JqQAVfGoHXZy2EByt2Rzkmt yxrQ== 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 a86si2050652pfc.207.2018.04.03.05.05.17; Tue, 03 Apr 2018 05:05:32 -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 S1755509AbeDCMDf (ORCPT + 99 others); Tue, 3 Apr 2018 08:03:35 -0400 Received: from mx2.suse.de ([195.135.220.15]:33751 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755300AbeDCMDe (ORCPT ); Tue, 3 Apr 2018 08:03:34 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BA74DAF96; Tue, 3 Apr 2018 12:03:32 +0000 (UTC) Date: Tue, 3 Apr 2018 14:03:32 +0200 From: Michal Hocko To: Wang Long Cc: tj@kernel.org, hannes@cmpxchg.org, gthelen@google.com, akpm@osdl.org, linux-kernel@vger.kernel.org, Nicholas Piggin Subject: Re: [RFC] Is it correctly that the usage for spin_{lock|unlock}_irq in clear_page_dirty_for_io Message-ID: <20180403120312.GS5501@dhcp22.suse.cz> References: <157ed606-4a61-508b-d26a-2f5d638f39bb@meituan.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 02-04-18 19:50:50, Wang Long wrote: > > Hi,? Johannes Weiner and Tejun Heo > > I use linux-4.4.y to test the new cgroup controller io and the current > stable kernel linux-4.4.y has the follow logic > > > int clear_page_dirty_for_io(struct page *page){ > ... > ... > ??????????????? memcg = mem_cgroup_begin_page_stat(page); ----------(a) > ??????????????? wb = unlocked_inode_to_wb_begin(inode, &locked); ---------(b) > ??????????????? if (TestClearPageDirty(page)) { > ??????????????????????? mem_cgroup_dec_page_stat(memcg, MEM_CGROUP_STAT_DIRTY); > ??????????????????????? dec_zone_page_state(page, NR_FILE_DIRTY); > ??????????????????????? dec_wb_stat(wb, WB_RECLAIMABLE); > ??????????????????????? ret =1; > ??????????????? } > ??????????????? unlocked_inode_to_wb_end(inode, locked); -----------(c) > ??????????????? mem_cgroup_end_page_stat(memcg); -------------(d) > ??????????????? return ret; > ... > ... > } > > > when memcg is moving, and I_WB_SWITCH flags for inode is set. the logic > is the following: > > > spin_lock_irqsave(&memcg->move_lock, flags); -------------(a) > ??????? spin_lock_irq(&inode->i_mapping->tree_lock); ------------(b) > ??????? spin_unlock_irq(&inode->i_mapping->tree_lock); -----------(c) > spin_unlock_irqrestore(&memcg->move_lock, flags); -----------(d) > > > after (c) , the local irq is enabled. I think it is not correct. > > We get a deadlock backtrace after (c), the cpu get an softirq and in the > irq it also call mem_cgroup_begin_page_stat to lock the same > memcg->move_lock. > > Since the conditions are too harsh, this scenario is difficult to > reproduce.? But it really exists. > > So how about change (b) (c) to spin_lock_irqsave/spin_lock_irqrestore? Yes, it seems we really need this even for the current tree. Please note that At least clear_page_dirty_for_io doesn't lock memcg anymore. __cancel_dirty_page still uses lock_page_memcg though (former mem_cgroup_begin_page_stat). -- Michal Hocko SUSE Labs