Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4027358pxf; Tue, 16 Mar 2021 04:04:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsaRFpeI4BgsU7/D6KKdDnrUtckFPrv0lhfjGQELdjzT32yKTQDXWC3XqdGfumiLb67ruW X-Received: by 2002:a17:906:a049:: with SMTP id bg9mr29035450ejb.186.1615892690525; Tue, 16 Mar 2021 04:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615892690; cv=none; d=google.com; s=arc-20160816; b=ytqaOmmHfrnaBiCBqkhcYJSNcNMQbJm1p6z476tVpvtrZ8ebMqgfVBzwSKvKQQJaYf gQYeY0wB2aF46ml6KAB8UsrpPKptaorMb8gpJTO6Fvfg5zwZkJRRYH37CI3O+Uz7+z8K Eya2ZuID8xxkwtxDUY4VxwIuRHhwpuKKjK6rb5iW+m7A7O9Twi2W/Xd00enQ4as2YQgh WZGXpL+Z/yqlI6Mh5mvJ+P+dGqiMJ2OSAuUnSXHmA9ZK9zeOGBo2vFY9N/1RMu7hyxkQ oVoydfvuS03gRqcHu4ZavF4aGvcNhTU8Q6k1XHrvWcJdCos1pfTOrnyiTeFPyjtWVnJA HZ7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=sHh364PFI7gr7Rg7wpaysNQPtI9BiNpDxSsKea0W7pA=; b=yv3XwrPBk8Tqtoq1oToKRNNhnraE2MDMN3F2vulXvkxSSr0cRrkv+pgbusuefiA4T8 pcNGHxEQtDja/OMJlIu4weEmzqL+UEtFcs6DvdW0J2LY03+2bIS6u/RlqKP290XcI4/d oELpDIitW5oj5xIYAslo+1QzTH45NbD4JJKx9bSYnidFrvG1Ji6cc4knr0grfUJZ99Yd yadnH/2shtWGUdGgjX99BfhRmRfkh2TH0LvLhoiiJsVLlZs7F6cfn6zP4LlbqMLK7g8B BAbmVmEY0pmgK3N7AZB2GgZ1o3737CRdv948h90i46+VoLeVFB+HnoiBg2IImRjsv6/x Hp4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=KbheRMtg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s17si13851665edx.88.2021.03.16.04.04.24; Tue, 16 Mar 2021 04:04:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=KbheRMtg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229748AbhCOXl0 (ORCPT + 99 others); Mon, 15 Mar 2021 19:41:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232042AbhCOXlJ (ORCPT ); Mon, 15 Mar 2021 19:41:09 -0400 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9E62C06174A for ; Mon, 15 Mar 2021 16:41:01 -0700 (PDT) Received: by mail-qt1-x82b.google.com with SMTP id l13so10468912qtu.9 for ; Mon, 15 Mar 2021 16:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sHh364PFI7gr7Rg7wpaysNQPtI9BiNpDxSsKea0W7pA=; b=KbheRMtg2robQTyXPOEUrlWiONJ6e2isDPkgv9TYBs4HWXHrRdzR9F4j8VM+dTeX2M eabV8ybFsCDihGBWhwgMPDDTOX737BCr06IpzJThWzsqHtEJiT5yZZq3Z89KjreYoS2W 9GMEiDZw38HOxAu7Z1TuHEAcU6cUTzw/i3xPEKKtM4aJJtASYaaboQmNpTbWdtH+uOIs tAPWz2umjmR8R0K+EHsBDPmG35CNquRmgrNIM+onWovfmkuPW6eYCeH4T0Bg0KGQ1Jbo 2m7pNiKU76I12k+7IUBC77cbwWHyrwEwwo1g1QPp8LoL/FS4EHStaALOmG1cd3x7bIUn ms7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=sHh364PFI7gr7Rg7wpaysNQPtI9BiNpDxSsKea0W7pA=; b=KAlZ5SLVHiHRZ+UQedGJrfAr0xBNbfTIdOQAzjJ5M0bmjfrmJ+f7FttlkdGe+geyuA MXtRV263WYi8yrFx62yDdMj7NUpjYDLHfhfuudLr2/VoQYtmzaldP2pxDXUlyeQW4ZH7 3ExMm9II0gcw+NKxFzysYsD4GhwdVHvPJr7wQosUtjsNvPMSklZyo5DOlSFXl4EGFfBg JdFQmFcXsgUNKAW3bisp2iUkJUmJHFZJKXaaYAyH5WBnC5klHneGiNDhXU76DYXUNcm8 oVG/H+tGavY7km/7C9udxbnXV6WnD09oyDTqKrYEb/fKC/NudrbQg36+MKn3RKR75TJQ FrjQ== X-Gm-Message-State: AOAM5311qIs9LiqiTAMAQ/VtoVx9u0b2WiAjjQGWWTC8xvCUi3qs7WD+ uGhe4zrvGXamTMoYyM1oAmk1+g== X-Received: by 2002:ac8:1186:: with SMTP id d6mr14164688qtj.124.1615851661253; Mon, 15 Mar 2021 16:41:01 -0700 (PDT) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id o7sm13242112qki.63.2021.03.15.16.41.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 16:41:00 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Michal Hocko , Roman Gushchin , Shakeel Butt , Tejun Heo , =?UTF-8?q?Michal=20Koutn=C3=BD?= , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH] mm: memcontrol: switch to rstat fix Date: Mon, 15 Mar 2021 19:41:00 -0400 Message-Id: <20210315234100.64307-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix a sleep in atomic section problem: wb_writeback() takes a spinlock and calls wb_over_bg_thresh() -> mem_cgroup_wb_stats, but the regular rstat flushing function called from in there does lockbreaking and may sleep. Switch to the atomic variant, cgroup_rstat_irqsafe(). To be consistent with other memcg flush calls, but without adding another memcg wrapper, inline and drop memcg_flush_vmstats() instead. Signed-off-by: Johannes Weiner --- mm/memcontrol.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index f7fb12d3c2fc..9091913ec877 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -757,11 +757,6 @@ mem_cgroup_largest_soft_limit_node(struct mem_cgroup_tree_per_node *mctz) return mz; } -static void memcg_flush_vmstats(struct mem_cgroup *memcg) -{ - cgroup_rstat_flush(memcg->css.cgroup); -} - /** * __mod_memcg_state - update cgroup memory statistics * @memcg: the memory cgroup @@ -1572,7 +1567,7 @@ static char *memory_stat_format(struct mem_cgroup *memcg) * * Current memory state: */ - memcg_flush_vmstats(memcg); + cgroup_rstat_flush(memcg->css.cgroup); for (i = 0; i < ARRAY_SIZE(memory_stats); i++) { u64 size; @@ -3523,7 +3518,7 @@ static unsigned long mem_cgroup_usage(struct mem_cgroup *memcg, bool swap) unsigned long val; if (mem_cgroup_is_root(memcg)) { - memcg_flush_vmstats(memcg); + cgroup_rstat_flush(memcg->css.cgroup); val = memcg_page_state(memcg, NR_FILE_PAGES) + memcg_page_state(memcg, NR_ANON_MAPPED); if (swap) @@ -3925,7 +3920,7 @@ static int memcg_numa_stat_show(struct seq_file *m, void *v) int nid; struct mem_cgroup *memcg = mem_cgroup_from_seq(m); - memcg_flush_vmstats(memcg); + cgroup_rstat_flush(memcg->css.cgroup); for (stat = stats; stat < stats + ARRAY_SIZE(stats); stat++) { seq_printf(m, "%s=%lu", stat->name, @@ -3997,7 +3992,7 @@ static int memcg_stat_show(struct seq_file *m, void *v) BUILD_BUG_ON(ARRAY_SIZE(memcg1_stat_names) != ARRAY_SIZE(memcg1_stats)); - memcg_flush_vmstats(memcg); + cgroup_rstat_flush(memcg->css.cgroup); for (i = 0; i < ARRAY_SIZE(memcg1_stats); i++) { unsigned long nr; @@ -4500,7 +4495,7 @@ void mem_cgroup_wb_stats(struct bdi_writeback *wb, unsigned long *pfilepages, struct mem_cgroup *memcg = mem_cgroup_from_css(wb->memcg_css); struct mem_cgroup *parent; - memcg_flush_vmstats(memcg); + cgroup_rstat_flush_irqsafe(memcg->css.cgroup); *pdirty = memcg_page_state(memcg, NR_FILE_DIRTY); *pwriteback = memcg_page_state(memcg, NR_WRITEBACK); -- 2.30.1