From patchwork Sat Aug 3 05:33:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13752160 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 7B04FC3DA4A for ; Sat, 3 Aug 2024 05:33:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA9166B007B; Sat, 3 Aug 2024 01:33:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B58C76B0083; Sat, 3 Aug 2024 01:33:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1ED56B0085; Sat, 3 Aug 2024 01:33:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 835C56B007B for ; Sat, 3 Aug 2024 01:33:12 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E0CA5A0DE8 for ; Sat, 3 Aug 2024 05:33:11 +0000 (UTC) X-FDA: 82409815782.20.8205F2C Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf15.hostedemail.com (Postfix) with ESMTP id 478E7A0011 for ; Sat, 3 Aug 2024 05:33:10 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=PdKHRZ7a; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3FcGtZgoKCIoC265Cov0sru22uzs.q20zw18B-00y9oqy.25u@flex--yosryahmed.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3FcGtZgoKCIoC265Cov0sru22uzs.q20zw18B-00y9oqy.25u@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722663184; a=rsa-sha256; cv=none; b=2ieRNidzoWR4Jjq7g8tZEDUKuxohzO6pebboeupKvFf3MDAtDrKdsbue/LAf1+aOSFxw8L 5MI3fjM6qB4xn9EVUKQY2wyOo8f+sTq8v3QqNesLDIDbD9xKjYSn0YLFqJD4+AW8xuWbAE NdJwQy7PfmB36JFV0JHrTz6jOTl5zk4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=PdKHRZ7a; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3FcGtZgoKCIoC265Cov0sru22uzs.q20zw18B-00y9oqy.25u@flex--yosryahmed.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3FcGtZgoKCIoC265Cov0sru22uzs.q20zw18B-00y9oqy.25u@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722663184; 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: references:dkim-signature; bh=dVMABDG6zvtzBrluDCQkwCGip5NCjvJGZc7ooD15Ipc=; b=zPSSvbCchIvBw8bqK+IPUqcSKOHcuq4G+T7fP3MnOYtPIT5pYvA79lQFhIpcb2Td5/KpQv 9IJRqBeNFaFazCqRAFzrTZuzSnXkyGRRpUZszntdjqeYCvEhszFDsW0iE0jh3F7Ujw83Zg IYmpHB8qQrWigvNOsTNOQPFMi/rwJRs= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e05e9e4dfbeso13852734276.1 for ; Fri, 02 Aug 2024 22:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722663189; x=1723267989; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=dVMABDG6zvtzBrluDCQkwCGip5NCjvJGZc7ooD15Ipc=; b=PdKHRZ7aycFXdqSweMxV0XcUwKeODCzs+fnnNZ/dg3T0HzLUAVEvap2WtE0AhvXaRV wLlKEY2QbHnXXp9mdOL0d5/zK8vZal8h0Yj35hITgwcPZGnQqs9bZG9Fj15PnstodkBq 19Pi/cuQTkWO0oEiFqkDH/HrFGPLxiWndMGJOPCAtvmRk6Zmx3565YDap4fQwEiO0bJc hLE1TesZwetagulpU1Bk8JJ/5nG39aJb8muHWBZm0BWJ0kALP4Acj5xVPCEA3o3+RyDH 6ZwriPDzyiRt0WLA3qhM2QEgvQKNl+PRU/pLrumMwIdV6EjdVCkVIJrYM+SygP7HPla9 mM8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722663189; x=1723267989; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=dVMABDG6zvtzBrluDCQkwCGip5NCjvJGZc7ooD15Ipc=; b=lPn1UaR5sv0Bd9zCRLQjolq9lzYNgneFltUSxmNaI+8Azp1ilf9YWWluEmb3PBCp9e XQkWIcZRzWHhEaXlGXpLQNZRCQO7NYtQOWKr+kwNOv7GLJh35DZGbv0InOhIEJqzpc7i zYLlD4TM/rtS1a2ErlT6SWnbA3Oog8nA0zsN0tB7ZHoYOEb3jWqK6VwVrbdBi4+hQCZ+ tNfkZTNk92NEQQtA/pJ/fh6gK3ihBLLKSOtBKArxhQ8ALEVCawTeyN5pJKKm7lYO6vel GKyN0cp/6cN1PS955XfvbZSTuQIyI5xqkG7a00OsERi3Hh6nsJSgc1tcKdJx6vWj/4Em 6pXQ== X-Forwarded-Encrypted: i=1; AJvYcCXBKWlHszIg5smJmi7aOdEvTUy0z8xDMHH1WvZG9pwOv6oLthwHfl7wG87SYMRMhe+qsH19CVVkE5xd0KPrbgX6k4s= X-Gm-Message-State: AOJu0YwxFrec54aKcJUc4JRVmjvsbAM3GHl1H/cr5aliaolYvbUcjnFr /6BmyvlQAWbYRwWpVtQgsXNK1KJepvixcXj3WY+WQIdGGEV/kuqiFq7rW50WMzoKqfP0vVH2rRa FPJXMnlplB/nCxxTd6A== X-Google-Smtp-Source: AGHT+IGiZEPPAQNY2/nwbwVwRsUGjO4TgUlfihhyR0VvwxRkt7mU9aLbAmPrEM8xOeTxVidxnOufplpnPgFzgwEo X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:2313:b0:e05:65b7:32d9 with SMTP id 3f1490d57ef6-e0bde22af67mr16846276.6.1722663189151; Fri, 02 Aug 2024 22:33:09 -0700 (PDT) Date: Sat, 3 Aug 2024 05:33:06 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.46.0.rc2.264.g509ed76dc8-goog Message-ID: <20240803053306.2685541-1-yosryahmed@google.com> Subject: [PATCH] mm: zswap: make the lock critical section obvious in shrink_worker() From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , Takero Funaki , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspam-User: X-Rspamd-Queue-Id: 478E7A0011 X-Rspamd-Server: rspam01 X-Stat-Signature: yu9kz5aqacte9dxess7oserwzd9m1fdu X-HE-Tag: 1722663190-701483 X-HE-Meta: U2FsdGVkX188t19Vqebycb27b8db+6+tzgEKlIE/AKy3kqJNHVTbK4CeRJMF2zL4J+RNoGtqbmDvAf1A/ZPiTF0a7xO3zX4NRmswEGZtHvp3rd6iMFadq+Ytt+TjvkmTmDjVn5bwJ5Uo04v7pyalirj7JtCBgRUelfC6Y/rxElg1xnFnv3io94mALz7VjH7qvliZ/W7hyEA2oYU/q2Sg3tQ4DmyVLSEtBELRr5Z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QVvspLgmnyROTlYSHQOVkZSF1VT8/aeyFng7LUFRM3XQSn90oaUu9ICj5HWsPKRDwZmLhOwNKWON+5QGnlmYxTwTlWT5R37QggieF4TUaDaKe/e2Mdr9Z1t6LbS3Z4yqW90/8/X+5OPM/GlaAUfsFSjbuY8rWygp0hfm9NSdbxckdK/Hx4pNQHkQ6lz2In7P4ikS6dNcMDIO1OnJRhVrEkgP2wa1wmdTbx2lf3ejUYHwujnYhx35TMg8eSjHEDcMqYG+ur1u8fqmeXQ9jZvEik7tZ7A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000350, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Move the comments and spin_{lock/unlock}() calls around in shrink_worker() to make it obvious the lock is protecting the loop updating zswap_next_shrink. Signed-off-by: Yosry Ahmed Reviewed-by: Nhat Pham Reviewed-by: Chengming Zhou Acked-by: Johannes Weiner --- This is intended to be squashed into "mm: zswap: fix global shrinker memcg iteration". --- mm/zswap.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index babf0abbcc765..df620eacd1d11 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1364,24 +1364,22 @@ static void shrink_worker(struct work_struct *w) * until the next run of shrink_worker(). */ do { - spin_lock(&zswap_shrink_lock); - /* * Start shrinking from the next memcg after zswap_next_shrink. * When the offline cleaner has already advanced the cursor, * advancing the cursor here overlooks one memcg, but this * should be negligibly rare. + * + * If we get an online memcg, keep the extra reference in case + * the original one obtained by mem_cgroup_iter() is dropped by + * zswap_memcg_offline_cleanup() while we are shrinking the + * memcg. */ + spin_lock(&zswap_shrink_lock); do { memcg = mem_cgroup_iter(NULL, zswap_next_shrink, NULL); zswap_next_shrink = memcg; } while (memcg && !mem_cgroup_tryget_online(memcg)); - /* - * Note that if we got an online memcg, we will keep the extra - * reference in case the original reference obtained by mem_cgroup_iter - * is dropped by the zswap memcg offlining callback, ensuring that the - * memcg is not killed when we are reclaiming. - */ spin_unlock(&zswap_shrink_lock); if (!memcg) {