Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2891884rwb; Mon, 15 Aug 2022 13:26:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR7vkoJPsnd7e3IIbGk7a1w8G2kjz5OM8pW79cixjrVNod6SxG90LM6FPMS8XzCfesodrsxv X-Received: by 2002:a17:907:6818:b0:730:d99f:7b91 with SMTP id qz24-20020a170907681800b00730d99f7b91mr11305433ejc.496.1660595194335; Mon, 15 Aug 2022 13:26:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660595194; cv=none; d=google.com; s=arc-20160816; b=P3A9ESYYSOKjGwE6YONsgw1K8/FJVJj92yJ9C/pxU3YikwyRbhm8QaZ03i+Wvg32b7 3pG7CCifIuFjid5FURWGEIwMeLlJUojqmbWktT3iFOIF/mzzS2Y0gOb60SNUpiJqbXlV xXDQMO7ZSvvME9/oXzjvncEtXaTUn3zvJUzDVCKNDE7yJojQXkD0y8KGk0Whn+q+SyWy BTBRv/O7/E5FHqjQACDAvSKtJ/GoYjHWdE0RZvLzYjEc5JlhnfYwtXWLaDK0a7UAW7wW iGDQEAIcrmDAQOaxcO86UYSh74h02DnNhV9QYaBrqoBBHYYBkkGc6iUExGIMv3hoqFwa ynOQ== 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=ibcFdEPVAOAbLSBJplDO9cgsEjtKHcH5Vq/coaM7trS/68W3ZCzqFsdwVIrLmeRy7n uoyc8TmjFVdqLZ6QWQvXcV9JL7RyTusYXLneCwfJbKbmltXAhQZ06DnCT/CpQG4rvRpN uO9b1FBz6yN2cggFlB4ftJXERbXZ39viDswBFxHxvYxhFxqOYspB7tkjupKgUxGwJNuO Ej3yBVHr1zVrZfQKLR0PmIW73T4kIHE5r2k8H56oSNCQxE8j/kIor/UPpJxVXQiQY29T 2qq/tTq2txta1IIixztO9ogH+6LsLSX6A5Tn8mLumykd1xh0Vcomug3n+nxM3GP5RXyc Ye/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XwqYkVCI; 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 l9-20020aa7c3c9000000b0043e01070ae6si8026101edr.512.2022.08.15.13.26.05; Mon, 15 Aug 2022 13:26:34 -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=XwqYkVCI; 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 S1347282AbiHOUX5 (ORCPT + 99 others); Mon, 15 Aug 2022 16:23:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346442AbiHOUPq (ORCPT ); Mon, 15 Aug 2022 16:15:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F42B91D02; Mon, 15 Aug 2022 11:59: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 528736123F; Mon, 15 Aug 2022 18:59:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 536F1C433C1; Mon, 15 Aug 2022 18:59:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660589973; bh=uwI7jOt3LUj5x/gvUBN4HIO7/wzxiNFPzitTcyPAavQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XwqYkVCIPh5kXbACtmlzGHthqnVMEM/Ozx5Mx0upP0meO3aj41CcaJfo2k2QDjNI/ PdA8bJuck9SL9RFlNa4ddZwqhOULSgUWCtoiHN6DuNiiDmxR8jdOkZyLP/06Wuk3x7 aXZ6Ku05YvXSTweTWh8pCZj+FpRXQY9IixobWVFo= 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.18 0110/1095] mbcache: dont reclaim used entries Date: Mon, 15 Aug 2022 19:51:49 +0200 Message-Id: <20220815180434.122910839@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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);