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, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,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 86199C3F2C6 for ; Tue, 3 Mar 2020 21:06:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 367AB20848 for ; Tue, 3 Mar 2020 21:06:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="CacSztLJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 367AB20848 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CC3E16B0005; Tue, 3 Mar 2020 16:06:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C4D846B0006; Tue, 3 Mar 2020 16:06:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3B956B0007; Tue, 3 Mar 2020 16:06:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0046.hostedemail.com [216.40.44.46]) by kanga.kvack.org (Postfix) with ESMTP id 989576B0005 for ; Tue, 3 Mar 2020 16:06:35 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E87BD8248D52 for ; Tue, 3 Mar 2020 21:06:34 +0000 (UTC) X-FDA: 76555284708.09.bear36_567e5c8c6bb31 X-HE-Tag: bear36_567e5c8c6bb31 X-Filterd-Recvd-Size: 7696 Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Tue, 3 Mar 2020 21:06:34 +0000 (UTC) Received: by mail-qt1-f196.google.com with SMTP id o10so4007400qtr.7 for ; Tue, 03 Mar 2020 13:06:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=hhsDW/6XZWZ5oKxK1xZ8fI60VjeufcRjR/rJHW+SvGs=; b=CacSztLJzNBx6cIkRVLKRwIN58rRf+RxCaZ/0f38BRwCjhxMI58Ts8FHjqIXwHoao2 KHA5IscehRg52ssLH1XxCeaN6AVhUFlsn0JQc5npwyO+G2Jz2stC1DI4KAmIKnQ7ub+F 7Qklaz1bWkj7AAirVzbLikiu43/zNpNlPMJ/IVBd+dTrJeGcwfcFrLGLF6cgWELxjpLH q3NPHz+mE90cztgtYJJ8YvIQmwmuBWKJtw4ws1X2kC2rO+jwsTkpwB2WVeuHpbqlO2a8 ptDB6G4WhDb3oHwoKd2fYIKj0x+Eas90jbdb+Vk97VPWIIBVwHYC9kmkrGm+RzWzFoeY xBGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=hhsDW/6XZWZ5oKxK1xZ8fI60VjeufcRjR/rJHW+SvGs=; b=Ye3f/LEZl0kOnGFzV0IwcQs+mE/nf3+px30XB3CYP3BeZGLSgnCx/f7Yhb0nAEso2K hXQDEqMn/e8PqVInT9/UujlhP1axLbPKMyDLgwRorXkcpjLgd6DHxoMXxc2TY5ULT1V3 n6dZtLPINhWqTtjHBE/cwCjKGwj0ZNDrjqzoqXhqlByC5N5N9CgBkFa7hKyfWYk67uWQ aFImTgWnXVw7onhxHrvgZc+hITcjNljda7BueXAqxjgGpCL6v/4/+vgpE+TWkepcl9HS 2LnNADIdZ4F8NJ7UjORVNc5v5u3sDBY/dvVVkgwgBad+8xc7MeaRNQqfD7SSdOTMI73c NLvg== X-Gm-Message-State: ANhLgQ1muvYwNRlgbspaCN8jHIyOu7lI5mDGwKL9pka9xVB0ibGhP/Qk f2ftRpkY8UiTuLj5GrnbjnXgJw== X-Google-Smtp-Source: ADFU+vs2MwlsuGRRGHU+djUgqUrCV/s+Xd84+zeHCokWSSNiNVXx1jPJZ/WD3k0TcmurUzZtSVHxgg== X-Received: by 2002:ac8:42c6:: with SMTP id g6mr6302191qtm.250.1583269593629; Tue, 03 Mar 2020 13:06:33 -0800 (PST) Received: from localhost ([2620:10d:c091:500::be1f]) by smtp.gmail.com with ESMTPSA id t6sm12774106qke.57.2020.03.03.13.06.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 13:06:32 -0800 (PST) Date: Tue, 3 Mar 2020 16:06:32 -0500 From: Johannes Weiner To: Shakeel Butt Cc: Yang Shi , Tetsuo Handa , Naresh Kamboju , linux-mm , Andrew Morton , Mel Gorman , Michal Hocko , Dan Schatzberg Subject: Re: fs/buffer.c: WARNING: alloc_page_buffers while mke2fs Message-ID: <20200303210632.GC68565@cmpxchg.org> References: <0a37bb7d-18a7-c43c-52a5-f13a34decf69@i-love.sakura.ne.jp> <20200303202623.GA68565@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 03, 2020 at 12:40:33PM -0800, Shakeel Butt wrote: > On Tue, Mar 3, 2020 at 12:26 PM Johannes Weiner wrote: > > From e0e5ace069af5a36e41eafe3bf21a67966127c04 Mon Sep 17 00:00:00 2001 > > From: Johannes Weiner > > Date: Tue, 3 Mar 2020 15:15:39 -0500 > > Subject: [PATCH] mm: support nesting memalloc_use_memcg() > > > > The memalloc_use_memcg() function to override the default memcg > > accounting context currently doesn't nest. But the patches to make the > > loop driver cgroup-aware will end up nesting: > > > > [ 98.137605] alloc_page_buffers+0x210/0x288 > > [ 98.141799] __getblk_gfp+0x1d4/0x400 > > [ 98.145475] ext4_read_block_bitmap_nowait+0x148/0xbc8 > > [ 98.150628] ext4_mb_init_cache+0x25c/0x9b0 > > [ 98.154821] ext4_mb_init_group+0x270/0x390 > > [ 98.159014] ext4_mb_good_group+0x264/0x270 > > [ 98.163208] ext4_mb_regular_allocator+0x480/0x798 > > [ 98.168011] ext4_mb_new_blocks+0x958/0x10f8 > > [ 98.172294] ext4_ext_map_blocks+0xec8/0x1618 > > [ 98.176660] ext4_map_blocks+0x1b8/0x8a0 > > [ 98.180592] ext4_writepages+0x830/0xf10 > > [ 98.184523] do_writepages+0xb4/0x198 > > [ 98.188195] __filemap_fdatawrite_range+0x170/0x1c8 > > [ 98.193086] filemap_write_and_wait_range+0x40/0xb0 > > [ 98.197974] ext4_punch_hole+0x4a4/0x660 > > [ 98.201907] ext4_fallocate+0x294/0x1190 > > [ 98.205839] loop_process_work+0x690/0x1100 > > [ 98.210032] loop_workfn+0x2c/0x110 > > [ 98.213529] process_one_work+0x3e0/0x648 > > [ 98.217546] worker_thread+0x70/0x670 > > [ 98.221217] kthread+0x1b8/0x1c0 > > [ 98.224452] ret_from_fork+0x10/0x18 > > > > where loop_process_work() sets the memcg override to the memcg that > > submitted the IO request, and alloc_page_buffers() sets the override > > to the memcg that instantiated the cache page, which may differ. > > > > Make memalloc_use_memcg() return the old memcg and convert existing > > users to a stacking model. Delete the unused memalloc_unuse_memcg(). > > > > Signed-off-by: Johannes Weiner > > Reviewed-by: Shakeel Butt Thanks Shakeel > > @@ -316,31 +316,26 @@ static inline void memalloc_nocma_restore(unsigned int flags) > > * __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; > > -} > > - > > -/** > > - * memalloc_unuse_memcg - Ends the remote memcg charging scope. > > + * NOTE: This function can nest. Users must save the return value and > > + * reset the previous value after their own charging scope is over: > > Should we mention that this is still not irq safe? At the moment other > than skmem we don't do memcg charging in the interrupt and skmem has a > memcg already associated with it. Maybe in future there might be a > case where we want a specific memcg be charged for kmem in the > interrupt context. Until then we can mark that this function should > not be used in interrupt. Is it actually unsafe? It's not an RMW operation, being interrupted doesn't corrupt its state. I.e. this is safe: process: interrupt: old = current->active_memcg old = current->active_memcg current->active_memcg = new allocate current->active_memcg = old current->active_memcg = new return old This is safe as well: process: interrupt: old = current->active_memcg current->active_memcg = new old = current->active_memcg current->active_memcg = new allocate current->active_memcg = old return old