Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2808134rwb; Mon, 15 Aug 2022 11:45:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR4AP8HSDc3iX1ZzaEmAUYKyQavjmT/QbT+mg2CsVv3wnX2Bnl+lUkifDLngmZx/ekCLOYoM X-Received: by 2002:a05:6402:138f:b0:43d:8ed5:c841 with SMTP id b15-20020a056402138f00b0043d8ed5c841mr15749497edv.27.1660589133837; Mon, 15 Aug 2022 11:45:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660589133; cv=none; d=google.com; s=arc-20160816; b=w5sgqvdHbs/lGFa/tdTyRHLXbLk0X/tEUgrUyHPY0/cbQJjXnYng3M7UojV5OIY8Sw AorPdkAL9kktGys0k1fZIZMqxCd6i24TwPYxjAkrxXERbQPG3qpgD1PPknpLkv4HlI6K 3PRfgFGoWIs63Bh7J2htLqEB7dm+SchY1c78jrOBKPNzbwFeRYSH307of50PByMQBB9b DBUPnniZoITIwn2vTSCO8Z5ksO33jUCKMu0+RQIc3op60/FUgEm+owp5RTg/00NQQtZj WYrikJLSKq/Kwr8uWR+Tl/yXwCFCs95tfSNoz3A3BKoY6yQVZLtyfhisUn6+ZRkzn2ox rYBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8lm+hKVXMlTyrofcvjpNAqsoI018za7SO2iYY7y1BXk=; b=a9YHrkPMsmR319hNNpApRPQM2TrGfzX4vWJSA95eUiu/ZaUWkzUsacAvBe8fO+9e1g 5z1ONILUWEhWcSF0/oBg/0uKy01YfgJ5K6gdY+Udb7oDh9GHxDmSE8Ll9EzkcUt4QBPO KXmsCVymMDAJqnNe6G5whoizzgSz5OOG/L7hHZL4Pyf65q9xm0hXp/p+Lr0JgFIv4vhY pwaUB2pZhhfn5IqG1cINacliXOMbHEwd0zqBtHMzKWisjQWGfFxCxNFp2Umj/BK4xXUa 51EM4Y2jzkMgd6cYespqIz//pfR43HSWHhTiHsYNyDYtGI0jCXaavSD88m6VvoTuPUiN a7nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GN9sS4M5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id du20-20020a17090772d400b00734ba6143a7si8706257ejc.930.2022.08.15.11.45.08; Mon, 15 Aug 2022 11:45:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GN9sS4M5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241879AbiHOS14 (ORCPT + 99 others); Mon, 15 Aug 2022 14:27:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243113AbiHOS0o (ORCPT ); Mon, 15 Aug 2022 14:26:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4241D3122C; Mon, 15 Aug 2022 11:19:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DF5C360C07; Mon, 15 Aug 2022 18:19:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2792C433C1; Mon, 15 Aug 2022 18:19:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660587553; bh=uwI7jOt3LUj5x/gvUBN4HIO7/wzxiNFPzitTcyPAavQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GN9sS4M59OpeLi4zqhL/bdZpB8oPDB7z8yakGjzO3qZdiHafOif7rVfDYNkwG0fjI Tt5Hxz73tt3cJOI35yaCawvLVRQUxwQaUq+yq8ofA9XJSsPSsKkRzVcNjeJWWs9JnH RVRP2HLVyRShfjE4aI1QRylZlloKeVuBEVj5fMTM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , Theodore Tso Subject: [PATCH 5.15 090/779] mbcache: dont reclaim used entries Date: Mon, 15 Aug 2022 19:55:34 +0200 Message-Id: <20220815180341.138257153@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kara commit 58318914186c157477b978b1739dfe2f1b9dc0fe upstream. Do not reclaim entries that are currently used by somebody from a shrinker. Firstly, these entries are likely useful. Secondly, we will need to keep such entries to protect pending increment of xattr block refcount. CC: stable@vger.kernel.org Fixes: 82939d7999df ("ext4: convert to mbcache2") Signed-off-by: Jan Kara Link: https://lore.kernel.org/r/20220712105436.32204-1-jack@suse.cz Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/mbcache.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/fs/mbcache.c +++ b/fs/mbcache.c @@ -288,7 +288,7 @@ static unsigned long mb_cache_shrink(str while (nr_to_scan-- && !list_empty(&cache->c_list)) { entry = list_first_entry(&cache->c_list, struct mb_cache_entry, e_list); - if (entry->e_referenced) { + if (entry->e_referenced || atomic_read(&entry->e_refcnt) > 2) { entry->e_referenced = 0; list_move_tail(&entry->e_list, &cache->c_list); continue; @@ -302,6 +302,14 @@ static unsigned long mb_cache_shrink(str spin_unlock(&cache->c_list_lock); head = mb_cache_entry_head(cache, entry->e_key); hlist_bl_lock(head); + /* Now a reliable check if the entry didn't get used... */ + if (atomic_read(&entry->e_refcnt) > 2) { + hlist_bl_unlock(head); + spin_lock(&cache->c_list_lock); + list_add_tail(&entry->e_list, &cache->c_list); + cache->c_entry_count++; + continue; + } if (!hlist_bl_unhashed(&entry->e_hash_list)) { hlist_bl_del_init(&entry->e_hash_list); atomic_dec(&entry->e_refcnt);