From patchwork Tue Nov 7 00:31:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13447622 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 9641AC4167D for ; Tue, 7 Nov 2023 00:31:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19DE78D0033; Mon, 6 Nov 2023 19:31:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 14D018D0001; Mon, 6 Nov 2023 19:31:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 014948D0033; Mon, 6 Nov 2023 19:31:54 -0500 (EST) 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 E31D18D0001 for ; Mon, 6 Nov 2023 19:31:54 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BD59E1208F9 for ; Tue, 7 Nov 2023 00:31:54 +0000 (UTC) X-FDA: 81429280548.05.834C98C Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) by imf28.hostedemail.com (Postfix) with ESMTP id 03F6EC0016 for ; Tue, 7 Nov 2023 00:31:52 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Bdaq4elg; spf=pass (imf28.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.167.171 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699317113; a=rsa-sha256; cv=none; b=RJE4crNZkxJNMIEGY09YNKr6DPOLaKEMSxNlMuCI89EAeGfkNIAedz4+Y8Y518QEnycpys vsIL4pbwibw/cAnft2yyqCZqDEgl9YoJehzNBpglxUsMFMD/LnJlJGq3FaXVmrPsQiQjwF hr1Tf8BAY5olVlrKrQDmXS63vuoh0Ek= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Bdaq4elg; spf=pass (imf28.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.167.171 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699317113; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=d0WGY/AKCQE6ND37JA3v4q+xJaxjKD8rC8TyYg2oDtg=; b=SBJhEpOzg5G6ZLpHIDLKLnxnWfFcSKzmfYwV/XfSyB1jswaLtkw2L4PdCgBAAmegImgiHF I/Sudz8wE2PbAaZP/cyqacJgiugrcC1wF5jWJO5wtDZjXhlmVue2QPhXnij4nxtgZ664Xv n9iBBd1JE7uai6cCpY+KjZWEZxZrF9I= Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-3b3f6dd612cso3061119b6e.3 for ; Mon, 06 Nov 2023 16:31:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699317112; x=1699921912; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d0WGY/AKCQE6ND37JA3v4q+xJaxjKD8rC8TyYg2oDtg=; b=Bdaq4elg0AMQ7eg6WIvUaHCnVnEM7kdFVT4KyAHZiwbQ/RdJpE/3rDQaaytFF+YwBB X5szQE2+/1r1r4GgN/NxKBl4tsrzvaPU0O07C8EXNTLR8Cek3W7i3MKKFAlytFZVvdRW fNdelpci+mpPPUE8qWlYjj9GfYMA0Ny3VSqY3R1szOigh/m9V98sXwcKKPYEjWFUK0hL YSadE1NvQV5iJppTomvNg2hN8OoiNjoTPLU00GBwIvSMXucOp64V2I3r3Js82idXw1WU pBGkaRBRdjaTS27oeU1OYQ/K2+NWvSCMe+bNv12OgoIqfBixMGGBm8SX2/OxspqQXOGE qa+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699317112; x=1699921912; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d0WGY/AKCQE6ND37JA3v4q+xJaxjKD8rC8TyYg2oDtg=; b=JlX9z0U1ktgfzKKKHJ03M1lacHQ8vdSJ9GkODm9kyKxCbMAERiLYtY1n0wXAQ4mSkf pDaZ1WrimuZuaojnkWXuu1aqq9mmdS2NB7XL3hkuWuxctmQWZ/EXpTrf4nVhojLK4nfs U3s2/6UehIciGGHh49B8494SF1YjEMWTuVvFB0z88TNyPyGuxm5u+3kXsNCVDzLEgc26 GPotAq4YsV8omtsIYdRNE8DdNndKjPC2hwmjZ5LPjYK4Cte8sHS2BjxnBGkKOscvKFxA NLmO0h6czOjmqRktSsT1yD30kVq12CpUMXBj7GfVVawpuoamg5k9F7CSrc1G8qVRPr5E lRqA== X-Gm-Message-State: AOJu0Yxh8buQl3OwsMur8rk+WUWxCF862rD561WIv10NmSBowC9N4fGR 86J4DKqOGbrF254lRc1JOKg= X-Google-Smtp-Source: AGHT+IFLDk2laxdyQ5ieeG3Edwclvst8+hE+8U16b+m5kSoKdpGwnzW/8zTX4A4zOu0NFtZPrk5Wxw== X-Received: by 2002:a05:6808:210d:b0:3ac:aae1:6d64 with SMTP id r13-20020a056808210d00b003acaae16d64mr37640029oiw.2.1699317111933; Mon, 06 Nov 2023 16:31:51 -0800 (PST) Received: from localhost (fwdproxy-prn-004.fbsv.net. [2a03:2880:ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id fb24-20020a056a002d9800b006c3488498bbsm3732085pfb.44.2023.11.06.16.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 16:31:51 -0800 (PST) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, cerasuolodomenico@gmail.com, yosryahmed@google.com, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, chrisl@kernel.org, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, shuah@kernel.org Subject: [PATCH v5 3/6] zswap: make shrinking memcg-aware (fix) Date: Mon, 6 Nov 2023 16:31:51 -0800 Message-Id: <20231107003151.724860-1-nphamcs@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231106183159.3562879-4-nphamcs@gmail.com> References: <20231106183159.3562879-4-nphamcs@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 03F6EC0016 X-Stat-Signature: 1biwf4trszu7kdkwa7ajbij7xp5ue67w X-Rspam-User: X-HE-Tag: 1699317112-385500 X-HE-Meta: U2FsdGVkX182SvNrlIuttCmvo6PwQ/1VX9hBEHFZutETclcdBAP5lIfTEjKgfjf8pC4qIHSwcwK9H0HFxplK4jraDiWmJB8ArOE3uf9AKk753RzafzcTQnHqFO4UoTBOC9PTFjCVbpseDVa3dIBPQC8S6SDVlUJ3SKWttkxNwV44jr6hpko9X8Q5mU8xm+5b8vR3DBbwnigXzkDbw634Br3NVJSnl7rLIEVtAsWiDvDniXUYMiEBtbacj4DnKmY6lGpazIQboB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gK5Lo3dZGywGTptB+wdY09GODWOJm0qMk8oLmV2OfeAwe6ZikkjZCCjCmGrz6AxP/6W0zcX8emNeShWw7lRrlYpt8KFnQMYfoCsLgbTVCXTw= 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: List-Subscribe: List-Unsubscribe: Rename get_mem_cgroup_from_entry() to mem_cgroup_from_entry() and use the zswap_pools_lock for next_shrink update. Suggested-by: Yosry Ahmed Signed-off-by: Nhat Pham --- mm/zswap.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 2654b0d214cc..f1998dbd3519 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -174,7 +174,6 @@ struct zswap_pool { struct hlist_node node; char tfm_name[CRYPTO_MAX_ALG_NAME]; struct list_lru list_lru; - spinlock_t next_shrink_lock; struct mem_cgroup *next_shrink; }; @@ -292,7 +291,7 @@ static void zswap_update_total_size(void) } /* should be called under RCU */ -static inline struct mem_cgroup *get_mem_cgroup_from_entry(struct zswap_entry *entry) +static inline struct mem_cgroup *mem_cgroup_from_entry(struct zswap_entry *entry) { return entry->objcg ? obj_cgroup_memcg(entry->objcg) : NULL; } @@ -309,11 +308,9 @@ void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg) /* lock out zswap pools list modification */ spin_lock(&zswap_pools_lock); list_for_each_entry(pool, &zswap_pools, list) { - spin_lock(&pool->next_shrink_lock); if (pool->next_shrink == memcg) pool->next_shrink = mem_cgroup_iter(NULL, pool->next_shrink, NULL, true); - spin_unlock(&pool->next_shrink_lock); } spin_unlock(&zswap_pools_lock); } @@ -360,7 +357,7 @@ static void zswap_lru_add(struct list_lru *list_lru, struct zswap_entry *entry) * Similar reasoning holds for list_lru_del() and list_lru_putback(). */ rcu_read_lock(); - memcg = get_mem_cgroup_from_entry(entry); + memcg = mem_cgroup_from_entry(entry); /* will always succeed */ list_lru_add(list_lru, &entry->lru, nid, memcg); rcu_read_unlock(); @@ -372,7 +369,7 @@ static void zswap_lru_del(struct list_lru *list_lru, struct zswap_entry *entry) struct mem_cgroup *memcg; rcu_read_lock(); - memcg = get_mem_cgroup_from_entry(entry); + memcg = mem_cgroup_from_entry(entry); /* will always succeed */ list_lru_del(list_lru, &entry->lru, nid, memcg); rcu_read_unlock(); @@ -386,7 +383,7 @@ static void zswap_lru_putback(struct list_lru *list_lru, struct mem_cgroup *memcg; rcu_read_lock(); - memcg = get_mem_cgroup_from_entry(entry); + memcg = mem_cgroup_from_entry(entry); spin_lock(lock); /* we cannot use list_lru_add here, because it increments node's lru count */ list_lru_putback(list_lru, &entry->lru, nid, memcg); @@ -806,13 +803,13 @@ static void shrink_worker(struct work_struct *w) /* global reclaim will select cgroup in a round-robin fashion. */ do { - spin_lock(&pool->next_shrink_lock); + spin_lock(&zswap_pools_lock); memcg = pool->next_shrink = mem_cgroup_iter(NULL, pool->next_shrink, NULL, true); /* full round trip */ if (!memcg) { - spin_unlock(&pool->next_shrink_lock); + spin_unlock(&zswap_pools_lock); if (++failures == MAX_RECLAIM_RETRIES) break; @@ -824,7 +821,7 @@ static void shrink_worker(struct work_struct *w) * original reference is dropped by the zswap offlining callback. */ css_get(&memcg->css); - spin_unlock(&pool->next_shrink_lock); + spin_unlock(&zswap_pools_lock); ret = shrink_memcg(memcg); mem_cgroup_put(memcg); @@ -898,7 +895,6 @@ static struct zswap_pool *zswap_pool_create(char *type, char *compressor) INIT_WORK(&pool->shrink_work, shrink_worker); zswap_pool_debug("created", pool); - spin_lock_init(&pool->next_shrink_lock); return pool; @@ -963,10 +959,10 @@ static void zswap_pool_destroy(struct zswap_pool *pool) free_percpu(pool->acomp_ctx); list_lru_destroy(&pool->list_lru); - spin_lock(&pool->next_shrink_lock); + spin_lock(&zswap_pools_lock); mem_cgroup_put(pool->next_shrink); pool->next_shrink = NULL; - spin_unlock(&pool->next_shrink_lock); + spin_unlock(&zswap_pools_lock); for (i = 0; i < ZSWAP_NR_ZPOOLS; i++) zpool_destroy_pool(pool->zpools[i]);