From patchwork Thu Aug 24 03:43:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363507 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 583DBC3DA6F for ; Thu, 24 Aug 2023 03:50:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6262680004; Wed, 23 Aug 2023 23:50:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E12F88E0011; Wed, 23 Aug 2023 23:50:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0195680004; Wed, 23 Aug 2023 23:50:17 -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 BF2BF8E0011 for ; Wed, 23 Aug 2023 23:50:17 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A33C6C011C for ; Thu, 24 Aug 2023 03:50:17 +0000 (UTC) X-FDA: 81157620474.18.2C7CCBB Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) by imf23.hostedemail.com (Postfix) with ESMTP id E036614000C for ; Thu, 24 Aug 2023 03:50:15 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=CCTuSOBg; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.51 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692849015; 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=4FlzFvcCQYvI8dZSQr0uzK4V9UWa182sTQHb8HSYecY=; b=4iCvTFwA+vdBsxASNHsNkjdI1P/8YOzAwv8qFKiLcrA7cNaeW0C9wpdRhE8z3T7eAhSFNV oIJrBHI01Aq9ryUFTXMrAIqnBfHt6eviiuV3ogWyZFwINdepbznlwUgjsePrHBVTRkHFYM 62lDK6Jwbfju/G2aoz+Utp6ynJpO3oI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=CCTuSOBg; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.51 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692849015; a=rsa-sha256; cv=none; b=t876snbB0CLNpjlLAbkCnABj/EjEEFQFrx9pSBhVgEDad6uU2lnY6p/xjikeZsRk2Q1u3t ZPWG7IBmJDU6H5ChEEYHK+bJen/2kvlL4K+lbj3bERTyQPMjBs2MXm/10jwEyll7qRuSjF U4d9r8GELdCdcAJS5g5E81HmFWp5/lw= Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-6bc57401cb9so829331a34.0 for ; Wed, 23 Aug 2023 20:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692849015; x=1693453815; 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=4FlzFvcCQYvI8dZSQr0uzK4V9UWa182sTQHb8HSYecY=; b=CCTuSOBgedcKOMD6iZJkvY7Us2mVWVIovgQPaP6ZUpdF+pw4bAhv02m/Nl/S4QVY4d LPWSynhpJLRykIHUCiAxqCO+wFldrWBDT8NgV40tAakicxue0r1bpK5B/Q/mLIz5qd9g E+PYwX2FapH/Q+l5AGm47K2ttt7y4CjIrDWtAgA5OR6aYvDU11Lb8F1MD1U2SE6i8Bj6 H25VAPO/X8QTRWh+vgYHVw4v2i7u3qqCizmLZFjpxfwshexicHFZyXOq/NSfx2KwPlBG 0SM3oY1UWfVHYDPVirSv4+DuSFqTIUnfwkygBDf843DNNjRGpZkoSP1jM2B6BMbRru4C IyZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692849015; x=1693453815; 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=4FlzFvcCQYvI8dZSQr0uzK4V9UWa182sTQHb8HSYecY=; b=IfstaGKm2HwYgmAqnf+LNfChiUob/R3Bja4AMkIyHKC86WdVtfaY47an3OuJjCZBlD EVyZsrZ9nqglhsH0WmY4NSLT4MBsg/SZzS7PUZuuuiZC3L50MxMfZxfUXa0F+dRYBvRC sDJtUt5cK4Z88Uu69ixnrFsvkXe5RPtaWdCkDAePtANuZP2Vs8OFROHyCRTMBrwiJxyA Q6txJsxWgb50ncyqc/Mifx4lOBjm0+Orx0+9HlJ7cgSFok4hSFJEWv5f6AiP6aaXnQ0F D3MTfr8lVQT/1mwjzGmv8lwdRvGDGYKU26G6Zkn2DzYR9l0EUGrKzwi3aMK885fBmDIb RXHA== X-Gm-Message-State: AOJu0Ywf3Ok7UXrlTbnPp2lb4o/8qE5dXTxPtfGU39+cXIEDO+uRluqO FJySFTjQDPKGLUUedFBPDUSvBg== X-Google-Smtp-Source: AGHT+IGNNFy+tJmkErp1Cj65UOC5qZG9ZWIMpE+ontdaYElYA5FS/+TvI/fJv+zkeYDhjrDv7KNO4g== X-Received: by 2002:a05:6830:308f:b0:6b9:b987:1337 with SMTP id g15-20020a056830308f00b006b9b9871337mr14530264ots.1.1692849015165; Wed, 23 Aug 2023 20:50:15 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:50:14 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Qi Zheng Subject: [PATCH v5 44/45] mm: shrinker: hold write lock to reparent shrinker nr_deferred Date: Thu, 24 Aug 2023 11:43:03 +0800 Message-Id: <20230824034304.37411-45-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: E036614000C X-Stat-Signature: e66nzezm1yndre3srtkkpen3bearumta X-Rspam-User: X-HE-Tag: 1692849015-180612 X-HE-Meta: U2FsdGVkX1/8dTV1hESZyf/8HjV0Z7/REgVLIqxTVezMLLnssct0o+FoEVN1ooKXfLQKSEYiNtm9DqYFfSdOJFjrzdZN7VNI5TEbmUEUoO7CnXUwhnYa2G85j5SS87SP77K4dUjb7MS/BBokqHp6ENcHN5If23r/bDkXWNrfrPLfPqODGE8eeCQhCgor1FW7SBfeFekK0XQFXtYZz+lWwu0Ztr8WhpFRJWCg75i1CpO+H8Xj7zH2vWYDsYlCbK6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smjj6PJJyWrEKb/fiaDyDq40doPg== 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: For now, reparent_shrinker_deferred() is the only holder of read lock of shrinker_rwsem. And it already holds the global cgroup_mutex, so it will not be called in parallel. Therefore, in order to convert shrinker_rwsem to shrinker_mutex later, here we change to hold the write lock of shrinker_rwsem to reparent. Signed-off-by: Qi Zheng --- mm/shrinker.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/shrinker.c b/mm/shrinker.c index a66e2a30cc16..b8cb9d2f5dbf 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -292,7 +292,7 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) parent = root_mem_cgroup; /* Prevent from concurrent shrinker_info expand */ - down_read(&shrinker_rwsem); + down_write(&shrinker_rwsem); for_each_node(nid) { child_info = shrinker_info_protected(memcg, nid); parent_info = shrinker_info_protected(parent, nid); @@ -305,7 +305,7 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) } } } - up_read(&shrinker_rwsem); + up_write(&shrinker_rwsem); } #else static int shrinker_memcg_alloc(struct shrinker *shrinker)