Received: by 10.213.65.68 with SMTP id h4csp2290920imn; Mon, 2 Apr 2018 05:00:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx493D/24sJ+AtHrl9WyBQuuXRwcRaiGLAF3De7uIJvDDi6eK/w5bql6o9uSrw8AP2nl14c+v X-Received: by 2002:a17:902:9a96:: with SMTP id w22-v6mr9489617plp.209.1522670456300; Mon, 02 Apr 2018 05:00:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522670456; cv=none; d=google.com; s=arc-20160816; b=xAs4aSc88lfzUiCFeFH0n/Z2T+DiRlWDUSaUbA9bVCKeO1kHhM4Rf5qKUvy491PoiO C8UKqQpgS3eaPw/QoF3cVlpcdiF5FCOff7ffRZPnEUGk2hNDA101e+eD8+ohBn51WKSn I7SELOg8aKVE3y/hdg3UEcaVHihr5HPzyUNY2eHPNc2pIyqVDdl7JzZisDwMogznUjTA qWG4Smwm/q0CIcSy4rEcccC9p1/stTIjAGHlBSllGPonQCuKhnpFkYntbzAd2e9O1Azv nVDLcrA4V1UrsgpVdo9cWXUxiXZclik5/3VqLSaLdE6tAoKnLnTsN2nCfG4roAVtx81j QhUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:cc:to:references:subject:dkim-signature:dkim-filter :arc-authentication-results; bh=NUjjnCpHJUBTXIPjuzyl54Rprgwtbl0tFTkOeGoDQpg=; b=KI/SJW9vWvhvvDHUirsm/Yr2Y7F3QGVCNRL2w8JtbuTNvZnn0h0wtUR8q9lWm+x79o LjzHjW80Cjeez2evT6kfu3KfesF9Z2FrCwlsjUoI+Iik9PS6lGE0xT6Ma1fFcONgTJ/H 5PLVfx/CdBoL3DN1liuAMhNYcNxDJFEURfinejyddlTkvBB2oO0pt09o6UeeefkE1V/l xSGt5OZx2Z9LHYEXYUKEcseD/Vw+zYJAJpwwiPXT5mAXWj/5ehN+5JWSFaGK3fRXFBd7 MGNh7qqYvXJLhTEsUtc6j9ikYLGuWr91P5UhgvCKorIFFw4KkDOP+cpi8xunOPEo/upr /bCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@meituan.com header.s=20130113 header.b=LVe3VFqA; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=meituan.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i35-v6si184257plg.504.2018.04.02.05.00.29; Mon, 02 Apr 2018 05:00:56 -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; dkim=pass header.i=@meituan.com header.s=20130113 header.b=LVe3VFqA; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=meituan.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751254AbeDBL6l (ORCPT + 99 others); Mon, 2 Apr 2018 07:58:41 -0400 Received: from mx-fe5-210.meituan.com ([103.37.138.210]:34964 "EHLO mx02.meituan.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750927AbeDBL6j (ORCPT ); Mon, 2 Apr 2018 07:58:39 -0400 X-Greylist: delayed 442 seconds by postgrey-1.27 at vger.kernel.org; Mon, 02 Apr 2018 07:58:38 EDT Received: from localhost (localhost [127.0.0.1]) by dx-it-mx02.dx.sankuai.com (Postfix) with ESMTP id B7998297608D; Mon, 2 Apr 2018 19:51:07 +0800 (CST) Received: from mx02.meituan.com ([127.0.0.1]) by localhost (dx-it-mx02.dx.sankuai.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Rhi3_B82_PdI; Mon, 2 Apr 2018 19:51:07 +0800 (CST) Received: from localhost (localhost [127.0.0.1]) by dx-it-mx02.dx.sankuai.com (Postfix) with ESMTP id 90B052976048; Mon, 2 Apr 2018 19:51:05 +0800 (CST) DKIM-Filter: OpenDKIM Filter v2.9.2 dx-it-mx02.dx.sankuai.com 90B052976048 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meituan.com; s=20130113; t=1522669867; bh=NUjjnCpHJUBTXIPjuzyl54Rprgwtbl0tFTkOeGoDQpg=; h=Subject:To:From:Message-ID:Date:MIME-Version:Content-Type: Content-Transfer-Encoding; b=LVe3VFqA0CgCYpdMupGjHClY73o7pInLNGXGvW3vIJGwU3i93pDHS8bjn7muQ+e5T 1opKO0WhsoxHudFuX4l4ZIbREija7L+9RGzDVjLubZMJAdeMTyZ3Sq2C6PunH6gGkq e4jsRyFes1j4Ks3WZpBL/AHXQvNLoi/69JaeyPq0= X-Virus-Scanned: amavisd-new at dx-it-mx02.dx.sankuai.com Received: from mx02.meituan.com ([127.0.0.1]) by localhost (dx-it-mx02.dx.sankuai.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id NR8Et69Ld8o6; Mon, 2 Apr 2018 19:51:05 +0800 (CST) Received: from wanglongs-MacBook-Pro.local (unknown [103.37.140.18]) by dx-it-mx02.dx.sankuai.com (Postfix) with ESMTPSA id 3F06B2976054; Mon, 2 Apr 2018 19:50:50 +0800 (CST) Subject: [RFC] Is it correctly that the usage for spin_{lock|unlock}_irq in clear_page_dirty_for_io References: <157ed606-4a61-508b-d26a-2f5d638f39bb@meituan.com> To: tj@kernel.org, hannes@cmpxchg.org Cc: gthelen@google.com, npiggin@suse.de, akpm@osdl.org, linux-kernel@vger.kernel.org, wanglong19@meituan.com From: Wang Long X-Forwarded-Message-Id: <157ed606-4a61-508b-d26a-2f5d638f39bb@meituan.com> Message-ID: Date: Mon, 2 Apr 2018 19:50:50 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <157ed606-4a61-508b-d26a-2f5d638f39bb@meituan.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi,=C2=A0 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){ ... ... =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 memcg =3D mem_cgroup_begin_page_stat(page); ----------= (a) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 wb =3D unlocked_inode_to_wb_begin(inode, &locked); ---= ------(b) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 if (TestClearPageDirty(page)) { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 mem_cg= roup_dec_page_stat(memcg, MEM_CGROUP_STAT_DIRTY); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 dec_zo= ne_page_state(page, NR_FILE_DIRTY); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 dec_wb= _stat(wb, WB_RECLAIMABLE); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D= 1; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 } =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 unlocked_inode_to_wb_end(inode, locked); -----------(c= ) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 mem_cgroup_end_page_stat(memcg); -------------(d) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 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) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 spin_lock_irq(&inode->i_mappi= ng->tree_lock); ------------(b) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 spin_unlock_irq(&inode->i_map= ping->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.=C2=A0 But it really exists. So how about change (b) (c) to spin_lock_irqsave/spin_lock_irqrestore? Thanks:-)