Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7956928imu; Mon, 3 Dec 2018 23:55:58 -0800 (PST) X-Google-Smtp-Source: AFSGD/VbPkwqlIS1iPIm3xXncXkRplFKK40HzfWlWJCnb8B8lCZMTTgy1dtDV8P5+Vhy1GGA2Hqz X-Received: by 2002:a17:902:8e8a:: with SMTP id bg10mr19197538plb.192.1543910158673; Mon, 03 Dec 2018 23:55:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543910158; cv=none; d=google.com; s=arc-20160816; b=wUgKTC4yfV+Pagep2lh4c6jBbUxgHCtduH/JKC544mhTWEO4hSETJAsa9mMmer7Xry PhNRBKNjOIPbaR6v2+xCoHkbSUW2fpBt87zWtt1oE7tUaIAa3t5P/9+x9bbZHuTwGnQi dog4WEMxGEMZZA4rDUu8p+3IvNQmNrf2hYknug/fb2lOvyI95nKScRolXVzZlZhILsup 3IbOW/uFt3XSCc1GwejYXVbmRCq+RF85/aUwJ/4gssmMZCdO0fQRoCn776W904KuK1Ib bILkqaQzxTgEpkX1bKuRdtH3McV8hXCLrPEKCN9llJjC62i1hTxTlP15/9PuPm1FkVvA Tgaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:subject:cc:to:from:date; bh=2gsN3Zi4qX3m1tZlkPcnBKVBQCLN1eEPDtf+u/Vytjw=; b=Ow2o2bsc+EahVbmHEeMPROT6dhMDUWkcGMwRkXh+ESdm3Q9uI2jUXzpnqKNcJowF7n uwmcQFbs8cNK/hi1CPMeGP5KEo51tM8uhwwHJyW8ev85kFkK+Qem3UNNGHJfP+SE3P3Y UNdeac7XEzVUCtKw7ZpOdLpKAXHGPiTNcz6RNTAdr+DSC3EJYKTh1m1ECDe/cY3AGIrr lPuFcRHyYy/xTrvys5JLlFJmH6FodjzW8zSH4JgPqkkUaw4EnxUN6PLXbyx7yam4lPi1 5Hy5x0IGWckxh3WetqOxLJdNERqWdPXz1NlRIyINYALiR5QpkFFq6CSXxtLJ/8fpz/Mw so2Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m38si15401942pgl.125.2018.12.03.23.55.43; Mon, 03 Dec 2018 23:55:58 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726073AbeLDHxj (ORCPT + 99 others); Tue, 4 Dec 2018 02:53:39 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46404 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725996AbeLDHxi (ORCPT ); Tue, 4 Dec 2018 02:53:38 -0500 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wB47nAYW030964 for ; Tue, 4 Dec 2018 02:53:37 -0500 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2p5kmrw8pj-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 04 Dec 2018 02:53:37 -0500 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 4 Dec 2018 07:53:34 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 4 Dec 2018 07:53:29 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wB47rSwm25821414 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 4 Dec 2018 07:53:28 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2A463AE045; Tue, 4 Dec 2018 07:53:28 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 30932AE053; Tue, 4 Dec 2018 07:53:26 +0000 (GMT) Received: from rapoport-lnx (unknown [9.148.206.196]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Tue, 4 Dec 2018 07:53:26 +0000 (GMT) Date: Tue, 4 Dec 2018 09:53:24 +0200 From: Mike Rapoport To: john.hubbard@gmail.com Cc: Andrew Morton , linux-mm@kvack.org, Jan Kara , Tom Talpey , Al Viro , Christian Benvenuti , Christoph Hellwig , Christopher Lameter , Dan Williams , Dennis Dalessandro , Doug Ledford , Jason Gunthorpe , Jerome Glisse , Matthew Wilcox , Michal Hocko , Mike Marciniszyn , Ralph Campbell , LKML , linux-fsdevel@vger.kernel.org, John Hubbard Subject: Re: [PATCH 1/2] mm: introduce put_user_page*(), placeholder versions References: <20181204001720.26138-1-jhubbard@nvidia.com> <20181204001720.26138-2-jhubbard@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181204001720.26138-2-jhubbard@nvidia.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-TM-AS-GCONF: 00 x-cbid: 18120407-0016-0000-0000-00000231B04F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18120407-0017-0000-0000-00003289B913 Message-Id: <20181204075323.GI26700@rapoport-lnx> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-04_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812040071 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi John, Thanks for having documentation as a part of the patch. Some kernel-doc nits below. On Mon, Dec 03, 2018 at 04:17:19PM -0800, john.hubbard@gmail.com wrote: > 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 is the first step of fixing the problem described in [1]. The steps > are: > > 1) (This patch): provide put_user_page*() routines, intended to be used > for releasing pages that were pinned via get_user_pages*(). > > 2) Convert all of the call sites for get_user_pages*(), to > invoke put_user_page*(), instead of put_page(). This involves dozens of > call sites, and will take some time. > > 3) After (2) is complete, use get_user_pages*() and put_user_page*() to > implement tracking of these pages. This tracking will be separate from > the existing struct page refcounting. > > 4) Use the tracking and identification of these pages, to implement > special handling (especially in writeback paths) when the pages are > backed by a filesystem. Again, [1] provides details as to why that is > desirable. > > [1] https://lwn.net/Articles/753027/ : "The Trouble with get_user_pages()" > > Reviewed-by: Jan Kara > > 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 > Signed-off-by: John Hubbard > --- > include/linux/mm.h | 20 ++++++++++++ > mm/swap.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 100 insertions(+) > > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 5411de93a363..09fbb2c81aba 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -963,6 +963,26 @@ static inline void put_page(struct page *page) > __put_page(page); > } > > +/* > + * put_user_page() - release a page that had previously been acquired via > + * a call to one of the get_user_pages*() functions. Please add @page parameter description, otherwise kernel-doc is unhappy > + * > + * Pages that were pinned via get_user_pages*() must be released via > + * either put_user_page(), or one of the put_user_pages*() routines > + * below. This is so that eventually, pages that are pinned via > + * get_user_pages*() can be separately tracked and uniquely handled. In > + * particular, interactions with RDMA and filesystems need special > + * handling. > + */ > +static inline void put_user_page(struct page *page) > +{ > + put_page(page); > +} > + > +void put_user_pages_dirty(struct page **pages, unsigned long npages); > +void put_user_pages_dirty_lock(struct page **pages, unsigned long npages); > +void put_user_pages(struct page **pages, unsigned long npages); > + > #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) > #define SECTION_IN_PAGE_FLAGS > #endif > diff --git a/mm/swap.c b/mm/swap.c > index aa483719922e..bb8c32595e5f 100644 > --- a/mm/swap.c > +++ b/mm/swap.c > @@ -133,6 +133,86 @@ void put_pages_list(struct list_head *pages) > } > EXPORT_SYMBOL(put_pages_list); > > +typedef int (*set_dirty_func)(struct page *page); > + > +static void __put_user_pages_dirty(struct page **pages, > + unsigned long npages, > + set_dirty_func sdf) > +{ > + unsigned long index; > + > + for (index = 0; index < npages; index++) { > + struct page *page = compound_head(pages[index]); > + > + if (!PageDirty(page)) > + sdf(page); > + > + put_user_page(page); > + } > +} > + > +/* > + * put_user_pages_dirty() - for each page in the @pages array, make > + * that page (or its head page, if a compound page) dirty, if it was > + * previously listed as clean. Then, release the page using > + * put_user_page(). > + * > + * Please see the put_user_page() documentation for details. > + * > + * set_page_dirty(), which does not lock the page, is used here. > + * Therefore, it is the caller's responsibility to ensure that this is > + * safe. If not, then put_user_pages_dirty_lock() should be called instead. > + * > + * @pages: array of pages to be marked dirty and released. > + * @npages: number of pages in the @pages array. Please put the parameters description next to the brief function description, as described in [1] [1] https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation > + * > + */ > +void put_user_pages_dirty(struct page **pages, unsigned long npages) > +{ > + __put_user_pages_dirty(pages, npages, set_page_dirty); > +} > +EXPORT_SYMBOL(put_user_pages_dirty); > + > +/* > + * put_user_pages_dirty_lock() - for each page in the @pages array, make > + * that page (or its head page, if a compound page) dirty, if it was > + * previously listed as clean. Then, release the page using > + * put_user_page(). > + * > + * Please see the put_user_page() documentation for details. > + * > + * This is just like put_user_pages_dirty(), except that it invokes > + * set_page_dirty_lock(), instead of set_page_dirty(). > + * > + * @pages: array of pages to be marked dirty and released. > + * @npages: number of pages in the @pages array. Ditto > + * > + */ > +void put_user_pages_dirty_lock(struct page **pages, unsigned long npages) > +{ > + __put_user_pages_dirty(pages, npages, set_page_dirty_lock); > +} > +EXPORT_SYMBOL(put_user_pages_dirty_lock); > + > +/* > + * put_user_pages() - for each page in the @pages array, release the page > + * using put_user_page(). > + * > + * Please see the put_user_page() documentation for details. > + * > + * @pages: array of pages to be marked dirty and released. > + * @npages: number of pages in the @pages array. > + * And here as well :) > + */ > +void put_user_pages(struct page **pages, unsigned long npages) > +{ > + unsigned long index; > + > + for (index = 0; index < npages; index++) > + put_user_page(pages[index]); > +} > +EXPORT_SYMBOL(put_user_pages); > + > /* > * get_kernel_pages() - pin kernel pages in memory > * @kiov: An array of struct kvec structures > -- > 2.19.2 > -- Sincerely yours, Mike.