Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3030218rwb; Mon, 15 Aug 2022 16:29:15 -0700 (PDT) X-Google-Smtp-Source: AA6agR5tc3RX7XdWWBH1jpCwWxnN23DBtKD2bWKucQo/B1AeXMolzLPhH4Ufa1+TYWVD/9fplRcJ X-Received: by 2002:a05:6402:5489:b0:43b:b935:db37 with SMTP id fg9-20020a056402548900b0043bb935db37mr16778644edb.347.1660605792594; Mon, 15 Aug 2022 16:23:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605792; cv=none; d=google.com; s=arc-20160816; b=KkfteaZKRsAeBFmNKdHAvFI64YUi2TRnXoWGpsqz/1lIUlqzh3HXkYODnmbNs0iVaQ RB8xIUCNz2nZcImnDTjKdUMXcAXYHh7cUg8qE+2tN7Vt1MGYrdYOP501jvvj0i145jOD VMwS9+FrG0zIHGApzPbLi8lCt64mrwOCYPx1xV6xCO0k+YJ6jym8Va52t/naeT/yGFkv pvxgpWeFJjwrOLYlx+IgpMUsPHc5etDxwOZUtyHrs9yQ86vRfhiiLBCyAfERxHfr7JGP hkMG2Kh8s6aEeaTqkT5CS//nJ/EVzNnpjglUs76gq9U65fzcz6lQIxK+y83Q/p58j/uw gFdg== 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=ffQBVq8ndETnGGNOQ1lB2f29AG5E6eoJEj2zncJyb4YDZEFLXVTzSvc20Ou0jjS1M+ Ge/fXkD3foBJRsQvAI4sYqZvckW+oNvlz2b2hizEJhHzBG7Zrj78M0z/mt0gd/xtWorA NKjQBasHWdABsHUi8olCWSNqSHBEC9RRlEOAhh6ZG+ydes6gmXAMJkHN7Zdjj8cKDb68 uRKj1W08Mop6LbUE4ptVyBokqzEDvyI9DqeHPIIRyqf5re7iuxKlOCdZwge6X59I1jSw 8JLgPiSWVeb8mzJ+vU7K+YT/5nQ2AFtokAqBJ1ER1RP6qWfET/rxK4dhqf09r19uKeml LU8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1wLgD+cq; 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 z26-20020aa7c65a000000b0043cc6e2abf4si8417125edr.298.2022.08.15.16.22.47; Mon, 15 Aug 2022 16:23:12 -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=1wLgD+cq; 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 S1347490AbiHOWYL (ORCPT + 99 others); Mon, 15 Aug 2022 18:24:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350782AbiHOWSc (ORCPT ); Mon, 15 Aug 2022 18:18:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B3A56556A; Mon, 15 Aug 2022 12:41:35 -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 EB1F460FB9; Mon, 15 Aug 2022 19:41:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EACB5C433D6; Mon, 15 Aug 2022 19:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592494; bh=uwI7jOt3LUj5x/gvUBN4HIO7/wzxiNFPzitTcyPAavQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1wLgD+cqLnd5bgcjVhVxkUDj99pWnulFgh8R3ytltqRXoklMTOcUMW7U9fprH56oF QSY4bXkaKwT3ZI8wocjsD4r4FJJ++Pw9XDvA9mG4ES1YlFmQcOjI7ujlo1Ko9K64Mc XRmVGYNfOtnd+xSrcGuoZHuzivWhdivxBLVUOrY4= 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.19 0120/1157] mbcache: dont reclaim used entries Date: Mon, 15 Aug 2022 19:51:16 +0200 Message-Id: <20220815180444.411280397@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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);