Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp614510imw; Thu, 14 Jul 2022 07:41:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1samBc3TER6CRmY0fw4g7Lgvkj7D8RE9fLRgTd26BjUCwV59j0YFJXRTi0VMr44aY8UHxuC X-Received: by 2002:a05:6402:1d51:b0:41f:cf6c:35a5 with SMTP id dz17-20020a0564021d5100b0041fcf6c35a5mr13091519edb.25.1657809691267; Thu, 14 Jul 2022 07:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657809691; cv=none; d=google.com; s=arc-20160816; b=ZGEiAPEYeatBfh6FG9AEc+JKYNo970lg2svWzGcIIUTxL25ppQJT1nxcodua256bAq HhuE7OaIj9g25R7NAhXmdpWefCnIkA2cbpjrrXsaZ83JMBJz+3I5PBy+YgWjuz3I+Afi HA9615J4aViM1ATOKfsr2yXlsaNWri4AONSIj7tP0WdvAm0KN9WVX59rOvaRsXHI35cz +MmQ7+bmZ6d5oLO6PgfOFe4s9UP2El2lm8dEdX1P/646guYpczTAqzyPr0H/pCkgFwyj lYD7AvjFnLgzr6yMKZYQIaKbTdJQg7UJe0NRYVH15kteXf7snT0+V/JNUCoqznNf72kM RwxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=oiA6bm68GhNL1nE09mGZal3jW7PG2ycFzn8PLoBQg4E=; b=ODVL/n1CiBkXD9yoyEpW7v3DU/hGaJesR05XQKXbk6W4CV5I9y7criVx1TKLaF+NSt G2L4kSn5o5DK4vJBR7j4D7J9SPs5YQq2C5Xqp8euRXsMVS2MDmlmW+W3Y136Qfvl6s6x q45wILjJoDF2WZjScvs8HeKmTdWgzHrT5+1d3ySZsUEzDEbQpZD1dxCjEx3QEZNgYBYr JHhE/bnxonbcA8ABJxXfBWvA/eOCiHHqg2Fyn0GjQMcAx0zXjtX447OiBO+9jw2MdGxv 6xauYmlweqlkozZ7LQ6fShtxP24mvI9uhPMS3pYxeuNfT2AxRLUo8aiOb0DgOUxDVtS7 hBFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=QL3DsJuj; dkim=neutral (no key) header.i=@suse.cz header.b=XOqQbPUF; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne35-20020a1709077ba300b00726a62cded2si2807722ejc.554.2022.07.14.07.40.58; Thu, 14 Jul 2022 07:41:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@suse.cz header.s=susede2_rsa header.b=QL3DsJuj; dkim=neutral (no key) header.i=@suse.cz header.b=XOqQbPUF; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231439AbiGNOgQ (ORCPT + 99 others); Thu, 14 Jul 2022 10:36:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237551AbiGNOgP (ORCPT ); Thu, 14 Jul 2022 10:36:15 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39BC549B6E; Thu, 14 Jul 2022 07:36:14 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id CEFA81F889; Thu, 14 Jul 2022 14:36:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1657809372; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oiA6bm68GhNL1nE09mGZal3jW7PG2ycFzn8PLoBQg4E=; b=QL3DsJujqdIQvn52TEio7swg8ge2ikF8ogH0NKasGJZGk7MurF4+qTox7+I3U6ED0ZPRbw aROzuLAJB2+ZGJLJJl2mPhaJ7H2NZLpLshjC4gieOSZxhR5erj28QqtOJNAQ8cBMiCr/qx m6JV4fKYNQ+uOzQO/TfOIs6xN8lwoG8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1657809372; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oiA6bm68GhNL1nE09mGZal3jW7PG2ycFzn8PLoBQg4E=; b=XOqQbPUF62a5LjCXjCEdRpbPxPwXd72QtfWK30wI+YZz3QkbAQFYcq2A2YgdC6jIDqtLZX r79qS1XMknD+cDDw== Received: from quack3.suse.cz (unknown [10.100.224.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id BBB822C141; Thu, 14 Jul 2022 14:36:12 +0000 (UTC) Received: by quack3.suse.cz (Postfix, from userid 1000) id 640A5A0659; Thu, 14 Jul 2022 16:36:12 +0200 (CEST) Date: Thu, 14 Jul 2022 16:36:12 +0200 From: Jan Kara To: Ritesh Harjani Cc: Jan Kara , Ted Tso , linux-ext4@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH 01/10] mbcache: Don't reclaim used entries Message-ID: <20220714143612.oa2u6opi6feqkrvy@quack3> References: <20220712104519.29887-1-jack@suse.cz> <20220712105436.32204-1-jack@suse.cz> <20220714114702.wwd4o3zjdujd34kz@riteshh-domain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220714114702.wwd4o3zjdujd34kz@riteshh-domain> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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-ext4@vger.kernel.org On Thu 14-07-22 17:17:02, Ritesh Harjani wrote: > On 22/07/12 12:54PM, Jan Kara wrote: > > 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 > > --- > > fs/mbcache.c | 10 +++++++++- > > 1 file changed, 9 insertions(+), 1 deletion(-) > > > > diff --git a/fs/mbcache.c b/fs/mbcache.c > > index 97c54d3a2227..cfc28129fb6f 100644 > > --- a/fs/mbcache.c > > +++ b/fs/mbcache.c > > @@ -288,7 +288,7 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache, > > 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(struct mb_cache *cache, > > 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) { > > On taking a look at this patchset again. I think if we move this "if" condition > of checking refcnt to above i.e. before we delete the entry from c_list. > Then we can avoid => > removing of the entry -> checking it's refcnt under lock -> adding it back > if the refcnt is elevated. > > Thoughts? Well, but synchronization would get more complicated because we don't want to acquire hlist_bl_lock() under c_list_lock (technically we could at this point in the series but it would make life harder for the last patch in the series). And we need c_list_lock to remove entry from the LRU list. It could be all done but I don't think what you suggest is really that simpler and this code will go away later in the patchset anyway... Honza -- Jan Kara SUSE Labs, CR