Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp321697pxb; Thu, 25 Feb 2021 03:34:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJy6egL2Y+/uiDZT7iW1Bt0XGWTL437eEjxVErl7vOXR/eLdYzcWKH9P3ETEbTspmEFkx4Ap X-Received: by 2002:a17:906:e91:: with SMTP id p17mr2240357ejf.399.1614252899775; Thu, 25 Feb 2021 03:34:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614252899; cv=none; d=google.com; s=arc-20160816; b=XhFjt4L5QIE4o/kS21UnzEIyBTcDXAgYeYAePF10y65rKpn1HDJTg2/AnZQX9thViK 8jjCVHY6EB3Rd+b/Rws0IWMsmTVrGfUGBFP9zct+67tpWqTvTb8LhBKTyZxfW9G2uSbw o2+zXBj1pNcWvqJg9xQcm90Gp9XknyEYBtiNUPiVuMsrtQoCFjWUYA8jm88j/FDvdgy0 sbj0oj71Cz9POoX7UB1VrvWABprIZTsxe2B6Ed6LNdIQCy6oD13Nj6TthWQq9rrDw/0R SEw++E0Xi83gm7ctelGeQBWtVWGijxmpFfo0D6QyA9UECDoofFozOFgAOSU87dyBx2pk x+Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=7uPn+gulMqhjaE42kJBeaOP3zpjHqeQ12o0+1jYccOE=; b=glsjb5iaGvCBTHmYf2Cx3uq/NunyzV/5P3HHWl+2T5PXtKtHaJqqYHW6iH2pTo4RSz +CJSW8NXKRC4DcsGXlIM6KYrMYvXsh9+l0KbWGCs+4vqU1qyysVpRM2x8YAJBCBNDUxA RqN1JvOWhVF6UbDDfjpQa6q8SLbsTM4Y97f6iy3c+ekDQtq8xiIz9P8qCdELNdPKcOtE i41GU4ZI6ipGubYXpU43rgQ1iwvpCrtyeoaQzC7gD0SwXQCHLsIaHtmqBGOQq4p0xngN uHyRKazTb0FXUCGEVcgGwlniLfqN0DYjMs/xkv40Jny/GroEcczdrGAPj7KU8oAkW56q YOGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MclzpfaL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d4si3132253ejb.594.2021.02.25.03.34.37; Thu, 25 Feb 2021 03:34:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MclzpfaL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234087AbhBYHeU (ORCPT + 99 others); Thu, 25 Feb 2021 02:34:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233963AbhBYHeN (ORCPT ); Thu, 25 Feb 2021 02:34:13 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85363C061574 for ; Wed, 24 Feb 2021 23:33:48 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id t25so3234696pga.2 for ; Wed, 24 Feb 2021 23:33:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7uPn+gulMqhjaE42kJBeaOP3zpjHqeQ12o0+1jYccOE=; b=MclzpfaLfKRRoTmtHKOR+QpD7iRU7gZnLM4D29YRc09BXBn6SZA0QA16+njtTz4Yoy Ks5SD7jL/4HV6tcNHIZGTQB/J5tjAasaxzcJKnNe++qadDyDLJsL+yTi5JRr1SjCiqjj +4rDvsM1JQ2ZdaXT1z3K+8BIIaoLhvM8lW+FM/GhEdA/H6PHn6mjp3nt89vBEEvBumIo 4L3Dd5EaOQx+AS8CYcb9m+ZLDGmA3gDJSayp1sQgAqOAi8K7heOgqUP+72auHRfBMeBY zCo7eXCAVdBTaxOnQw2OGRilwbn6RwA+6D2Uv7fPK7pUJzJ4JSaEn2UvPlUgdQGuRzfE sp9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7uPn+gulMqhjaE42kJBeaOP3zpjHqeQ12o0+1jYccOE=; b=fVjq2wLZyh+RwT/zFyQewmqJ3Pz7ORDtNbMPDHi8CfBRgstmrNpWPGpsBZrVznBpaL kjdTJpx+GC0z2LBcnOUhq8dH32Gi1bOxqj3/nKWzTOYJMXOVkasgisTD8Qy+T/17SJA6 /j4PkE4hwFLItn1HtbMayMaeuSJ5NopMrdIta6Dc05CS8i5lonVLYDr/24D1jyRV/tlk eLYWUmotM6wSi4JJw689zOKxZT8+/w6+/HfizThTxq5gzFTOtSpMeAcOPuTrykUvYBdH sz/2grgktRKm98r4+QE4Tix5kf5HlwZoTAdkm/66r+7qA5wI2/ZK4zDMYXKKJHfUDsGE sFHg== X-Gm-Message-State: AOAM533vrO3cPUjavOgU93cRdxP9rC/u25frtaCocKLVd+dV9cN1ENYZ cKHlWIw6fveIAB/vLPA4cY0= X-Received: by 2002:aa7:83cc:0:b029:1ed:446b:1ae2 with SMTP id j12-20020aa783cc0000b02901ed446b1ae2mr1938968pfn.47.1614238427898; Wed, 24 Feb 2021 23:33:47 -0800 (PST) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id w3sm4917561pjt.24.2021.02.24.23.33.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Feb 2021 23:33:47 -0800 (PST) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hugh Dickins , Andy Lutomirski , Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Borislav Petkov , Nadav Amit , Sean Christopherson , Andrew Morton , x86@kernel.org Subject: [RFC 0/6] x86: prefetch_page() vDSO call Date: Wed, 24 Feb 2021 23:29:04 -0800 Message-Id: <20210225072910.2811795-1-namit@vmware.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Cc: Andy Lutomirski Cc: Peter Zijlstra Cc: Sean Christopherson Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Andrew Morton Cc: x86@kernel.org Nadav Amit (6): vdso/extable: fix calculation of base x86/vdso: add mask and flags to extable x86/vdso: introduce page_prefetch() mm/swap_state: respect FAULT_FLAG_RETRY_NOWAIT mm: use lightweight reclaim on FAULT_FLAG_RETRY_NOWAIT testing/selftest: test vDSO prefetch_page() arch/x86/Kconfig | 1 + arch/x86/entry/vdso/Makefile | 1 + arch/x86/entry/vdso/extable.c | 70 +++-- arch/x86/entry/vdso/extable.h | 21 +- arch/x86/entry/vdso/vdso.lds.S | 1 + arch/x86/entry/vdso/vprefetch.S | 39 +++ arch/x86/entry/vdso/vsgx.S | 9 +- arch/x86/include/asm/vdso.h | 38 ++- arch/x86/mm/fault.c | 11 +- lib/vdso/Kconfig | 5 + mm/memory.c | 47 +++- mm/shmem.c | 1 + mm/swap_state.c | 12 +- tools/testing/selftests/vDSO/Makefile | 2 + .../selftests/vDSO/vdso_test_prefetch_page.c | 265 ++++++++++++++++++ 15 files changed, 470 insertions(+), 53 deletions(-) create mode 100644 arch/x86/entry/vdso/vprefetch.S create mode 100644 tools/testing/selftests/vDSO/vdso_test_prefetch_page.c -- 2.25.1