Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp747661rdb; Fri, 2 Feb 2024 02:53:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFdiburUaLxUhGkBcuFJ5ItfAf0zBEkJAYi1N4eeFOqzl//L8BwKOZ1OjYnQGc6QQHMVqSN X-Received: by 2002:a25:6f55:0:b0:dbf:e0a:c62b with SMTP id k82-20020a256f55000000b00dbf0e0ac62bmr7316194ybc.48.1706871202850; Fri, 02 Feb 2024 02:53:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706871202; cv=pass; d=google.com; s=arc-20160816; b=xa7m/baw15j5WWv20vYLhp0lKPsjIxdjKQ5LhRSse5cXUAy5JMtnwqrUMuicO/YJo1 NbNpwWXXp5Dhgx+k0+dWmPFG+J3/HU5nDQqdrLiyDQzcHxKh0A+l9YlbYbONnN3EduEk /Lkeg2ZnRps633MWyDNelE9Rv/ZW5d8P4ykcy/pjlU8UVAyk5Q1mcgyIx4g8ffhCwIu8 jjT+OxMGJfViulXGoGT1FijTKN3gKeTnAAKQuoXSiK83o4YoKJFgtckIlaXjmVVzoHH+ 2nIuqY8FO9KjCL9sMuHs2xg33ZDUG/08AXfeT2Bu3eKIbA6wpCBw6T19an7yFBay2ncb bogA== 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=ZClaqx53ZJJu0ie6KUCf9aABm/H96wl0onIl5m7Has8=; fh=zTMaihvkIDVPEg8Awqfcl+tJTYX5zTDCDzhHw0a5Y1g=; b=GTSncTKqZU7uKTgqxS99vwd7VLIvBJaYtWr+0ybg+86sWdITXA2Qq+/bhScl86SzxR eIHyfw/Ez2JOtkxmYcgD7W3bD4VawOZd8qPdqeQmp4GRAvnKfE8Tmu+R+fLZ6MXZX2kn ha+nUQ8KQN9+KZBcbZbHuE4TISSGXfieyzOjBhfE2Aa2mbhj9p9o3wM3nNqtStuxwdBz t8xnxJX4qNUDp4lsyiQQ0e+vjYSTlOhVN94n0gY7ZO6aLvuzbHvFHQ14IcpuJu8eBxrY wEg8Dti7+CZaff0XBn6UZVSeZ+2K2JBHT8fXYQ35ivuyAC1afzmFJSlOyzvnXRhxK+26 kC1A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="DOzrgy/W"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-49704-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49704-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Forwarded-Encrypted: i=1; AJvYcCWmb4ipCES31Ac7R10778b+gXZkh9SX7Xzi+uLf0V5O0k4la8s+6PK5p9odNwu2GcVgP4CWDFvBZY3So58Q2++euxpsTnCuCeMRPbD1xw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g7-20020ac87f47000000b0042c069a9973si527449qtk.744.2024.02.02.02.53.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 02:53:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49704-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="DOzrgy/W"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-49704-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49704-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8C13A1C25FBF for ; Fri, 2 Feb 2024 10:53:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EEE6013DB87; Fri, 2 Feb 2024 10:52:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DOzrgy/W" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6746913D50C for ; Fri, 2 Feb 2024 10:52:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706871178; cv=none; b=R3pJLG87PgiwMeCvN+Hge3HX07G+6uju+gm8ssGythQCuSuYW7EJRcWc8VhPf96aFRwRiB8YSK9xCtA0KjMnhnb6ID4i7Na75jXhP/EVDiZW93bXT+0ZA40cBvfQnAH+tDFvTN65HqFt8eY6j07ZxYg8MiriHhop5c2VgAHnVZU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706871178; c=relaxed/simple; bh=dqUxwBZX2kfI3B+P5TtoZCK0zVV9VHWfEdhugIz7LIE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=af48uh/EI4Vxf//eRcno+vDAfCFqGHsYK9f4NHeO1yAZdx9V3xiZIHp3FVDjOCPI6XYPGuxoNYW9izvdiqk7POVlPkBT6nLYLmR8JebEYewkIWb8qPsjO7zn+ji4l+0DDJzG+cgmhm+zVFhEmSmJuGr1+2ApaW6AhfTSH/bIz90= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DOzrgy/W; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706871175; h=from:from:reply-to:subject:subject: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=ZClaqx53ZJJu0ie6KUCf9aABm/H96wl0onIl5m7Has8=; b=DOzrgy/W08sf3mtiqa3OTy0qrOrN8lADr1U41ZRuGcRJUxE1bPxYVT/mcYK66VWYP7hBjz hhT5MDffNkZdyUVk4Gj0oaafuF+Po1SetQW4B4kcca2+s+rgJwogS22ztlIf53l0a8THJ3 ou7aTa8hpvmRhre6EwqFRqP9aODhyXk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-iW2aeLZvPEy-2p72J5_cXA-1; Fri, 02 Feb 2024 05:52:52 -0500 X-MC-Unique: iW2aeLZvPEy-2p72J5_cXA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 71E5385A588; Fri, 2 Feb 2024 10:52:51 +0000 (UTC) Received: from fedora (unknown [10.72.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D9E5640C95AD; Fri, 2 Feb 2024 10:52:45 +0000 (UTC) Date: Fri, 2 Feb 2024 18:52:22 +0800 From: Ming Lei To: Mike Snitzer 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> 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: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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. > 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. > 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, Ming