Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp924789rdb; Tue, 30 Jan 2024 02:52:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6QuLHzUtTCiqaIUUI2YJfoNTD+DSa/H5sm4xbfqt3ZUjl2Qky1gcjfYQQE7gpFkTqCmvo X-Received: by 2002:a17:902:7ed6:b0:1d6:ff27:7627 with SMTP id p22-20020a1709027ed600b001d6ff277627mr6625005plb.50.1706611935334; Tue, 30 Jan 2024 02:52:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706611935; cv=pass; d=google.com; s=arc-20160816; b=ChBCLqSQrn/KGjDtk4hE5YuvMddaullKvBv0xYzVHCU5ta3FH+ty5R3FXu9kZ4W7Sx mFyYDdEVZNIKsxu8XdzVvByqT3HEIdDhKXACMknhBiMIYZQinS6y4C0JANiBQBjYdeEm ZNWMYjEkXk0qOqdz7tFc+rI41MXZBFyctAWlBvN9/cWzp0zuKsXRqAsAMK/mhj+8h8BK 5CwE1d3fWIwoPPc1NuuwUGT0baK1UMGN0gP9WjFq3Y2RybCZ88oAyZqWEuXukgnQ/DqP UNOuwuEFQ3gVe/1RiJrRomoW66WD4qK8GA30weZ97q4DgN3wKYi0k5gE8dlBiuh5Mb2K Ha3g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=2HONVDKuSZ2w2l05+cN156w2V56GzzGmZ9dXonpaH9I=; fh=8nn0ltP08i4ULJhkeO7RNtR++OkIeO05/vRBlMr0IQg=; b=TJqMG24eeEph3kGuZARvazmqWOvqI0sdK8XfKGJUOSvZ1TPN+Qr14bohFDHV5hlvyJ 4xEmBwuT53hHE0Jf6RoYVz2DgEASTyr8soziuAyaRVC9MtxSRLbLmL/TiSwq4Fo+Ih0B puK4KLS/KUZ8ZV8+1CU/qeE7mLks+Y+oWkponswWYbkPi8MJleUYIGvOyYMuvIbDlFlO MiWk6e98ZxeizzlHXWPWlP4Vr4Luo1CZlzQhGXmO+sQlgji7oVo36mcgdpBdwD/TmUtN cX78ufERRQFJ549cTpdy2Aw3W9FyJWvsjtb64ajD+YAl/bEkZqCxrIMT7M4OxYpR6lqQ bnwA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JbsS9ZAN; 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-44407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q11-20020a170902c74b00b001d903a572edsi1207330plq.606.2024.01.30.02.52.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 02:52:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JbsS9ZAN; 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-44407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44407-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7E62028AEDE for ; Tue, 30 Jan 2024 10:43:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C7FE664A9; Tue, 30 Jan 2024 10:43:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JbsS9ZAN" 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 B723360DE0 for ; Tue, 30 Jan 2024 10:43:27 +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=1706611409; cv=none; b=WD3/A6TA7mah9hXKaaDEU0mc0TgzqDb/wk1W/PD7GhmT4voLlnt1ZcLBh861L7CXd9quKD3RYCICM3b8DX4hNrSIaLumAs5Ok/9HjIwSwuDVYJ/8b2FV0VphDDRl4dhuN/Wo0ESQeDL+WwR+sSOaaCIWTjokJ3BBM46Oo6hNkIU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706611409; c=relaxed/simple; bh=owkU35HiBe4EUW9bL/iY9553g7P8YyHRpTmmFYvFxTA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=aM3fzjLX+U5Ax7S6dDE5a4E4sX8M2E2W+DbMSDsilfLNzbWrIvkXrZuWRbDklL1H799esqcJdqIHg24l3KlOJyl50Ks+8JZu0ZM5F61ktmGE0jOGiPvcM78TcHvSjgQ2BPF0pyPZhUZlCHI+NUzzWx1lKk6tVW0PDijk1Iu/0bk= 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=JbsS9ZAN; 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=1706611406; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=2HONVDKuSZ2w2l05+cN156w2V56GzzGmZ9dXonpaH9I=; b=JbsS9ZANWadul27lgkJdXIZ8mnwUbHiVB3maQCo4ChmFj2VI7b+6umJ1epgFYrRPCWKMaH NtdyZLx0OENAuezVxmzIfNJVZ5jOdhVpaSpfIwOKdUoQ0DyoTekXiyXo52V0434aJM2qy6 Dd9+oW18hbBq4LVbIwGDFKK3gvDewg4= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-541-XJZMCy-kN5KEwEkLHE-uSg-1; Tue, 30 Jan 2024 05:43:25 -0500 X-MC-Unique: XJZMCy-kN5KEwEkLHE-uSg-1 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-50e9e5c8f49so3948180e87.3 for ; Tue, 30 Jan 2024 02:43:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706611404; x=1707216204; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2HONVDKuSZ2w2l05+cN156w2V56GzzGmZ9dXonpaH9I=; b=MOzxmP9+E+qTzKbye6LR9A9M6F+Y+IoA0yjkhf7ct6ner0oRiajWxXcEcAx9IyHTid RX9HdQ5Zbd02WiUwYxYuwgIAEBrOnYF8A9z9LpjST4r19c4ds9lTnX15bk82PLUBam1B lpzjd4veDfNR3upuzqb7A/18u0BVdDAwb3u4iHyh/0Xs6OlT+ZgNqBkI8q2bsJBok4hA fNMB4Pln5f+Crt4OBwLIqv03cDFuJoYgBk41F5BeIrs8WFQ5a6l67mH7achfeqO6Ld7P 85MU7sIZCtd4UVLLTJYMlbrNCW6F4V+XIaHfU56+B19F1ti0UyrIDgZbrqei6CyPrQVv Or7Q== X-Gm-Message-State: AOJu0Yx8JwmBKCpQjsuU3pP7RLAmhioT5E/QId80nHiHZ+ixjBR15MCR oPNUeOER75P7fhSsaiJ1VjgTt09zQYNJtZsB2mmGIM28ghknRP0PIDtcws9wBSjInlL0DWHplMk LBqZWP62p/G0/m7IfW6drH/zDd6emICkU45gn7oEVsm5PEa2GExo0G3YI2pul1Q== X-Received: by 2002:a05:6512:2209:b0:50e:4098:3798 with SMTP id h9-20020a056512220900b0050e40983798mr6360921lfu.60.1706611403681; Tue, 30 Jan 2024 02:43:23 -0800 (PST) X-Received: by 2002:a05:6512:2209:b0:50e:4098:3798 with SMTP id h9-20020a056512220900b0050e40983798mr6360892lfu.60.1706611403250; Tue, 30 Jan 2024 02:43:23 -0800 (PST) Received: from ?IPV6:2003:cb:c708:2700:bdf6:739b:9f9d:862f? (p200300cbc7082700bdf6739b9f9d862f.dip0.t-ipconnect.de. [2003:cb:c708:2700:bdf6:739b:9f9d:862f]) by smtp.gmail.com with ESMTPSA id b16-20020a05600c4e1000b0040fafc8bb3asm204081wmq.9.2024.01.30.02.43.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 30 Jan 2024 02:43:22 -0800 (PST) Message-ID: Date: Tue, 30 Jan 2024 11:43:21 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH] mm/readahead: readahead aggressively if read drops in willneed range Content-Language: en-US To: Mike Snitzer , Dave Chinner Cc: Ming Lei , Matthew Wilcox , Andrew Morton , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Don Dutile , Raghavendra K T , Alexander Viro , Christian Brauner , linux-block@vger.kernel.org References: <20240128142522.1524741-1-ming.lei@redhat.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqzt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dng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 29.01.24 23:46, Mike Snitzer wrote: > On Mon, Jan 29 2024 at 5:12P -0500, > Dave Chinner wrote: > >> On Mon, Jan 29, 2024 at 12:19:02PM -0500, Mike Snitzer wrote: >>> While I'm sure this legacy application would love to not have to >>> change its code at all, I think we can all agree that we need to just >>> focus on how best to advise applications that have mixed workloads >>> accomplish efficient mmap+read of both sequential and random. >>> >>> To that end, I heard Dave clearly suggest 2 things: >>> >>> 1) update MADV/FADV_SEQUENTIAL to set file->f_ra.ra_pages to >>> bdi->io_pages, not bdi->ra_pages * 2 >>> >>> 2) Have the application first issue MADV_SEQUENTIAL to convey that for >>> the following MADV_WILLNEED is for sequential file load (so it is >>> desirable to use larger ra_pages) >>> >>> This overrides the default of bdi->ra_pages and _should_ provide the >>> required per-file duality of control for readahead, correct? >> >> I just discovered MADV_POPULATE_READ - see my reply to Ming >> up-thread about that. The applicaiton should use that instead of >> MADV_WILLNEED because it gives cache population guarantees that >> WILLNEED doesn't. Then we can look at optimising the performance of >> MADV_POPULATE_READ (if needed) as there is constrained scope we can >> optimise within in ways that we cannot do with WILLNEED. > > Nice find! Given commit 4ca9b3859dac ("mm/madvise: introduce > MADV_POPULATE_(READ|WRITE) to prefault page tables"), I've cc'd David > Hildenbrand just so he's in the loop. Thanks for CCing me. MADV_POPULATE_READ is indeed different; it doesn't give hints (not "might be a good idea to read some pages" like MADV_WILLNEED documents), it forces swapin/read/.../. In a sense, MADV_POPULATE_READ is similar to simply reading one byte from each PTE, triggering page faults. However, without actually reading from the target pages. MADV_POPULATE_READ has a conceptual benefit: we know exactly how much memory user space wants to have populated (which range). In contrast, page faults contain no such hints and we have to guess based on historical behavior. One could use that range information to *not* do any faultaround/readahead when we come via MADV_POPULATE_READ, and really only popoulate the range of interest. Further, one can use that range information to allocate larger folios, without having to guess where placement of a large folio is reasonable, and which size we should use. > > FYI, I proactively raised feedback and questions to the reporter of > this issue: > > CONTEXT: madvise(WILLNEED) doesn't convey the nature of the access, > sequential vs random, just the range that may be accessed. Indeed. The "problem" with MADV_SEQUENTIAL/MADV_RANDOM is that it will fragment/split VMAs. So applying it to smaller chunks (like one would do with MADV_WILLNEED) is likely not a good option. -- Cheers, David / dhildenb