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 X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0AE1C433E0 for ; Thu, 25 Feb 2021 08:40:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2520764EDC for ; Thu, 25 Feb 2021 08:40:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2520764EDC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7F8C58D000D; Thu, 25 Feb 2021 03:40:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CFA38D0005; Thu, 25 Feb 2021 03:40:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BF678D000D; Thu, 25 Feb 2021 03:40:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0009.hostedemail.com [216.40.44.9]) by kanga.kvack.org (Postfix) with ESMTP id 56A718D0005 for ; Thu, 25 Feb 2021 03:40:35 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 0FFCA82F76A5 for ; Thu, 25 Feb 2021 08:40:35 +0000 (UTC) X-FDA: 77856144030.14.9169775 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf22.hostedemail.com (Postfix) with ESMTP id D147BC0001FE for ; Thu, 25 Feb 2021 08:40:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=G+01GQRHgNms4G9fglToOhULoGDVmmEVkT36Qkg4cjs=; b=Eu00hKiDI9mkbFIMX4dmRTBmKk AWdU7kS2sSAqOk/5jU/4o/Zmi4EqQSOYu1M1hQVfWmm1aGvkUlFlI1QOBqd1QgefOnW8SJ2rTZC+I e72DwUBXXsrhqMgLGFekDfcSbXI07vqx4Bv58iyCA2P9mk3Otsi98kTkWo5ABk9Tqn6qkPbYCjU/T A+/8sJVpnIzFNhiTzyFR1iTdksTBz4gvgNUwhNn48F2NU090qeHDiAtzhInXMEnXmXmuodzAJKGPS kZKL2IXYsVHOnlfQ82holow3Sl7HEKnzGIl8is5MfjUM/ZB65Wc4zZwY4ymyUyD2mFSgWvPpT8c+D bTl0/ElA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lFCBt-00ATfr-Ge; Thu, 25 Feb 2021 08:40:12 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 1AAF73010C8; Thu, 25 Feb 2021 09:40:08 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 08EA82023FDE4; Thu, 25 Feb 2021 09:40:08 +0100 (CET) Date: Thu, 25 Feb 2021 09:40:07 +0100 From: Peter Zijlstra To: Nadav Amit Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hugh Dickins , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Nadav Amit , Sean Christopherson , Andrew Morton , x86@kernel.org Subject: Re: [RFC 0/6] x86: prefetch_page() vDSO call Message-ID: References: <20210225072910.2811795-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210225072910.2811795-1-namit@vmware.com> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: D147BC0001FE X-Stat-Signature: x9iy69ndojbmo4p61gj5pp3z5hnae36q Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf22; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614242429-999292 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: On Wed, Feb 24, 2021 at 11:29:04PM -0800, Nadav Amit wrote: > From: Nadav Amit > > Just as applications can use prefetch instructions to overlap > computations and memory accesses, applications may want to overlap the > page-faults and compute or overlap the I/O accesses that are required > for page-faults of different pages. > > Applications can use multiple threads and cores for this matter, by > running one thread that prefetches the data (i.e., faults in the data) > and another that does the compute, but this scheme is inefficient. Using > mincore() can tell whether a page is mapped, but might not tell whether > the page is in the page-cache and does not fault in the data. > > Introduce prefetch_page() vDSO-call to prefetch, i.e. fault-in memory > asynchronously. The semantic of this call is: try to prefetch a page of > in a given address and return zero if the page is accessible following > the call. Start I/O operations to retrieve the page if such operations > are required and there is no high memory pressure that might introduce > slowdowns. > > Note that as usual the page might be paged-out at any point and > therefore, similarly to mincore(), there is no guarantee that the page > will be present at the time that the user application uses the data that > resides on the page. Nevertheless, it is expected that in the vast > majority of the cases this would not happen, since prefetch_page() > accesses the page and therefore sets the PTE access-bit (if it is > clear). > > The implementation is as follows. The vDSO code accesses the data, > triggering a page-fault it is not present. The handler detects based on > the instruction pointer that this is an asynchronous-#PF, using the > recently introduce vDSO exception tables. If the page can be brought > without waiting (e.g., the page is already in the page-cache), the > kernel handles the fault and returns success (zero). If there is memory > pressure that prevents the proper handling of the fault (i.e., requires > heavy-weight reclamation) it returns a failure. Otherwise, it starts an > I/O to bring the page and returns failure. > > Compilers can be extended to issue the prefetch_page() calls when > needed. Interesting, but given we've been removing explicit prefetch from some parts of the kernel how useful is this in actual use? I'm thinking there should at least be a real user and performance numbers with this before merging.