From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D4DFC77B73 for ; Wed, 19 Apr 2023 11:38:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2440E8E0005; Wed, 19 Apr 2023 07:38:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CE8A8E0001; Wed, 19 Apr 2023 07:38:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06E9D8E0005; Wed, 19 Apr 2023 07:38:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E52278E0001 for ; Wed, 19 Apr 2023 07:38:17 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A88B4C0240 for ; Wed, 19 Apr 2023 11:38:17 +0000 (UTC) X-FDA: 80697942234.16.69262EA Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf29.hostedemail.com (Postfix) with ESMTP id BD7B412001E for ; Wed, 19 Apr 2023 11:38:14 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=GL5fAGiW; spf=pass (imf29.hostedemail.com: domain of mkoutny@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mkoutny@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681904295; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CawZP8F8+xYMOVFHt2q5TqVfXamwgFnKSbMRqGDkkis=; b=FIao5/EvzK/o/6hulYRxzd97NEd716P1MbqIhE8o8P7tkScbHJl4kfQbiH/41hHcIGmSgq X0FnSts2Tyz68Z8GuVqRwzjWRq8/uxuEcCGCu6fVRdTk6YH6XqcDt97DVVrRJ29qYQeDfT /tz/xgeWSgP+WswnlmJECB2LCj1r5b8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=GL5fAGiW; spf=pass (imf29.hostedemail.com: domain of mkoutny@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mkoutny@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681904295; a=rsa-sha256; cv=none; b=Utm7ITvSStnkIUt1NYsTBYRBby993gzsLt2aGe8pZ5r7180S0Qx9vEy/SqDM4X1jl6qByp xZA7Z8Tz+kRe583KxHykRBbW+9XvW0nZ0hpsLrfHRPFpqOAYq6oJ53czGlXc8r2yLrgaLX KCcvi1kMp1UvTgktsFTPNuC+7rU80FU= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 26D8021996; Wed, 19 Apr 2023 11:38:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1681904293; 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=CawZP8F8+xYMOVFHt2q5TqVfXamwgFnKSbMRqGDkkis=; b=GL5fAGiWO2P5IiS5km6lqEZciICNE40kwVeLHDhHCVOZVt8jDUYanFIa1YaVUirxyzdxNF AemECDuu3TqA6SneZwBNJ3xttSlMUd3KMgmbg2ZfxFhIB73Azy1a5wAUPUd/zTbVMBZYbe ROOnf24qNyDC+lbl2/LAR9jU4dAfhI8= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E0F4613580; Wed, 19 Apr 2023 11:38:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id jWkQNqTSP2TZXAAAMHmgww (envelope-from ); Wed, 19 Apr 2023 11:38:12 +0000 Date: Wed, 19 Apr 2023 13:38:11 +0200 From: Michal =?utf-8?Q?Koutn=C3=BD?= To: Yosry Ahmed Cc: Alexander Viro , Christian Brauner , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH mm-unstable RFC 1/5] writeback: move wb_over_bg_thresh() call outside lock section Message-ID: <7woe6ljcarqsr6uep7uns7bc3hm6xqog6ufk4rhwfo4vxixczw@tdjkdhx2euok> References: <20230403220337.443510-1-yosryahmed@google.com> <20230403220337.443510-2-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="um3hlfownhi7iyh5" Content-Disposition: inline In-Reply-To: <20230403220337.443510-2-yosryahmed@google.com> X-Rspamd-Queue-Id: BD7B412001E X-Stat-Signature: pj5xo38m7ujijbs73ymfakb7rw1tbzmu X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1681904294-950632 X-HE-Meta: U2FsdGVkX18WDhsxa6YXScQ60YublSf/hww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fAvClE0eOjCzw/FdhDvkvHoxQB58elUBCUG6mCgvXpHpr9pgS9l3/QbO7VzsfQ3ztlSxiR8+t1ZBADL83W+kr8r9dg1xb62xWV91G9EJb+0mVB9fa4Ss7fiuWaLqAU6DwubIPXy1qbkm07MEsY2BMSpGgYSusaiJGEuWlEI0MLh/2D5PRmCZpaZSnID6jloHL9KxRtw/+Xf/cMfzykytYzRIPvrKWV3YQwW29UMGo+Oh9A3R8PDFu2KPMZCtE5ir6b96PPhavn3J+moUlcjpy8v37nPh63YGzaCMDMY55yJW0AzELUNdyrnxmuQz1hcOmD2pWQV1AvTFI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: --um3hlfownhi7iyh5 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Apr 03, 2023 at 10:03:33PM +0000, Yosry Ahmed wrote: > wb_over_bg_thresh() calls mem_cgroup_wb_stats() which invokes an rstat > flush, which can be expensive on large systems. Currently, > wb_writeback() calls wb_over_bg_thresh() within a lock section, so we > have to make the rstat flush atomically. On systems with a lot of > cpus/cgroups, this can cause us to disable irqs for a long time, > potentially causing problems. >=20 > Move the call to wb_over_bg_thresh() outside the lock section in > preparation to make the rstat flush in mem_cgroup_wb_stats() non-atomic. > The list_empty(&wb->work_list) should be okay outside the lock section > of wb->list_lock as it is protected by a separate lock (wb->work_lock), > and wb_over_bg_thresh() doesn't seem like it is modifying any of the b_* > lists the wb->list_lock is protecting. Also, the loop seems to be > already releasing and reacquring the lock, so this refactoring looks > safe. >=20 > Signed-off-by: Yosry Ahmed > --- > fs/fs-writeback.c | 16 +++++++++++----- > 1 file changed, 11 insertions(+), 5 deletions(-) >=20 > diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c > index 195dc23e0d831..012357bc8daa3 100644 > --- a/fs/fs-writeback.c > +++ b/fs/fs-writeback.c > @@ -2021,7 +2021,6 @@ static long wb_writeback(struct bdi_writeback *wb, > struct blk_plug plug; > =20 > blk_start_plug(&plug); > - spin_lock(&wb->list_lock); > for (;;) { > /* > * Stop writeback when nr_pages has been consumed > @@ -2046,6 +2045,9 @@ static long wb_writeback(struct bdi_writeback *wb, > if (work->for_background && !wb_over_bg_thresh(wb)) > break; > =20 > + > + spin_lock(&wb->list_lock); > + > /* > * Kupdate and background works are special and we want to > * include all inodes that need writing. Livelock avoidance is > @@ -2075,13 +2077,19 @@ static long wb_writeback(struct bdi_writeback *wb, > * mean the overall work is done. So we keep looping as long > * as made some progress on cleaning pages or inodes. > */ > - if (progress) > + if (progress) { > + spin_unlock(&wb->list_lock); > continue; > + } > + This would release wb->list_lock temporarily with progress but that's already not held continuously due to writeback_sb_inodes(). Holding the lock could even be shortened by taking it later after trace_writeback_start(). Altogether, the change looks OK, Reviewed-by: Michal Koutn=FD --um3hlfownhi7iyh5 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQTrXXag4J0QvXXBmkMkDQmsBEOquQUCZD/SoAAKCRAkDQmsBEOq ud9HAQDjyg6QsqLgZUGry6hNbONC5QVd0E2+HvxdLRrVBbVMTwD/dXaHa+QsVZiZ ADTParKHoShcH9b0N7u/scBSdpKHhgM= =xwT4 -----END PGP SIGNATURE----- --um3hlfownhi7iyh5--