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 60DE4C47DB3 for ; Fri, 2 Feb 2024 14:19:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACE196B006E; Fri, 2 Feb 2024 09:19:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A7E6D6B0071; Fri, 2 Feb 2024 09:19:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96D6A6B0072; Fri, 2 Feb 2024 09:19:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8AD666B006E for ; Fri, 2 Feb 2024 09:19:17 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3239F140FE0 for ; Fri, 2 Feb 2024 14:19:17 +0000 (UTC) X-FDA: 81747071154.07.5F5934E Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by imf30.hostedemail.com (Postfix) with ESMTP id 562768000D for ; Fri, 2 Feb 2024 14:19:15 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of msnitzer@redhat.com designates 209.85.160.172 as permitted sender) smtp.mailfrom=msnitzer@redhat.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706883555; 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; bh=PVCU/QdR6yOLyX27bti1riO+pE3pl8L1u9F5qqx6Qkg=; b=IFmDTNcpMmsJW8DrkkUGDAVlovh6jekWzhRuxwK3FNrKFcV9otX1fY9kkfLCApAMhBRkdX x4OVt5NUqo0HY5LlcCiRwYAakJfSw8MwzI6Nttk3zgxAXuiGUFzXaxnEQGWS79KXaSy9IP +99O0Sol39l1AuV9JW3zEXfEUuWzG8c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706883555; a=rsa-sha256; cv=none; b=w6te3a12y5hiu8S03IRbamrhYILGIF4ocVUvWdjonIwQ7BxKJDsLQfvJHwI8IBuf+NgwFx 5+q87fX5HYab4etfwPBhuW6ORPwRw8otgFfb0xqzsQEIhcmyvZNY6GxVbhpAO86VRc1Sxc 3MTMiJnVPrtgME31U3UdYZDxuEe/kyY= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of msnitzer@redhat.com designates 209.85.160.172 as permitted sender) smtp.mailfrom=msnitzer@redhat.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=kernel.org (policy=none) Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-42a99202ae0so4877481cf.1 for ; Fri, 02 Feb 2024 06:19:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706883554; x=1707488354; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=PVCU/QdR6yOLyX27bti1riO+pE3pl8L1u9F5qqx6Qkg=; b=VKxSJxSL5LbeoNiUGWyh2mOSPikqp6UDGZEH0ziqCRYmb8jf020CNJ3AJNFi4TpK9r Wan8MQfrzAug0elYBZJFIklH8x1lqw90QMvSXdHGEDA+swkvxQHXG7w2KRNlK57Af1IN LINVHYdUYm1VQR51DG7Rghxg1CVxviw4kegu2Ck7PNabyFtQdBzt7LGlRoBU2emaenHx 7cZ2eBxDTN9Q+Pk4N23Dqp5H3vlAHRDgiZjT4Bh0q3iZAgsOhPTaHKO4ECGBv/4CcQFv owDHlSeSZosMCE+OXzWAZ9zjgPgZZou4IHmFvmUb3RC3sackMMUrN/qZAh7Ak7ImQpS4 mhZA== X-Gm-Message-State: AOJu0YwHbeZiH8IIOaNC+iH31tU79FUfpvqR8a6xWjgtCvM6tf+ewINZ /DYoxBTryZd8+GFy8RcwSnFAbEOur4I38jHK3fbVz7WQV4tofycL/6WxoWWHKw== X-Google-Smtp-Source: AGHT+IEhQHanL60HiGDGS5wktHODuGtgnxpWhUHgFtWvSjOpTOhppcIFgAcuMhigP/FHcai4EZhJqw== X-Received: by 2002:a05:622a:1748:b0:42b:f6a6:4058 with SMTP id l8-20020a05622a174800b0042bf6a64058mr3632398qtk.15.1706883554394; Fri, 02 Feb 2024 06:19:14 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCW5ywsfSWxoOXCneHQ193arCv1HiGofCXP9MquEQ/empUbTJttjRivFKD+KnwEX2OLj+A5f1aEr9yLYUa5qZ8AjkA8ZvXZpTKFJQS3dsrO1C30IU+HPlrVB1cjjZmcvyv/AMHE3CvAY/rEYfQBU7wZBv1M8VW+VuJA2ex8qh2Tootn+uaTgnTyf0ZjdSZSztAEe2WvzWJIu6J3TanTtKlobuVMRO8kzofHOpoPGwdv+hSk6SxHREzEqsgUmJn08eE/wOkPXdPwGzSBGaxYiBtNU3APPVYeEV5DsX3JXi59bCFDMOvWJbbOXwf5/2vmHmxX9Eg6VkKsXzntKtE6YpfvxvcTKRzq8ah30mL/Vs572aA== Received: from localhost (pool-68-160-141-91.bstnma.fios.verizon.net. [68.160.141.91]) by smtp.gmail.com with ESMTPSA id ey22-20020a05622a4c1600b0042bed7dc558sm860739qtb.6.2024.02.02.06.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 06:19:14 -0800 (PST) Date: Fri, 2 Feb 2024 09:19:13 -0500 From: Mike Snitzer To: Ming Lei Cc: Andrew Morton , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, David Hildenbrand , Matthew Wilcox , Alexander Viro , Christian Brauner , Don Dutile , Rafael Aquini , Dave Chinner Subject: Re: mm/madvise: set ra_pages as device max request size during ADV_POPULATE_READ Message-ID: References: <20240202022029.1903629-1-ming.lei@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: bnow5ixcnmgtau8sjo4uy4bdj9eeri59 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 562768000D X-Rspam-User: X-HE-Tag: 1706883555-59961 X-HE-Meta: U2FsdGVkX1/FM29QmBMdHppPQpbrrF6k5PWnHgfEt7fCanVuqdGHP3jqJs9pfW+6haggtwyI4lLq7JbiAuun+9gzbnXpNdRHt+PyaqzqS7AxMYl+6B+JbCbmBJ3g6/gRWIMt1Z6UgDewHk25N10cvhAR1eKvbKJMkbDGMj151VXAiS+hlPwLrnAm3NLQD518OqSAsukXBZv2APxNFoiMfGLZm5jBCPTXz56T82ygBtvx+Jy23LJSaEgPEZiFVqjEZ+q0ltwN42ixx6rWN+W336+SGJnM3s344eoArlYZs2p1ZmEUuVOYbtmeVg1cZSLxVrXwmY2mtr35Zj89lMdSVpliE2+KxEq+Prfu57D0duJsCkTNAmvaOb4K7og2ZVzem2OIYEG4TjOClyHSnVetoyzH8qhUiupjUwGzFxE3gWsU8rMKJOUdrnGUitXhBjHoHcWHrRkG02Nnh8V5sfeyc978wPJxMOzEhs8EzBAX+4HUR3W0P3KnPbsUsykbyMfcyz38JuWTnuyMUbMMTnaw5XlLAbsHHPpWafMX1EodVIeuBEvkrItsHFX90F8ic/hi+5x9dSA/rktswkcOZcFeff1e8iNqs3Q/s3xSY+GiemhGyBbJhN4CQRWORuZmUlTuQo1rTkG/QheadmX0L5dS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LfZkzVTqOkbgugv8D586Ji27hmfWWfqh7QOd2V/HDxiGheIxnxvIcSMF/UweBfF2rxn5uPeLPDeAxjs5QixokwN5mg= 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 Fri, Feb 02 2024 at 5:52P -0500, Ming Lei wrote: > On Thu, Feb 01, 2024 at 11:43:11PM -0500, Mike Snitzer wrote: > > On Thu, Feb 01 2024 at 9:20P -0500, > > Ming Lei wrote: > > > > > madvise(MADV_POPULATE_READ) tries to populate all page tables in the > > > specific range, so it is usually sequential IO if VMA is backed by > > > file. > > > > > > Set ra_pages as device max request size for the involved readahead in > > > the ADV_POPULATE_READ, this way reduces latency of madvise(MADV_POPULATE_READ) > > > to 1/10 when running madvise(MADV_POPULATE_READ) over one 1GB file with > > > usual(default) 128KB of read_ahead_kb. > > > > > > Cc: David Hildenbrand > > > Cc: Matthew Wilcox > > > Cc: Alexander Viro > > > Cc: Christian Brauner > > > Cc: Don Dutile > > > Cc: Rafael Aquini > > > Cc: Dave Chinner > > > Cc: Mike Snitzer > > > Cc: Andrew Morton > > > Signed-off-by: Ming Lei > > > --- > > > mm/madvise.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- > > > 1 file changed, 51 insertions(+), 1 deletion(-) > > > > > > diff --git a/mm/madvise.c b/mm/madvise.c > > > index 912155a94ed5..db5452c8abdd 100644 > > > --- a/mm/madvise.c > > > +++ b/mm/madvise.c > > > @@ -900,6 +900,37 @@ static long madvise_dontneed_free(struct vm_area_struct *vma, > > > return -EINVAL; > > > } > > > > > > +static void madvise_restore_ra_win(struct file **file, unsigned int ra_pages) > > > +{ > > > + if (*file) { > > > + struct file *f = *file; > > > + > > > + f->f_ra.ra_pages = ra_pages; > > > + fput(f); > > > + *file = NULL; > > > + } > > > +} > > > + > > > +static struct file *madvise_override_ra_win(struct file *f, > > > + unsigned long start, unsigned long end, > > > + unsigned int *old_ra_pages) > > > +{ > > > + unsigned int io_pages; > > > + > > > + if (!f || !f->f_mapping || !f->f_mapping->host) > > > + return NULL; > > > + > > > + io_pages = inode_to_bdi(f->f_mapping->host)->io_pages; > > > + if (((end - start) >> PAGE_SHIFT) < io_pages) > > > + return NULL; > > > + > > > + f = get_file(f); > > > + *old_ra_pages = f->f_ra.ra_pages; > > > + f->f_ra.ra_pages = io_pages; > > > + > > > + return f; > > > +} > > > + > > > > Does this override imply that madvise_populate resorts to calling > > filemap_fault() and here you're just arming it to use the larger > > ->io_pages for the duration of all associated faulting? > > Yes. > > > > > Wouldn't it be better to avoid faulting and build up larger page > > How can we avoid the fault handling? which is needed to build VA->PA mapping. I was wondering if it made sense to add fadvise_populate -- but given my lack of experience with MM I then get handwavvy quick -- I have more work ahead to round out my MM understanding so that I'm more informed. > > vectors that get sent down to the block layer in one go and let the > > filemap_fault() already tries to allocate folio in big size(max order > is MAX_PAGECACHE_ORDER), see page_cache_ra_order() and ra_alloc_folio(). > > > block layer split using the device's limits? (like happens with > > force_page_cache_ra) > > Here filemap code won't deal with block directly because there is VFS & > FS and io mapping is required, and it just calls aops->readahead() or > aops->read_folio(), but block plug & readahead_control are applied for > handling everything in batch. > > > > > I'm concerned that madvise_populate isn't so efficient with filemap > > That is why this patch increases readahead window, then > madvise_populate() performance can be improved by X10 in big file-backed > popluate read. Right, as you know I've tested your patch, the larger readahead window certainly did provide the much more desirable performance. I'll reply to your v2 (with reduced negative checks) with my Reviewed-by and Tested-by. I was just wondering if there an opportunity to plumb in more a specific (and potentially better) fadvise_populate for dealing with file backed pages. > > due to excessive faulting (*BUT* I haven't traced to know, I'm just > > inferring that is why twiddling f->f_ra.ra_pages helps improve > > madvise_populate by having it issue larger IO. Apologies if I'm way > > off base) > > As mentioned, fault handling can't be avoided, but we can improve > involved readahead IO perf. Thanks, and sorry for asking such a naive question (put more pressure on you to educate than I should have). Mike