From patchwork Thu Mar 23 04:00:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13184905 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 689CFC6FD1C for ; Thu, 23 Mar 2023 04:00:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD6F26B007D; Thu, 23 Mar 2023 00:00:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C0E366B007E; Thu, 23 Mar 2023 00:00:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAE336B0080; Thu, 23 Mar 2023 00:00:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9A9E86B007D for ; Thu, 23 Mar 2023 00:00:48 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 65D48A032E for ; Thu, 23 Mar 2023 04:00:48 +0000 (UTC) X-FDA: 80598811776.06.150ABDA Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf17.hostedemail.com (Postfix) with ESMTP id 96B6340009 for ; Thu, 23 Mar 2023 04:00:46 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=nvFwhwj7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 37c4bZAoKCCIWMQPW8FKCBEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--yosryahmed.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=37c4bZAoKCCIWMQPW8FKCBEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679544046; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=0V6KepxSWjC0U8YUMhyf5sEsW80RflfKR4tDJnFyjUM=; b=U9MXZmRcj0w6Y8llg554o8MLapiOO0c1JFAOtX/pYDJHh4/oNeCgpYDacDx+OOnmhOOa/g y21a+cG4WXRtf/yHmE96wGst3t49NgakNkFgJ/aPRUWKXKSwS3Iu2+j7w0ZFoMBXjXsnVD 1wSgJqvS9JRxqLC18VW1kYyqMLtXBoc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=nvFwhwj7; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 37c4bZAoKCCIWMQPW8FKCBEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--yosryahmed.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=37c4bZAoKCCIWMQPW8FKCBEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679544046; a=rsa-sha256; cv=none; b=MB7xGOf6oF5qrMmlWXzr9tfrY3P4JL8KM8VjCOtcE2eQH25Ru0eWKS/O+l//eE0S9hKVxJ 5iY71NjxBCgGapAoXLn8IfGtaxLx9lpsOvdMHabhTuKHWJtocQiCbn0lYKRLJu3Xr4G0HS XJnGtpnTilPPgnGIjz+iRdMzKcICTR8= Received: by mail-pf1-f202.google.com with SMTP id i15-20020aa78d8f000000b005edc307b103so9972307pfr.17 for ; Wed, 22 Mar 2023 21:00:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679544045; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=0V6KepxSWjC0U8YUMhyf5sEsW80RflfKR4tDJnFyjUM=; b=nvFwhwj7qGyMPQaTPrzYFw+T0XNSe66OQzM5b4pjwLTwVBRy9Yg/AbwpYFnRMIM5gG L465fbRhjctsBw/iYduTrtP7LUUTB2pfnwQVaagEQM0GyAtfd40drA654+PpJ27hrtIB BUWcp/c32KQ98SFLCZ9FSHYNM6vaide1p2wRQYwdJvG/bU3/l2g1YAjLINeXoxbcrV2W 3/G5Y/6fhAJDfUsgxXfVWzP78YqVFCMwh/+/7IKP9AVvA+7qfhsyQkLxneMASA+CreO0 VfuwrktKMl3lyTDdGpOXeKO210ebUx1dz4XnfSvMg+6i1Ne/G/0TP1oqkrL/txGwmyNx VJtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679544045; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0V6KepxSWjC0U8YUMhyf5sEsW80RflfKR4tDJnFyjUM=; b=nIWFSlpiLrtrAEQowd7WqwAv4gJaNPovz9hHers5zvy4UIxiFmscHw7r3w8oQ0IKou uhFgjYCYSfEAs7x3yhdfrjeiGTNnS6wNO0C/bOEBsslU8AJdyChCzJKjyiHoAEkvQ9nU A5W/vSEjRIevmTdsnKauVc6qofeg5mO723reiFiSN7Sq4nT0W5Qr8PHOZR1kRiBFA5mL Ibci4s+KCawaE7ZM35EI5d4YoKtH7Sr5UPwmoyk6EuLashSgzsrDwhsRdT5BWOCNfK8Y iWFlMrpIwSRViCcqCm3/0lKy5w+d/JcDtFpfbTFoTfMAeIOOhmcXZbhsf9badeTwkeYE uZzQ== X-Gm-Message-State: AO0yUKUBq1YS3B656VGLpi4aYL9sXsbY1t+/zNK5L0OsueyFXUjOuZbh H3NnFAwpyUk23HOwbppzu08dphFaAlI+vkrQ X-Google-Smtp-Source: AK7set+NjW/4AXEB5d0IG7XiVNOSp7doL59qiTn9uvLqiFnoG/BqWGCoWZHV7SR3pQA/2uxuP1t6d8Miz+ziUaX1 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a05:6a00:851:b0:628:30d:2d2f with SMTP id q17-20020a056a00085100b00628030d2d2fmr2879444pfk.5.1679544045305; Wed, 22 Mar 2023 21:00:45 -0700 (PDT) Date: Thu, 23 Mar 2023 04:00:32 +0000 In-Reply-To: <20230323040037.2389095-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20230323040037.2389095-1-yosryahmed@google.com> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Message-ID: <20230323040037.2389095-3-yosryahmed@google.com> Subject: [RFC PATCH 2/7] memcg: do not disable interrupts when holding stats_flush_lock From: Yosry Ahmed To: Tejun Heo , Josef Bacik , Jens Axboe , Zefan Li , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton Cc: Vasily Averin , cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, Yosry Ahmed X-Rspamd-Queue-Id: 96B6340009 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: ch79rfttckgap5gdpczhqti75fk1uc1w X-HE-Tag: 1679544046-993972 X-HE-Meta: U2FsdGVkX18Rf/+3OQvoDa+OjiDOd8iI0cEv5nsfj9hId4aiEInV1MasphSj8eEm/W4TL50qQ9orQ9gaSFVpooL2atv/ViQWmVJghw3Kru56n+qMCHpwsCyt7+8Ho3bxTXERV4GxSMhuMTMPZLWqZh5txKqEMt/FUKDptrhvAJnP4LZwbWPyfHRde8LxgfsNF4zoc0UeHzR2vdkPVY6O8XGXXki66Ryz6Z+9YA2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jTqeu4YbtMe39lCQHJlTL8CREgIhB27lgFtr8DxYXVkJi2lxlI+8TTbRKzIDEzGSRJ/910MuGAunzJw7Q4UYpkA9QKZ0e2cuDxkPQzNbP9KbIsm6tctxjpmRdWy8e58GZJPurQF+zkTRMa0ruXaHbYj0rPDoR85xcDtDM5z8FnKMUUOvbeClyz2f3IoqEN+ZVzCGTrWYKrs3vSMNeJL9oFtVFn0pDyVbw4oRook0PpHQ/17ev+q773ZkzUKBwMxgkoCwvqUfsj5WwAI4K5/GQX8RAMiet+MhNINO8qaI1GTgNjGDWtAIYOFp6m3uoLrwnp/kDx98RLlobFJBqFhKfrMWObupFuyYMY81+2c5vV5DxhVLy3IlR24whT54BEILDvS913o9ozaOrrNQ= 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: The rstat flushing code was modified so that we do not disable interrupts when we hold the global rstat lock. Do the same for stats_flush_lock on the memcg side to avoid unnecessarily disabling interrupts throughout flushing. Since the code exclusively uses trylock to acquire this lock, it should be fine to hold from interrupt contexts or normal contexts without disabling interrupts as a deadlock cannot occur. For interrupt contexts we will return immediately without flushing anyway. Signed-off-by: Yosry Ahmed --- mm/memcontrol.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5abffe6f8389..e0e92b38fa51 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -636,15 +636,17 @@ static inline void memcg_rstat_updated(struct mem_cgroup *memcg, int val) static void __mem_cgroup_flush_stats(void) { - unsigned long flag; - - if (!spin_trylock_irqsave(&stats_flush_lock, flag)) + /* + * This lock can be acquired from interrupt context, but we only acquire + * using trylock so it should be fine as we cannot cause a deadlock. + */ + if (!spin_trylock(&stats_flush_lock)) return; flush_next_time = jiffies_64 + 2*FLUSH_TIME; cgroup_rstat_flush_irqsafe(root_mem_cgroup->css.cgroup); atomic_set(&stats_flush_threshold, 0); - spin_unlock_irqrestore(&stats_flush_lock, flag); + spin_unlock(&stats_flush_lock); } void mem_cgroup_flush_stats(void)