Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2101542rdb; Sun, 4 Feb 2024 15:35:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEU2gA11sTMiBVwOHJENt8vE96KAKJlqkHDAWug5fp9bSF6pqHelJpUvPOpuUXW2axdEtmj X-Received: by 2002:a17:90a:d984:b0:296:452a:9662 with SMTP id d4-20020a17090ad98400b00296452a9662mr6164772pjv.2.1707089716808; Sun, 04 Feb 2024 15:35:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707089716; cv=pass; d=google.com; s=arc-20160816; b=fR4Uey8+dWuahctrE5JgTeXcK3JT3szTbh5WqF1pkaZdD8nzcfbnzqlpq+GvP+KMD2 vfPVUlZ9Igoiu8NP++55grhhci4Iww30geYW2BorTcokire3ag9hleUD9DUf9OI8iWgd rueyBB2NLXoBSzwGOkEOpABHrq3S8HLUaj4i35qUcIxZOtykNEKHdyMPvIgGi3NLDYt3 nUYoNqLpiPZNClgHDiPqOBF8PjDOPGOEjBW4teYhVAa7aQE3+hDZ72++mGiq53B33Xkz +ojhvLZ4BCr2wu63SsIvUJk4dRP5iaoUlRaCAqTpotJPDYvjJMz7jKiLdwd4oHUg6zS0 6p4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=p2TnSnFYEsDimdpS3N17Ru85rGMnUNIuGwXCS2vJfQo=; fh=O8icGbqGGa/eaQNnpcTWYAIdCjyRs8BM1RWRLHBAO8o=; b=fG0a5ZiCAlmdl/hu/nzkfYI8h4ysq4ZruGJiUBytcoO2cnE0v1VyXT/jkKhjwugFK7 qrQSjRslxgRGiov7/mExiuSozbFpHmcUv3RhGq8CT8I5tUfbQ19UW7jvjCPmo80yLU69 +MqqEGosiuv0PWFOSIRLX6phIWOgd86uK01V/ZT0ZcccOpQI+f02yx0sZWDCwBzEq1ti d94HqNRoSX7jlwo9vtRhwjRhHAigY1t4oXDhZ4iXFMOtUQQWfyZJIWXaw/zpZRUJVUOj PAskDBmBCsMSENOE/mBrfBvlmeLVEujlsEV1gNrwaI0BXWrZfJUEqXYTN9FrFb9Ynqhb rHRw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fromorbit-com.20230601.gappssmtp.com header.s=20230601 header.b=FRw0G62Y; arc=pass (i=1 spf=pass spfdomain=fromorbit.com dkim=pass dkdomain=fromorbit-com.20230601.gappssmtp.com dmarc=pass fromdomain=fromorbit.com); spf=pass (google.com: domain of linux-kernel+bounces-51946-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51946-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fromorbit.com X-Forwarded-Encrypted: i=1; AJvYcCVKbCXnvoOWJv9yy8JjrgM7s1p2q2RkcSxHo45VQ2rD2jAj4LnIaxLRez9AxRx4e1LMrwfi+QPCZcMfmZEWd3LMayXDpqA/lQgiQ0FfmA== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e11-20020a63544b000000b005cdc2cc9a1dsi5084283pgm.699.2024.02.04.15.35.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 15:35:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51946-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@fromorbit-com.20230601.gappssmtp.com header.s=20230601 header.b=FRw0G62Y; arc=pass (i=1 spf=pass spfdomain=fromorbit.com dkim=pass dkdomain=fromorbit-com.20230601.gappssmtp.com dmarc=pass fromdomain=fromorbit.com); spf=pass (google.com: domain of linux-kernel+bounces-51946-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51946-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fromorbit.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D8A0DB21130 for ; Sun, 4 Feb 2024 23:35:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5CD3ACA73; Sun, 4 Feb 2024 23:34:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fromorbit-com.20230601.gappssmtp.com header.i=@fromorbit-com.20230601.gappssmtp.com header.b="FRw0G62Y" Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2AC3BE5A for ; Sun, 4 Feb 2024 23:34:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707089693; cv=none; b=dXn8VbJJz8v4NiDer2IMGmOiqvVAnSzA0r4fb2X3BihzUaNIX8gKF4fFLH+qDqWHDXGPuPCt0w/BKH0cMu+BY2qUCpEru36cDf5tFI5C/jYNKteZOESns9n/h1mkUpoKeUdrDlkKvPw5DCXtlSSSpZF211lIcnbleVhbgAJdJlo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707089693; c=relaxed/simple; bh=mzpbX0JLJdVzO2c/5EYUqV4nIisyNX0uSPxWZjygZhg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=S1tBpwdGQJrTDHD4wB20JAKC8M8CSFUEAgK0ukv4CWTvFH1AgWMV8iUEKQwSM6eOcVQwAtgG1vWTFephheiao7ArjMpgn0jqPFAk09MXYBNaWZxTWwHLD61hy8Ioa4J8zU/JUupxSIOl43QMnSzG4pnMIL/JKndBdud6YDv+X24= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fromorbit.com; spf=pass smtp.mailfrom=fromorbit.com; dkim=pass (2048-bit key) header.d=fromorbit-com.20230601.gappssmtp.com header.i=@fromorbit-com.20230601.gappssmtp.com header.b=FRw0G62Y; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fromorbit.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fromorbit.com Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6e040c83556so270106b3a.0 for ; Sun, 04 Feb 2024 15:34:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20230601.gappssmtp.com; s=20230601; t=1707089691; x=1707694491; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=p2TnSnFYEsDimdpS3N17Ru85rGMnUNIuGwXCS2vJfQo=; b=FRw0G62YRIRSd1l36tnMa358x2HiQDU2XiJb0Bc+TvQdyY61zgdkXPjpH3cdkpVKlK su/AVYrxGlwbd40jb99DJZvrAX/7vO6urSQzSNPrqkBKacpwsTvayKNF/ukiIrkni5VG nS9mKNFydm9PuVls1VWaLRsgKfrm3DRM8VgVxs5SKot1z+NYxwMw2Hwidob58qAWmYmz nqgEqKBOZrS2Zrn85Z66b8odKfk48F+CgrbXRgvlWM+lw0qWXPbSj5zSaKhlALXrYLnD 3nucyzhKs/bmJA/aZa6NXTK4hVbSFiIdqaQmWSloEqxDR9rMqbi6ZMLO4gMuoojjXvsF uFFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707089691; x=1707694491; 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=p2TnSnFYEsDimdpS3N17Ru85rGMnUNIuGwXCS2vJfQo=; b=c3WOUbaDLDosoMA7Sucz2FPDsocqH0xeheLUL8X/gXf8IMIJ4SFsonnB9YvEq1zYXh BmbvUqoW/ilgOwujE79UJSXxi3QhVqLIfepGo5ViwH+uNjhHAoiFfDVgZTZRFdYq7Hrq 3l6To7IM6dIGABSKtvyGJHtW+Ipr9lokbXIuDNvQHU7us5hwEGeV/SmVR67J+/FKNgKU cTynkWp0jvbqgN0sBWAgpcaoLqSJEMjYXtu2UbUyBSGP/ivlwRMk+hTtj1c5waD27bpC z1/3hQOVIJTMbwdJF51Q2z6+tZ44AeVdZJzE7IAKW3hHDtVT5fgphEPdXTLc+dQKpF6t ymOQ== X-Gm-Message-State: AOJu0YzOTJPwTj+uFmESjuHMufqlmBR3vBYPVBm87TUDXsx8iwVNhkoT 7+rkTzj843Q9vuR7hBoaq7OPzPYbBUdSnN0kzndchp5Lokj6dk44TlgQ7noaUbw= X-Received: by 2002:a05:6a00:2192:b0:6e0:25db:65b2 with SMTP id h18-20020a056a00219200b006e025db65b2mr5694366pfi.14.1707089691057; Sun, 04 Feb 2024 15:34:51 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUSoMhjFgbz6wgPYjJeWh0oBQcp6MJNa57h3rXjMk90rQX9EVmU21co4Vy13pQ78HfAK+dGBm51kXWCv8XPb7jMIPFd0Zg/FJOlcH/ShnF2EIeOLQY8LC2IRQIzg8ZOH6QBwJl9Die3twPbKyjCq158cXpUeT5L+wzpnvjJRWM1n4riTNHqBuOwCfGyDski6jpqfGIbMzRmo0z03NXa8O44yHf3NBsY+Ry8rtnnLptRU+M/jFT2un02cNaZBfEAbtTiQrB+oceSPYqkImMz1GtPC0COLQJ58gmUFrQEyh/gZcktQV3fs3APTofh01rGo3KBYsD+eV6vS5eqA8jjjyrLYpcxFYMqwwykAAqHa6O7 Received: from dread.disaster.area (pa49-181-38-249.pa.nsw.optusnet.com.au. [49.181.38.249]) by smtp.gmail.com with ESMTPSA id x2-20020aa79a42000000b006da2aad58adsm1422234pfj.176.2024.02.04.15.34.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 15:34:50 -0800 (PST) Received: from dave by dread.disaster.area with local (Exim 4.96) (envelope-from ) id 1rWm0d-00293b-35; Mon, 05 Feb 2024 10:34:47 +1100 Date: Mon, 5 Feb 2024 10:34:47 +1100 From: Dave Chinner 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 , Mike Snitzer Subject: Re: [PATCH] mm/madvise: set ra_pages as device max request size during ADV_POPULATE_READ Message-ID: References: <20240202022029.1903629-1-ming.lei@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240202022029.1903629-1-ming.lei@redhat.com> On Fri, Feb 02, 2024 at 10:20:29AM +0800, 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; > +} This won't do what you think if the file has been marked FMODE_RANDOM before this populate call. IOWs, I don't think madvise should be digging in the struct file readahead stuff here. It should call vfs_fadvise(FADV_SEQUENTIAL) to do the set the readahead mode, rather that try to duplicate FADV_SEQUENTIAL (badly). We already do this for WILLNEED to make it do the right thing, we should be doing the same thing here. Also, AFAICT, there is no need for get_file()/fput() here - the vma already has a reference to the struct file, and the vma should not be going away whilst the madvise() operation is in progress. -Dave. -- Dave Chinner david@fromorbit.com