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 16F97C47DDF for ; Thu, 1 Feb 2024 09:37:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0C056B0083; Thu, 1 Feb 2024 04:37:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9BB616B0085; Thu, 1 Feb 2024 04:37:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85C216B0087; Thu, 1 Feb 2024 04:37:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 763546B0083 for ; Thu, 1 Feb 2024 04:37:54 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 184421207FB for ; Thu, 1 Feb 2024 09:37:54 +0000 (UTC) X-FDA: 81742733268.10.9F8C351 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf12.hostedemail.com (Postfix) with ESMTP id BF3EB40007 for ; Thu, 1 Feb 2024 09:37:51 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=DgbICBFw; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=LQoeTL6v; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=DgbICBFw; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=LQoeTL6v; spf=pass (imf12.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 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=1706780272; 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=mw5Km38+9mHgHXuGiLgV165ByO4XGRf+Ps4iZpq/mhw=; b=wlZVNqd5ISgckBeps9wxhF1/jtp5FjDoddhh/h6EEgbrMHjMVFl6wP7UosQXvHezXrzU7R pgDXpHyf+lxRJk0wrftZd9L5kBr9Y8n0q5fCoji/xTc2rYx64mXahPzUFLXEt9M2Vzd1Sp emjwQzX99js+mBDad6irYLEo/a6hu74= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706780272; a=rsa-sha256; cv=none; b=JyvOAlndggHwjI1du1xdXXvObx5qAA7FizDuljLFB9yFf1tl39I5HWy4FO4dLQ3dWYJ0Xq wcHqRmivGRYabs4ze2x4yn+kQwrOJkAZYXzkhKgDwGfKuB9aC7wPR519xEixgOF71PMmfu Q375gsAbbDOOfa2L4399NxzdDjft6U0= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=DgbICBFw; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=LQoeTL6v; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=DgbICBFw; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=LQoeTL6v; spf=pass (imf12.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id C1EC122168; Thu, 1 Feb 2024 09:37:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1706780269; 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=mw5Km38+9mHgHXuGiLgV165ByO4XGRf+Ps4iZpq/mhw=; b=DgbICBFwQUioRqWHnu/WREm50kyZ9FBXR7GJM7GRGBSlhVnnckOkWAnXNpEppLsHNUKJKB 9c6yI/w6oivyqUea/bdrplZ2IGL0Nun4Lis/jADxpi8dujdpSnN5Br4uY13egIuBIDtXs1 V4g1HwPYMNwQCv1cYEMSRBBUL2Rl118= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1706780269; 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=mw5Km38+9mHgHXuGiLgV165ByO4XGRf+Ps4iZpq/mhw=; b=LQoeTL6vqQbbhc31167aNVBkOPwDjV1PNhX9ShezoGmZ0jnq8E3YC93JBL0dc42Tl1KLg1 hJV5h+RXV3u09ZBQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1706780269; 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=mw5Km38+9mHgHXuGiLgV165ByO4XGRf+Ps4iZpq/mhw=; b=DgbICBFwQUioRqWHnu/WREm50kyZ9FBXR7GJM7GRGBSlhVnnckOkWAnXNpEppLsHNUKJKB 9c6yI/w6oivyqUea/bdrplZ2IGL0Nun4Lis/jADxpi8dujdpSnN5Br4uY13egIuBIDtXs1 V4g1HwPYMNwQCv1cYEMSRBBUL2Rl118= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1706780269; 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=mw5Km38+9mHgHXuGiLgV165ByO4XGRf+Ps4iZpq/mhw=; b=LQoeTL6vqQbbhc31167aNVBkOPwDjV1PNhX9ShezoGmZ0jnq8E3YC93JBL0dc42Tl1KLg1 hJV5h+RXV3u09ZBQ== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id B612A13594; Thu, 1 Feb 2024 09:37:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id w1BrLG1mu2VrVAAAn2gu4w (envelope-from ); Thu, 01 Feb 2024 09:37:49 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 64447A0809; Thu, 1 Feb 2024 10:37:49 +0100 (CET) Date: Thu, 1 Feb 2024 10:37:49 +0100 From: Jan Kara To: Liu Shixin Cc: Alexander Viro , Christian Brauner , Jan Kara , Matthew Wilcox , Andrew Morton , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 2/2] mm/readahead: limit sync readahead while too many active refault Message-ID: <20240201093749.ll7uzgt7ixy7kkhw@quack3> References: <20240201100835.1626685-1-liushixin2@huawei.com> <20240201100835.1626685-3-liushixin2@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240201100835.1626685-3-liushixin2@huawei.com> X-Rspamd-Queue-Id: BF3EB40007 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 787dcmysnf9dcgsjzegfm78dqh9yrymd X-HE-Tag: 1706780271-157249 X-HE-Meta: U2FsdGVkX183jyLEhAzRtxgxCa3UnoMpjn0RRRlzwBYy8QquHBegMYSgOtw2gLMipsMfYMT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IiR4W3JM2xsxReONdB1NMDX3qByzzB3hzbMGcSW4sXOj/QQUMjsFTKQz+ezrCutEf2BpxtL2R3LSxl+Rrp3uyQTyFS5mfdoFZBeJDruXhdp/nIG4aAFfnNyk5A== 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: List-Subscribe: List-Unsubscribe: On Thu 01-02-24 18:08:35, Liu Shixin wrote: > When the pagefault is not for write and the refault distance is close, > the page will be activated directly. If there are too many such pages in > a file, that means the pages may be reclaimed immediately. > In such situation, there is no positive effect to read-ahead since it will > only waste IO. So collect the number of such pages and when the number is > too large, stop bothering with read-ahead for a while until it decreased > automatically. > > Define 'too large' as 10000 experientially, which can solves the problem > and does not affect by the occasional active refault. > > Signed-off-by: Liu Shixin So I'm not convinced this new logic is needed. We already have ra->mmap_miss which gets incremented when a page fault has to read the page (and decremented when a page fault found the page already in cache). This should already work to detect trashing as well, shouldn't it? If it does not, why? Honza > --- > include/linux/fs.h | 2 ++ > include/linux/pagemap.h | 1 + > mm/filemap.c | 16 ++++++++++++++++ > mm/readahead.c | 4 ++++ > 4 files changed, 23 insertions(+) > > diff --git a/include/linux/fs.h b/include/linux/fs.h > index ed5966a704951..f2a1825442f5a 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -960,6 +960,7 @@ struct fown_struct { > * the first of these pages is accessed. > * @ra_pages: Maximum size of a readahead request, copied from the bdi. > * @mmap_miss: How many mmap accesses missed in the page cache. > + * @active_refault: Number of active page refault. > * @prev_pos: The last byte in the most recent read request. > * > * When this structure is passed to ->readahead(), the "most recent" > @@ -971,6 +972,7 @@ struct file_ra_state { > unsigned int async_size; > unsigned int ra_pages; > unsigned int mmap_miss; > + unsigned int active_refault; > loff_t prev_pos; > }; > > diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h > index 2df35e65557d2..da9eaf985dec4 100644 > --- a/include/linux/pagemap.h > +++ b/include/linux/pagemap.h > @@ -1256,6 +1256,7 @@ struct readahead_control { > pgoff_t _index; > unsigned int _nr_pages; > unsigned int _batch_count; > + unsigned int _active_refault; > bool _workingset; > unsigned long _pflags; > }; > diff --git a/mm/filemap.c b/mm/filemap.c > index 750e779c23db7..4de80592ab270 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -3037,6 +3037,7 @@ loff_t mapping_seek_hole_data(struct address_space *mapping, loff_t start, > > #ifdef CONFIG_MMU > #define MMAP_LOTSAMISS (100) > +#define ACTIVE_REFAULT_LIMIT (10000) > /* > * lock_folio_maybe_drop_mmap - lock the page, possibly dropping the mmap_lock > * @vmf - the vm_fault for this fault. > @@ -3142,6 +3143,18 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) > if (mmap_miss > MMAP_LOTSAMISS) > return fpin; > > + ractl._active_refault = READ_ONCE(ra->active_refault); > + if (ractl._active_refault) > + WRITE_ONCE(ra->active_refault, --ractl._active_refault); > + > + /* > + * If there are a lot of refault of active pages in this file, > + * that means the memory reclaim is ongoing. Stop bothering with > + * read-ahead since it will only waste IO. > + */ > + if (ractl._active_refault >= ACTIVE_REFAULT_LIMIT) > + return fpin; > + > /* > * mmap read-around > */ > @@ -3151,6 +3164,9 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf) > ra->async_size = ra->ra_pages / 4; > ractl._index = ra->start; > page_cache_ra_order(&ractl, ra, 0); > + > + WRITE_ONCE(ra->active_refault, ractl._active_refault); > + > return fpin; > } > > diff --git a/mm/readahead.c b/mm/readahead.c > index cc4abb67eb223..d79bb70a232c4 100644 > --- a/mm/readahead.c > +++ b/mm/readahead.c > @@ -263,6 +263,10 @@ void page_cache_ra_unbounded(struct readahead_control *ractl, > folio_set_readahead(folio); > ractl->_workingset |= folio_test_workingset(folio); > ractl->_nr_pages++; > + if (unlikely(folio_test_workingset(folio))) > + ractl->_active_refault++; > + else if (unlikely(ractl->_active_refault)) > + ractl->_active_refault--; > } > > /* > -- > 2.25.1 > -- Jan Kara SUSE Labs, CR