Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1951878ybj; Wed, 6 May 2020 08:08:17 -0700 (PDT) X-Google-Smtp-Source: APiQypKsyj5IPihYg4XLg5/8RDkDYtPNh/Qn6ThIOdc055Jg5eOgGyN7vsCHSRcSZ9T9PtNmauHW X-Received: by 2002:a17:906:8611:: with SMTP id o17mr7641860ejx.221.1588777697700; Wed, 06 May 2020 08:08:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588777697; cv=none; d=google.com; s=arc-20160816; b=ccY9tcUBERM5sySA+8RkXo3sFnJOHiimfbnSbOejRT1cnPv+A4aJ+onowZU3GftnT1 5izPPwikWrt/BkUPf8YWsw2Cf3dTVjb7ZbF+3mvF1SExW22TSzjiRVbcRnr2XAdWh/dD QnmlaCSi3fQXUMlGyAY1dvgQY2eUp22MlmM3L9t06MC4v/+smmYPWmKMvDDMArq3W/Yw zbiJaaXmfTFncyZTBiRMhOdc+aE9EkARKuFpLnyOBNzug9mubGzmJTVlfvdQgZNAzO3z 0FaMQcmKwpwGb2GOINk4VZCKJmCasRwE6e+yeqi2e48XJmrdIKzbC+qP6pqiAhTNEO1d Dudw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=jGqdkh7TTJ45vjKzWmcK2DTojE2aSuNTDGkblxNI2xg=; b=XxaKI93i7wvI0G2zuIyU9BkPXFxe8eXdM3V1lUYDRvD8Po1FpTatzUq6jl79SzdM4o Uf2a3SwV5hYuTlroKhPQsbt+YmyRz3EPo6PtrjLoL9M6wxHlAEEfNHWJRKJXXDhr5LJj VaTB2crXz8zUjr/3DKNpul8xow7pIE/PvmF956kKFsJJbM+ItHFeIm12XHB4mRDeEnVy Yy6/GqIQD1RuGDyd6AeUis1kFP0WpVz21UFyzYjStQ/kaRcZW3jKzYYuy1tupDLm21wD ZjqvCTE9dpWrkftYd3y+D/C28HKVpbLEHpHoAVxV85Qy0Ng5gOuUINoKLurHxylxMo2C 1bqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qPtEdxFY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g25si1259824ejo.389.2020.05.06.08.07.46; Wed, 06 May 2020 08:08:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qPtEdxFY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729333AbgEFPFW (ORCPT + 99 others); Wed, 6 May 2020 11:05:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:58438 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727984AbgEFPFW (ORCPT ); Wed, 6 May 2020 11:05:22 -0400 Received: from localhost (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 896382076D; Wed, 6 May 2020 15:05:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588777521; bh=9EYI9KnuzJ4wy8Y0tCTKcy7C5bKDBzJt+DTI14fSzfM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qPtEdxFYcKZWnPZ5jgQGUjbOSBqPbRDEAyTkAUCtJbI03Q56n2YlsQ2FvsdBNXHWn vWUNTOfRtidssL08ENE6w1qvV7oUwIygRe6LUzl6D+k9zmzaqN3F3hPuqHK0MCasmE EPArj5nScAa0HLtN1YCR5i3fdeknEFxMMiU3KN9E= Date: Wed, 6 May 2020 08:05:21 -0700 From: Jaegeuk Kim To: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, chao@kernel.org Subject: Re: [PATCH v2] f2fs: shrink spinlock coverage Message-ID: <20200506150521.GE107238@google.com> References: <20200506104542.123575-1-yuchao0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200506104542.123575-1-yuchao0@huawei.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/06, Chao Yu wrote: > In f2fs_try_to_free_nids(), .nid_list_lock spinlock critical region will > increase as expected shrink number increase, to avoid spining other CPUs > for long time, it's better to implement like extent cache and nats > shrinker. > > Signed-off-by: Chao Yu > --- > v2: > - fix unlock wrong spinlock. > fs/f2fs/node.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c > index 4da0d8713df5..ad0b14f4dab8 100644 > --- a/fs/f2fs/node.c > +++ b/fs/f2fs/node.c > @@ -2488,7 +2488,6 @@ void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid) > int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink) > { > struct f2fs_nm_info *nm_i = NM_I(sbi); > - struct free_nid *i, *next; > int nr = nr_shrink; > > if (nm_i->nid_cnt[FREE_NID] <= MAX_FREE_NIDS) > @@ -2498,14 +2497,22 @@ int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink) > return 0; > > spin_lock(&nm_i->nid_list_lock); > - list_for_each_entry_safe(i, next, &nm_i->free_nid_list, list) { > - if (nr_shrink <= 0 || > - nm_i->nid_cnt[FREE_NID] <= MAX_FREE_NIDS) > + while (nr_shrink) { > + struct free_nid *i; > + > + if (nm_i->nid_cnt[FREE_NID] <= MAX_FREE_NIDS) > break; > > + i = list_first_entry(&nm_i->free_nid_list, > + struct free_nid, list); > + list_del(&i->list); > + spin_unlock(&nm_i->nid_list_lock); > + > __remove_free_nid(sbi, i, FREE_NID); __remove_free_nid() will do list_del again. btw, how about just splitting out given nr_shrink into multiple trials? > kmem_cache_free(free_nid_slab, i); > nr_shrink--; > + > + spin_lock(&nm_i->nid_list_lock); > } > spin_unlock(&nm_i->nid_list_lock); > mutex_unlock(&nm_i->build_lock); > -- > 2.18.0.rc1