Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4061945imm; Mon, 8 Oct 2018 14:18:52 -0700 (PDT) X-Google-Smtp-Source: ACcGV60gLchoi80rNBVGE2AWbDUiM1Dfs/jKDOVidY3aoZtbLOJugthgMuVDeUj7GH/oekgNEnK0 X-Received: by 2002:a62:6f43:: with SMTP id k64-v6mr26109065pfc.87.1539033532142; Mon, 08 Oct 2018 14:18:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539033532; cv=none; d=google.com; s=arc-20160816; b=EJo7Tk7t+wUboqHvpBPHu2oOaf+kyjboxV1CMszQJWTuq2Qv8ucGnEZ6lI4iDqpX+y Fh8zc7k674Fd10qdx3l38zhUyvbPuNRhBibR5MWECyJ+5XgBIBzpfDwVi2LO/PsSH5vX kAcRAIipPePvscBvHL8RiWiCs+A+B3iEX6uZYPGOkT6Q8Kdb4QmQtlpQZN3xKJAIB+Rq dGi9/xjnYhX1ymoNYlKXpFCKfBQ3a6DTBvp4hTh5vMvmwZ/jxfrV7oNerMYD2z6+LJi0 FMorR+OlrKfG+bqab30L0dVnuqW+4w/gmxzzft0afVpATqCuNW3TOW5ASIZcCZGqQyQz H8ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=k+/+jNVpClYYrnYjCdSDtQ5UKgPHQ1Yc+3CgIrq50RY=; b=tb00VRvTODWFJ0Gd+/e+qUbEXDUoPhjz9DXQRhGejyTV+5O4jpQow1pp2HISAwMr5x m4CdtFBCjUSOWj2uh13jBup95/W+bdATPNSt73pnOov2q8w87UiJzRiHfLrETxlTGDgl 2b19oecCWiM8UoFdu0++n4ny/PenU7fHjBg4q9QDr9fMuwIZaCUuLLxQDaNlUJHmyOnq Qyimw65uPCHas22B5hNFmJStyvak+WJF4k3NOUVry9TqBvJKM2UVKs4VqJX8Y/+wfKDT TETi4a2o3PV1FRZePNFrApCocLnvKnTIDn67aXhtNtUzqhm0d7VoS11JmVY0c14UzPwd XmIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fDiPneiU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id n6-v6si19858213pla.79.2018.10.08.14.18.36; Mon, 08 Oct 2018 14:18:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fDiPneiU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727261AbeJIEaQ (ORCPT + 99 others); Tue, 9 Oct 2018 00:30:16 -0400 Received: from mail-pf1-f180.google.com ([209.85.210.180]:46389 "EHLO mail-pf1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727197AbeJIEaP (ORCPT ); Tue, 9 Oct 2018 00:30:15 -0400 Received: by mail-pf1-f180.google.com with SMTP id r64-v6so8906434pfb.13; Mon, 08 Oct 2018 14:16:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k+/+jNVpClYYrnYjCdSDtQ5UKgPHQ1Yc+3CgIrq50RY=; b=fDiPneiU/6UFz4R1QH02YqIZ/WkPKzDaTlQBxArt122EPNQPQYe4k7I1BgXBoCy2GD lwGKE4fvsonhnvALxgDzpzKa+knf/mDwOmhcxMOUZFQleSGrUph4kP9ikUoeuzXa1pgG l6PvBcAfRFP9PAnChf6HEO+OC2eX4jHLobh6tjlfqZprgJFMQfKOGGA8mG1EeDgMQT/F TVXl79hARghB+r/3ifEnjmfbSWj1NykpxiSAyCSCPuu7M2ynO8ihcGovbvtBqaHKTsBL rT95UgYUYRvMTz8cnXjJobWnwkB+S1ibUPXLW7L8AB9f9Q44JiBE1kLNifQTKsmFFftJ joNw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=k+/+jNVpClYYrnYjCdSDtQ5UKgPHQ1Yc+3CgIrq50RY=; b=ITve0nVXzbgrqRoP66AL8/smS/KO1ke8e869RDGBMXMEZx4qXvGnZRXft+p8VTmYW2 s/ZMAjStLA0K93Plpo3TKQs0bAO0ksyptcKJYWflOEssv36W3X9KykTxcEnxhk3QXD/s VSpZKEhUk51/KMtVurUYBFOGENHFDrHnAoHMf/kvjBd/awrxYiF9maWGAjeIxV6DOl1J hpqULfwk/4UcxK48yNAUXwHxwN2HSe7AwDbH8kP/gx8TnWi1u5btuN/8X1Ci82Pcx/N3 B8IvI+yyeYUFw8vlYY1M8hQdWtcZlS/5zmFmwwtyN6/+KP5kJi94k9+Z2qDYI0rnxN7q D0iw== X-Gm-Message-State: ABuFfohRYkP7/Rtih75nVRs5mX6zZZh24Zm2nwT3GNrthWEG5UQgqFty aTJc3ThNGmopgc51XjdU4y0= X-Received: by 2002:a62:1655:: with SMTP id 82-v6mr26623699pfw.11.1539033393061; Mon, 08 Oct 2018 14:16:33 -0700 (PDT) Received: from blueforge.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id w127-v6sm23480045pfd.112.2018.10.08.14.16.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Oct 2018 14:16:32 -0700 (PDT) From: john.hubbard@gmail.com X-Google-Original-From: jhubbard@nvidia.com To: Matthew Wilcox , Michal Hocko , Christopher Lameter , Jason Gunthorpe , Dan Williams , Jan Kara Cc: linux-mm@kvack.org, LKML , linux-rdma , linux-fsdevel@vger.kernel.org, John Hubbard , Al Viro , Jerome Glisse , Christoph Hellwig , Ralph Campbell Subject: [PATCH v4 2/3] mm: introduce put_user_page*(), placeholder versions Date: Mon, 8 Oct 2018 14:16:22 -0700 Message-Id: <20181008211623.30796-3-jhubbard@nvidia.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008211623.30796-1-jhubbard@nvidia.com> References: <20181008211623.30796-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Hubbard Introduces put_user_page(), which simply calls put_page(). This provides a way to update all get_user_pages*() callers, so that they call put_user_page(), instead of put_page(). Also introduces put_user_pages(), and a few dirty/locked variations, as a replacement for release_pages(), and also as a replacement for open-coded loops that release multiple pages. These may be used for subsequent performance improvements, via batching of pages to be released. This prepares for eventually fixing the problem described in [1], and is following a plan listed in [2], [3], [4]. [1] https://lwn.net/Articles/753027/ : "The Trouble with get_user_pages()" [2] https://lkml.kernel.org/r/20180709080554.21931-1-jhubbard@nvidia.com Proposed steps for fixing get_user_pages() + DMA problems. [3]https://lkml.kernel.org/r/20180710082100.mkdwngdv5kkrcz6n@quack2.suse.cz Bounce buffers (otherwise [2] is not really viable). [4] https://lkml.kernel.org/r/20181003162115.GG24030@quack2.suse.cz Follow-up discussions. CC: Matthew Wilcox CC: Michal Hocko CC: Christopher Lameter CC: Jason Gunthorpe CC: Dan Williams CC: Jan Kara CC: Al Viro CC: Jerome Glisse CC: Christoph Hellwig CC: Ralph Campbell Reviewed-by: Jan Kara Signed-off-by: John Hubbard --- include/linux/mm.h | 49 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 0416a7204be3..0490f4a71b9c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -137,6 +137,8 @@ extern int overcommit_ratio_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *); extern int overcommit_kbytes_handler(struct ctl_table *, int, void __user *, size_t *, loff_t *); +int set_page_dirty(struct page *page); +int set_page_dirty_lock(struct page *page); #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n)) @@ -943,6 +945,51 @@ static inline void put_page(struct page *page) __put_page(page); } +/* + * Pages that were pinned via get_user_pages*() should be released via + * either put_user_page(), or one of the put_user_pages*() routines + * below. + */ +static inline void put_user_page(struct page *page) +{ + put_page(page); +} + +static inline void put_user_pages_dirty(struct page **pages, + unsigned long npages) +{ + unsigned long index; + + for (index = 0; index < npages; index++) { + if (!PageDirty(pages[index])) + set_page_dirty(pages[index]); + + put_user_page(pages[index]); + } +} + +static inline void put_user_pages_dirty_lock(struct page **pages, + unsigned long npages) +{ + unsigned long index; + + for (index = 0; index < npages; index++) { + if (!PageDirty(pages[index])) + set_page_dirty_lock(pages[index]); + + put_user_page(pages[index]); + } +} + +static inline void put_user_pages(struct page **pages, + unsigned long npages) +{ + unsigned long index; + + for (index = 0; index < npages; index++) + put_user_page(pages[index]); +} + #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) #define SECTION_IN_PAGE_FLAGS #endif @@ -1534,8 +1581,6 @@ int redirty_page_for_writepage(struct writeback_control *wbc, void account_page_dirtied(struct page *page, struct address_space *mapping); void account_page_cleaned(struct page *page, struct address_space *mapping, struct bdi_writeback *wb); -int set_page_dirty(struct page *page); -int set_page_dirty_lock(struct page *page); void __cancel_dirty_page(struct page *page); static inline void cancel_dirty_page(struct page *page) { -- 2.19.0