Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5434925ybl; Tue, 27 Aug 2019 04:47:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyEIzOHtBnPcQdYDJGkYHIw5PufKJV3iQ3pIE50SECo//L3yLtHGW5sgbeu0D7zeaOeceKm X-Received: by 2002:a65:654d:: with SMTP id a13mr20577520pgw.196.1566906428424; Tue, 27 Aug 2019 04:47:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566906428; cv=none; d=google.com; s=arc-20160816; b=YyeG1yeTA6Y2MVTl59a9etgWSEglAl1ndP7IOdxM/sBLz4hRXKfMu+UX8U3tCclbRQ 9rlAcSiDu0yVP3En3q9YREyKNDFb9b6Wo3yOi/h5lJkrCdglsYjinLLlTlF2VGfJ95KI 9HI002BiHbQPkKINS155F2s3NxoTc88CZo/MIWhQN2uiOXJ5A+xDtERuVTUPFhK3sY4f MoPsBZxNDGBOcHPNyl/uLRxWs4YFcWtIGHS0aga8fXdv6qEidG9/u2lXBY6qYWLnRljJ oVRjO8pUMWZ2U7ky/jQmmNZuSoqBHoZBcBQRTfS+vTcSPfDZUpo3qT2+9lRK10+N4bQY D+3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=B6JKwNjAX9OFJ5Xpu3hN1K2seR+5vG6lZdDfWoSwR4Y=; b=X/vZu8O2q73+IFdIyKLo1Wy7nk2rU7bflL6fr4LTc35nWz217qOimPuHBMmH1J4SeA rqKh3LlyhIAJnhBLvUbw+iAkLzDluwi+llWr0AE2rEtPmTOXSKx/DA7qezzBVNfTVtZW cRdr0wiLcstWcFXn59jhPPkM95IOpXgeo6S9sb1GIkcAwFrX8oY654Yaccj0iRWpoeSF F6Q97Q1x/d+wnlKqqwxg6GH6Eb/3SeQwQcyn1weeji0OiPMNowhW+3tROnGdcRUs3BPG NWTIEH/Rm7B2Cb31BwpDhI/9IHt3YCOU5UPow8Q2EGm2BoMiQEjauVKksNBlnFti9hix OfBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=k0fxmZy5; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f7si11226966pgs.415.2019.08.27.04.46.53; Tue, 27 Aug 2019 04:47:08 -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=@gmail.com header.s=20161025 header.b=k0fxmZy5; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727910AbfH0Lo0 (ORCPT + 99 others); Tue, 27 Aug 2019 07:44:26 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:39979 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726537AbfH0Lo0 (ORCPT ); Tue, 27 Aug 2019 07:44:26 -0400 Received: by mail-io1-f67.google.com with SMTP id t6so45544562ios.7 for ; Tue, 27 Aug 2019 04:44:26 -0700 (PDT) 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=B6JKwNjAX9OFJ5Xpu3hN1K2seR+5vG6lZdDfWoSwR4Y=; b=k0fxmZy5mkRO2ooZzqehi9uB3sSTOy7DeHxXcX76sPz5P/kJMkE6dE/KO8756/7LFu LzwR+VnWhUMMBLuZIOIOaQPqqt8Dt2/ANod0nT4sL8th5LprN+dh8fGsh89uWp960+lM 7rjYfVHHjGi3yVT9YbaPA2DuFoYbh1ERUyFbLHE47q6uKgd8liYwqsEX9LdcH+jal+nB ajXw7FAJhUGoWC8BrTi6s/6AbFg2tBHUEd/mAVCCeqS8ZjOJgfSo9PMXyoL29h+3h/rA FdjkoZveFpVmVRok2wvo/sI5+M9WmjA/0+nYxuheAtFKAnVph2kVxMd04vwiVyKsvwwo hU7A== 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=B6JKwNjAX9OFJ5Xpu3hN1K2seR+5vG6lZdDfWoSwR4Y=; b=LMGEeg8DcnWWLuuGUU1D4FdkLA9FK/g9FaR5HymNTX3b/ggLZSMXLSoRcXYg60U3lJ SHBXaQxXKui2z7FSkp2toz0hcVkHd+IXH8j9ec8GyKC6wqnrpjqhstj5mvVdlqplkjlP SHxDhciLzZCzmTAaX7Lh9HQA0i8PLEV7damZcbUzfDHwT4mVTeEFKUu7Ik9LA1/bQR4U wU5Fv6dsL+ymEIHN6zafaXGp0qSqKXi6vFTN6YCxNfI13Lk4DdRDg3redn2+t62ZWKHh 4Y0JlZ0Ba0KUHC3Icg+a1HFvWj1PbSxsrzpVZ/FBRzy0UAt3kQp0ABLOuACyU3jwOfnM L3ZA== X-Gm-Message-State: APjAAAWiW59vm3P+5FqyouXvsAnwENMRZ9312ULmMMsj4p6YSfBrjl2+ J3j/NNLcavz67tMcnJYPHtKTy7V3J8dir8ZEs3jPjw== X-Received: by 2002:a6b:cac2:: with SMTP id a185mr17954858iog.142.1566906265777; Tue, 27 Aug 2019 04:44:25 -0700 (PDT) MIME-Version: 1.0 References: <20190826105521.GF7538@dhcp22.suse.cz> <20190827104313.GW7538@dhcp22.suse.cz> In-Reply-To: <20190827104313.GW7538@dhcp22.suse.cz> From: Yafang Shao Date: Tue, 27 Aug 2019 19:43:49 +0800 Message-ID: Subject: Re: WARNINGs in set_task_reclaim_state with memory cgroup and full memory usage To: Michal Hocko Cc: Yang Shi , Adric Blake , Andrew Morton , Kirill Tkhai , Johannes Weiner , Daniel Jordan , Mel Gorman , Linux MM , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 27, 2019 at 6:43 PM Michal Hocko wrote: > > If there are no objection to the patch I will post it as a standalong > one. I have no objection to your patch. It could fix the issue. I still think that it is not proper to use a new scan_control here as it breaks the global reclaim context. This context switch from global reclaim to memcg reclaim is very subtle change to the subsequent processing, that may cause some unexpected behavior. Anyway, we can send this patch as a standalong one. Feel free to add: Acked-by: Yafang Shao > > On Mon 26-08-19 12:55:21, Michal Hocko wrote: > > From 59d128214a62bf2d83c2a2a9cde887b4817275e7 Mon Sep 17 00:00:00 2001 > > From: Michal Hocko > > Date: Mon, 26 Aug 2019 12:43:15 +0200 > > Subject: [PATCH] mm, memcg: do not set reclaim_state on soft limit reclaim > > > > Adric Blake has noticed the following warning: > > [38491.963105] WARNING: CPU: 7 PID: 175 at mm/vmscan.c:245 set_task_reclaim_state+0x1e/0x40 > > [...] > > [38491.963239] Call Trace: > > [38491.963246] mem_cgroup_shrink_node+0x9b/0x1d0 > > [38491.963250] mem_cgroup_soft_limit_reclaim+0x10c/0x3a0 > > [38491.963254] balance_pgdat+0x276/0x540 > > [38491.963258] kswapd+0x200/0x3f0 > > [38491.963261] ? wait_woken+0x80/0x80 > > [38491.963265] kthread+0xfd/0x130 > > [38491.963267] ? balance_pgdat+0x540/0x540 > > [38491.963269] ? kthread_park+0x80/0x80 > > [38491.963273] ret_from_fork+0x35/0x40 > > [38491.963276] ---[ end trace 727343df67b2398a ]--- > > > > which tells us that soft limit reclaim is about to overwrite the > > reclaim_state configured up in the call chain (kswapd in this case but > > the direct reclaim is equally possible). This means that reclaim stats > > would get misleading once the soft reclaim returns and another reclaim > > is done. > > > > Fix the warning by dropping set_task_reclaim_state from the soft reclaim > > which is always called with reclaim_state set up. > > > > Reported-by: Adric Blake > > Signed-off-by: Michal Hocko > > --- > > mm/vmscan.c | 5 +++-- > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c > > index c77d1e3761a7..a6c5d0b28321 100644 > > --- a/mm/vmscan.c > > +++ b/mm/vmscan.c > > @@ -3220,6 +3220,7 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order, > > > > #ifdef CONFIG_MEMCG > > > > +/* Only used by soft limit reclaim. Do not reuse for anything else. */ > > unsigned long mem_cgroup_shrink_node(struct mem_cgroup *memcg, > > gfp_t gfp_mask, bool noswap, > > pg_data_t *pgdat, > > @@ -3235,7 +3236,8 @@ unsigned long mem_cgroup_shrink_node(struct mem_cgroup *memcg, > > }; > > unsigned long lru_pages; > > > > - set_task_reclaim_state(current, &sc.reclaim_state); > > + WARN_ON_ONCE(!current->reclaim_state); > > + > > sc.gfp_mask = (gfp_mask & GFP_RECLAIM_MASK) | > > (GFP_HIGHUSER_MOVABLE & ~GFP_RECLAIM_MASK); > > > > @@ -3253,7 +3255,6 @@ unsigned long mem_cgroup_shrink_node(struct mem_cgroup *memcg, > > > > trace_mm_vmscan_memcg_softlimit_reclaim_end(sc.nr_reclaimed); > > > > - set_task_reclaim_state(current, NULL); > > *nr_scanned = sc.nr_scanned; > > > > return sc.nr_reclaimed; > > -- > > 2.20.1 > > > > -- > > Michal Hocko > > SUSE Labs > > -- > Michal Hocko > SUSE Labs