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 4961AC77B75 for ; Fri, 21 Apr 2023 08:53:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9BB866B0071; Fri, 21 Apr 2023 04:53:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 96BC36B0072; Fri, 21 Apr 2023 04:53:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 834356B0074; Fri, 21 Apr 2023 04:53:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 715876B0071 for ; Fri, 21 Apr 2023 04:53:46 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3A9FE808D3 for ; Fri, 21 Apr 2023 08:53:46 +0000 (UTC) X-FDA: 80704785252.13.8CA61A4 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf05.hostedemail.com (Postfix) with ESMTP id 44199100009 for ; Fri, 21 Apr 2023 08:53:44 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=DD3XydQv; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=X9A5npHx; spf=pass (imf05.hostedemail.com: domain of jack@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682067224; 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=TCgmgxLZjgBpHMVFd5dl+S+78y8snFvoa5hj4IkLKoE=; b=VIwE1o0LuWHOYGWno0q4EcYu2gZYA/gUl146qg5xwUZOrRuO67N9tQfw2LcHkRN3eHXZR9 K6b0+uquRYEl+ZdknQGYg2IqVS1MS/M60/nltMtLtRXRmG0GhugKn2gHSrLYiRDRGfghvf 3Ztovoeqhhhns8ZNKaSK7/iR1HuMpwo= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=DD3XydQv; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=X9A5npHx; spf=pass (imf05.hostedemail.com: domain of jack@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682067224; a=rsa-sha256; cv=none; b=khYCt/YitkV0epvDBqZ5jVN+R6TZPH00hQ09KzUyh5grvrsgQkPoMf2/vtLFOPv7wmScBI YdNf4ydJokuGfy8wYFDRHjr0fr7uBQ/dlxxrvR01Pi8qKRarifSpx5kH+dDaKCMeTwjr1s YFVrIFmI9KymDKyNWQ5VpaQeByUreLE= 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 8E75821A45; Fri, 21 Apr 2023 08:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1682067222; 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=TCgmgxLZjgBpHMVFd5dl+S+78y8snFvoa5hj4IkLKoE=; b=DD3XydQvq2QEpcTvPifPVBUDTl+Q1vC8UkEnUANJmx94wjnPGZMZIdPgbbIjDTb6puvIEX N0IA1hP0Gyew7LmVfFz6UQqOWSYav9dSa+4gOBWY2nM+bid/rQgR+n896ET5c8MDUjLGhD +1gtKZkb0byMBdkk5cHcQhLuievKAbA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1682067222; 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=TCgmgxLZjgBpHMVFd5dl+S+78y8snFvoa5hj4IkLKoE=; b=X9A5npHx6rz1+iay8T2pmWurjIpbJdx/lP8Xi7ZG6oyuIl696EnQV4LsYls8Itl45mA1vJ dpFF1YcwgA4pfhBA== 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 7D84C13456; Fri, 21 Apr 2023 08:53:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IRKIHhZPQmTsPAAAMHmgww (envelope-from ); Fri, 21 Apr 2023 08:53:42 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 06E2FA0729; Fri, 21 Apr 2023 10:53:42 +0200 (CEST) Date: Fri, 21 Apr 2023 10:53:41 +0200 From: Jan Kara 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: <20230421085341.b2zvzeuc745bs6sa@quack3> References: <20230403220337.443510-1-yosryahmed@google.com> <20230403220337.443510-2-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230403220337.443510-2-yosryahmed@google.com> X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 44199100009 X-Stat-Signature: i7h4txsroinyw1ckaf8eqr9gjzfmskyu X-HE-Tag: 1682067224-569724 X-HE-Meta: U2FsdGVkX1+yB0OO4kfcPfSNLgWC6lVh0w3Uk3c0u8tOaOVM5WxuqWMUOZd5P80Q2T6OjrMJXWJSQH7ug76K7Q5ZFiv+50d8xpo4myDYfYYlCrIvLOSAV9JjsQ3ZbocaOqgzgdpC3W9T2zBVSb54J8USodeSLD+NKqlwDVWzN1zySjkKVR1JpxykzncM3lVM8mgRKPBrIsLlftecw4rPzcv/KfUQf3F7/05c4zwKVnZ3c07IPIJGGyelhKmf1l7CrGUKvaDE0Fb37iEDWIVz2fWWgf4q8Tup2GjG6EZ5EDtBs5SUjUgOPkStYJA3jfSp8u1imZpbHcGzd0aIOqOin8xh/m76lT3P2BAfcHcTlmChpD6McRBvFdf8j8ybq+zDW9Qd7pZ9IarADncWwk6m0MzIcq1AUhFZOWjqwnTb3WcJMAwf6Wm4PCt7oCvwC5y4McH6u3XpoJN+e8tf+G1VR0FmzZQX2U9/vDnjysvGhMOw+UCIeSP8EEsdQTTUNZ6iH+x2IyasknpmtI22RPU3VsJSS0xyPPrfeHItuBlhOSc3oPByOJJCSMdU8d50x58Dji5f9EO84uIQcz/Jq6MI02fKtDG8WEg+z+xo9wYf34jmmTGA+acp71JyJQZYcLR/ey4tA9KwiruzjI43QGcgwahe13FNqyjT5tJeykNbcVRrENAlv/GRlzXVYDSeod+43cHJ6EvC7gwi77ym7M5C43/pMh/ZgJMjVJ1BFjrRoAegjfbQT97BumksuxGh6XpU+50WHqhsg06NcNApVgwcfz2IK7raCAd0KbIpX6GvzqEGwSdnrh+wmNBVGoRkPfqRegI4MFAtBhqb//XRW02sm5FFbyr9b7y0NQY64kXcy3vhZwiYcPcldtjbiUhDy8UFy371cP06GhBI7NFolAoDwH872Q81/yQHqur3fgakajIF5JODqb+kzHXm+F2LZTsC29vtyk0FY+BUczslg6D mPzaNWjI hNt43s6QVUsHVxhnHHTw6PKvATW3AEOJb7aB/cLp+12PIEKfi8zYCw6ttAYF69vznQZ1LDhOeoKbx+7TAIvspDtBx9jWwUtqK0OpSKRmcMMfAC4WTFsOOc1xUYgCeC9zmbBrugvhjHzJ3i/ia+vL71V8y2fksOdsi1lX7anFDM+D+JvBOY9NKFAMafafVCeNCM4VQu/S44e7gNJkV9ZEuLMqaSLdPfGe22bynzPXJfnZfeNAHGXtb3BiKMHB7Gs+ZRU2Pg/xN7hn5o+ho3nBFmDwU4HXvT0p9z/IqMbGR5MRsj90ZW2SoP4aW5XlE6buTQBU9 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: On Mon 03-04-23 22:03:33, 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. > > 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. > > Signed-off-by: Yosry Ahmed The patch looks good to me. Nice find. Feel free to add: Reviewed-by: Jan Kara Honza > --- > fs/fs-writeback.c | 16 +++++++++++----- > 1 file changed, 11 insertions(+), 5 deletions(-) > > 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; > > 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; > > + > + 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; > + } > + > /* > * No more inodes for IO, bail > */ > - if (list_empty(&wb->b_more_io)) > + if (list_empty(&wb->b_more_io)) { > + spin_unlock(&wb->list_lock); > break; > + } > + > /* > * Nothing written. Wait for some inode to > * become available for writeback. Otherwise > @@ -2093,9 +2101,7 @@ static long wb_writeback(struct bdi_writeback *wb, > spin_unlock(&wb->list_lock); > /* This function drops i_lock... */ > inode_sleep_on_writeback(inode); > - spin_lock(&wb->list_lock); > } > - spin_unlock(&wb->list_lock); > blk_finish_plug(&plug); > > return nr_pages - work->nr_pages; > -- > 2.40.0.348.gf938b09366-goog > -- Jan Kara SUSE Labs, CR