From patchwork Thu Mar 23 04:00:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13184909 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 1CE8EC6FD1C for ; Thu, 23 Mar 2023 04:00:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88F436B0089; Thu, 23 Mar 2023 00:00:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8644D6B008A; Thu, 23 Mar 2023 00:00:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7533F6B008C; Thu, 23 Mar 2023 00:00:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 59E6A6B0089 for ; Thu, 23 Mar 2023 00:00:55 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2E1A6A01A1 for ; Thu, 23 Mar 2023 04:00:55 +0000 (UTC) X-FDA: 80598812070.11.8DF25B2 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf01.hostedemail.com (Postfix) with ESMTP id 6A91340013 for ; Thu, 23 Mar 2023 04:00:53 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=CYUJafqL; spf=pass (imf01.hostedemail.com: domain of 39M4bZAoKCCkdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=39M4bZAoKCCkdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679544053; 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=IoeZYZryJtZ5YKLINZigwUk+eCMrWPKZYyl5pNjfs0s=; b=L1ZjT3IOmCjXrIFn6bAW7OyuPgvQHoetrTyQVvSwKZvkjHKaxvid1rhiYdLUA5SMln+fPj IA4rjEcmzLuzdhXUbpwi6ZXyKbLEPZDhMd8MTBfTZV8mAGpUTteWBFMcIbJ8Y5Jftac7I4 ncx3coFs0GObg9R9rSFtwI9KkCv/1uA= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=CYUJafqL; spf=pass (imf01.hostedemail.com: domain of 39M4bZAoKCCkdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=39M4bZAoKCCkdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679544053; a=rsa-sha256; cv=none; b=PbO98yvuBCmBq7rjfEDNCavtSKJJePmi4VDL6n5/KHnVI/XzqLLsUUW30+SXkz2YPC0FjP 7Cbi5VmqnymKJ1tIURwwunXACOrEOLfXa2/E8LYIMQRI1oOODorMXk5fRy/Le4Ny4Zyzkv KzQpgiaaZZDv+oT8rV1ROPA5wj6Mp+Y= Received: by mail-pl1-f202.google.com with SMTP id p9-20020a170902e74900b001a1c7b2e7afso7040174plf.0 for ; Wed, 22 Mar 2023 21:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679544052; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IoeZYZryJtZ5YKLINZigwUk+eCMrWPKZYyl5pNjfs0s=; b=CYUJafqLeSTzFoXixoXxJfg+d8a1R4JvCUerDh64ifDjpdaxbdbWqowybN/gvJ19LK Og473fSzkkpOeMA58DC64BMRm6M0MCGDM/VGSfHLkAlVcw8rDdEYpMTrVbzG7kCaO9yo XEy99SSbQbOpczsL5Zy04pgal2f5dv+k8luu/GDpUWQB1RZl9qYQhWpR8p3p3vD98PGc ce78QmYoavhlvFbHk6YMCQ65CM/lnXEYztj/xUq2pBOa3UnU3uBgApeimhahme8eLkyC CQZkL9MM7bPQMzx+6ozclKMKwr8T8qPF+ZR71Vewcxu4v3esM5hXIWD8hj0gOLxV+qOY L9ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679544052; 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=IoeZYZryJtZ5YKLINZigwUk+eCMrWPKZYyl5pNjfs0s=; b=H6ZUayMNcLAPerp6dBv7HZOe8jFnUQp9fOoe1K1LQCUF3SaxGpw9Kc0+bRU59rZIc9 LOmwCfWJz+8Gsto0CYdK2ub7EtDEEruHcwdyFcV4Aj7/cDug0sTUshme1pLo+0+yMPgL a2mmJ/2ZyfLcSY1O1mU//b7MLfaNWDAOnCHBm7zqGh6D5NJ06vgguLM25VWOLllRm6Lu vwzHypMYmSQ87+Ati1OU/+Pod0twolhbQZ42080Q/SOT5wrQ7jgLb9Apzivvvk74U7bb r3weA2au2nKu3LaV9OVs0DeXjCnMpmuzw6l1UF9O5gYP3Xikq4HEAq+EhnhBTva1sQnM nwRQ== X-Gm-Message-State: AO0yUKULjpmpGhJE+q//sf/MI7UqE3H+xYP8S/BI1KXB3S1M4r2eQ87l SIFYPfamluIh3QZxnnqRKbFrsTyfbhoTL5/k X-Google-Smtp-Source: AK7set9aF1O2O+BZVk6rqDRrbbtYYQ/yqA23fBe+9ZzPXGEhcCIhooyW8p0Z2epSuqN1jjR7FDL5kfmsz1ZKE44X X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:90a:ce11:b0:23f:d473:dd44 with SMTP id f17-20020a17090ace1100b0023fd473dd44mr1881490pju.3.1679544052257; Wed, 22 Mar 2023 21:00:52 -0700 (PDT) Date: Thu, 23 Mar 2023 04:00:36 +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-7-yosryahmed@google.com> Subject: [RFC PATCH 6/7] workingset: memcg: sleep when flushing stats in workingset_refault() 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: 6A91340013 X-Stat-Signature: zjuihm3wt7r9azktpcnqxb6877hmdzbe X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1679544053-475883 X-HE-Meta: U2FsdGVkX1+hchwr3HPCLL0ADODj6e7fH5k578ZfiUPfyfMzTuP9Gn0GMSuWid75YJaJP75RD73jcjJIRlpetxXrqCH237reFEcjIPAyqCFRk4ZMDs38HvXsOLwZLCAo0yZnDI/TrknzGg3d+D9WP3s3l1dcoGMPloIZEEOChWYTQvm1nexi26FSo7nZ0YmGCg7E1cmctXN7uRnBJAFQB/P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ThWgK8Ej+7UKgmZvHDY03W5Y5vCnVVwTWelkhIWIcRUk0kAAx8HZQmDPBxsWftKKISGdpYb/cUPqw73UFUqxZN8g4aE1PqEqGxx8rrTDDv3MYyVIy0goY0iR6kAb6ihf3dvBYD8VA/0ekOtmDNgCFrnIcmGBYYPq1RniZ5aQSySk4+rYLZDi6FZ10dRzHOncmAoGDVLkputbf6x+bhBlcdcc1Q5z85LaCsb/fVBwhSi3p//r5QW/xx6eocSkR+YgplxQgG61nnjC7981oVXcwhSl954ME7RCpzCdvs6jhBFTfvB7SMXcLoA+CAJHJCYAjTybPgl4or86oFJ8i1GXdjxaf57qUZHeNftFImNCAlLkTpGGrrYgrnSLocYOb7VOoXCwKMMpf0hLVc+6tuBnQQlh1buM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000154, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In workingset_refault(), we call mem_cgroup_flush_stats_delayed() to flush stats within an RCU read section and with sleeping disallowed. Move the call to mem_cgroup_flush_stats_delayed() above the RCU read section and allow sleeping to avoid unnecessarily performing a lot of work without sleeping. Signed-off-by: Yosry Ahmed --- A lot of code paths call into workingset_refault(), so I am not generally sure at all whether it's okay to sleep in all contexts or not. Feedback here would be very helpful. --- mm/workingset.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/workingset.c b/mm/workingset.c index 042eabbb43f6..410bc6684ea7 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -406,6 +406,8 @@ void workingset_refault(struct folio *folio, void *shadow) unpack_shadow(shadow, &memcgid, &pgdat, &eviction, &workingset); eviction <<= bucket_order; + /* Flush stats (and potentially sleep) before holding RCU read lock */ + mem_cgroup_flush_stats_delayed(true); rcu_read_lock(); /* * Look up the memcg associated with the stored ID. It might @@ -461,9 +463,6 @@ void workingset_refault(struct folio *folio, void *shadow) lruvec = mem_cgroup_lruvec(memcg, pgdat); mod_lruvec_state(lruvec, WORKINGSET_REFAULT_BASE + file, nr); - - /* Do not sleep with RCU lock held */ - mem_cgroup_flush_stats_delayed(false); /* * Compare the distance to the existing workingset size. We * don't activate pages that couldn't stay resident even if