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=-3.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 95C65C3F2C6 for ; Tue, 3 Mar 2020 20:59:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 477F120842 for ; Tue, 3 Mar 2020 20:59:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Bv/TIhuN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 477F120842 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 EC51A6B0005; Tue, 3 Mar 2020 15:59:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E75986B0007; Tue, 3 Mar 2020 15:59:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6C336B0005; Tue, 3 Mar 2020 15:59:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0113.hostedemail.com [216.40.44.113]) by kanga.kvack.org (Postfix) with ESMTP id BB5006B0005 for ; Tue, 3 Mar 2020 15:59:21 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2905718558 for ; Tue, 3 Mar 2020 20:59:21 +0000 (UTC) X-FDA: 76555266522.15.wish61_176ac46a98043 X-HE-Tag: wish61_176ac46a98043 X-Filterd-Recvd-Size: 6527 Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Tue, 3 Mar 2020 20:59:20 +0000 (UTC) Received: by mail-ed1-f68.google.com with SMTP id c62so6292749edf.0 for ; Tue, 03 Mar 2020 12:59:21 -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=GIH/XRtpKKShHSpTbhcTOzWc8bzrwSqVJlNZC+cefxQ=; b=Bv/TIhuNr63GA2YeY4GRraL7BGmTT/Fz/6YgckrJB0K/enWdVsKm2zaIrUBPaGA7oN LL9swUzy22K0dWMuzydhrgtDW2h/l+N8t14xa4Mp9lIhak0qqairTnH4Sh+uQlrZ+0EQ 5At+xM9b4bRl0L9qsVivJ3oR30ZpgDkr78Jq+fu7pF8Ehwech/SZsipWeWa9LWEb9ct7 A8UhRALfKk8bja+VxKZJPWCIdkyFdjhljuP8ZwOBtn0szQRs5b6YkS3TAJgtNAn025P1 U14Ilbjl5vJn+r27L6Mp9s57nPk4Z7pWVv+Iob5wRZ3tpT70KO0xrIZOeZkovAjcfwde KGlA== 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=GIH/XRtpKKShHSpTbhcTOzWc8bzrwSqVJlNZC+cefxQ=; b=RDop6cYSmJ/OcJsgf9MjfiH2+H6AdDNdsYKJNpkLi0YdMb61Bk5Qo5gnk7U/RPR4j/ wwx3pakf9pXkSIgZQawJIbLfMlJqVxs8sslsv3eLJFCXb7mN/cGBSYR6yaLXYKPAotD5 guUezKk5/rqfOxJ6eAZW7XwGkX27ir6CsD8HCJfdTSw9i855niwD+D3bVbMNQHNDFBkM dyNXr99hUEa2jqebwWxyT7Bcyu4LwFP5mjc+wJft0bqfYqNBIAKRq0leMnD8rhEmjcaT /OgciocRYfPclkhyClsrWpr7J2J/3fQw+gNX/LjiPtBpuLLm6vrx9HyNvlpOZi9Crhv/ cl+g== X-Gm-Message-State: ANhLgQ10gZ15nRzZruGjBLNOw35+CAu8xmwQnHc7GUulOGmTdto08zV+ dVG639CKDZdsaqSc6v/tSGIOq339zq36CeAWgq8= X-Google-Smtp-Source: ADFU+vsW3D97I7CMqoz1GpPEUcxLFhK+5VOWI77yviSxlrmZ97egIAu2edLZFcE2KCSSsi69A+kKCnSO+DtXdUkoMww= X-Received: by 2002:a17:906:1cc2:: with SMTP id i2mr5915040ejh.283.1583269160032; Tue, 03 Mar 2020 12:59:20 -0800 (PST) MIME-Version: 1.0 References: <0a37bb7d-18a7-c43c-52a5-f13a34decf69@i-love.sakura.ne.jp> <20200303203311.GB68565@cmpxchg.org> In-Reply-To: <20200303203311.GB68565@cmpxchg.org> From: Yang Shi Date: Tue, 3 Mar 2020 12:59:03 -0800 Message-ID: Subject: Re: fs/buffer.c: WARNING: alloc_page_buffers while mke2fs To: Johannes Weiner Cc: Shakeel Butt , Tetsuo Handa , Naresh Kamboju , linux-mm , Andrew Morton , Mel Gorman , Michal Hocko , Dan Schatzberg 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 Tue, Mar 3, 2020 at 12:33 PM Johannes Weiner wrote: > > On Tue, Mar 03, 2020 at 11:42:31AM -0800, Yang Shi wrote: > > On Tue, Mar 3, 2020 at 10:15 AM Shakeel Butt wrote: > > > > > > On Tue, Mar 3, 2020 at 9:47 AM Yang Shi wrote: > > > > > > > > On Tue, Mar 3, 2020 at 2:53 AM Tetsuo Handa > > > > wrote: > > > > > > > > > > Hello, Naresh. > > > > > > > > > > > [ 98.003346] WARNING: CPU: 2 PID: 340 at > > > > > > include/linux/sched/mm.h:323 alloc_page_buffers+0x210/0x288 > > > > > > > > > > This is > > > > > > > > > > /** > > > > > * memalloc_use_memcg - Starts the remote memcg charging scope. > > > > > * @memcg: memcg to charge. > > > > > * > > > > > * This function marks the beginning of the remote memcg charging scope. All the > > > > > * __GFP_ACCOUNT allocations till the end of the scope will be charged to the > > > > > * given memcg. > > > > > * > > > > > * NOTE: This function is not nesting safe. > > > > > */ > > > > > static inline void memalloc_use_memcg(struct mem_cgroup *memcg) > > > > > { > > > > > WARN_ON_ONCE(current->active_memcg); > > > > > current->active_memcg = memcg; > > > > > } > > > > > > > > > > which is about memcg. Redirecting to linux-mm. > > > > > > > > Isn't this triggered by ("loop: use worker per cgroup instead of > > > > kworker") in linux-next, which converted loop driver to use worker per > > > > cgroup, so it may have multiple workers work at the mean time? > > > > > > > > So they may share the same "current", then it may cause kind of nested > > > > call to memalloc_use_memcg(). > > > > > > > > Could you please try the below debug patch? This is not the proper > > > > fix, but it may help us narrow down the problem. > > > > > > > > diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h > > > > index c49257a..1cc1cdc 100644 > > > > --- a/include/linux/sched/mm.h > > > > +++ b/include/linux/sched/mm.h > > > > @@ -320,6 +320,10 @@ static inline void > > > > memalloc_nocma_restore(unsigned int flags) > > > > */ > > > > static inline void memalloc_use_memcg(struct mem_cgroup *memcg) > > > > { > > > > + if ((current->flags & PF_KTHREAD) && > > > > + current->active_memcg) > > > > + return; > > > > + > > > > WARN_ON_ONCE(current->active_memcg); > > > > current->active_memcg = memcg; > > > > } > > > > > > > > > > Maybe it's time to make memalloc_use_memcg() nesting safe. > > > > Need handle the below case: > > > > CPU A CPU B > > memalloc_use_memcg > > memalloc_use_memcg > > memalloc_unuse_memcg > > memalloc_unuse_memcg > > > > > > They may manipulate the same task->active_memcg, so CPU B may still > > see wrong memcg, and the last call to memalloc_unuse_memcg() on CPU B > > may not restore active_memcg to NULL. And, some code depends on > > correct active_memcg. > > It's safe because it's only `current` updating a private pointer - > nobody is changing active_memcg of a different task. And a task cannot > run on more than one CPU simultaneously. Yes, you are correct.