Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1218864pxb; Fri, 6 Nov 2020 04:16:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJwW7YAg//QxjbCC4/JLC/njr+VBx2h17+ESF9sew5f+CgbbfLIgSNwVwmgnxiQpOTiet7NN X-Received: by 2002:a17:906:19c3:: with SMTP id h3mr1729217ejd.395.1604664970195; Fri, 06 Nov 2020 04:16:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604664970; cv=none; d=google.com; s=arc-20160816; b=daWRUYXvWnxXq7xwfIbXGjjnJWshQOHrkw3n1w2xb/0CqeDBbJp8iLYhYWy5oZ7fHk n/PjenW+8D9T0ELsyFC+B9d0iJhYg4gNjYhbnVMb/q5C1XpuGUy5wzmJWmY2FOLfJrYt uYnBk78jzEdupck150u8xada+cZ+Z+IFoqIeQ9LQA6lk8q8zxBo2mGhLUzIqva2I6UPG X8Ygtgmpvfm9eg/rj770dqS4jiarRhHC7IyIFTItL9SOIuURSzA1sG5xM2nNDqP3LAG1 YOVWSKyawzyz2zuyZkxvcepGH4p3qxQYXU4oXDBpC3JUjua0knAJVFsVrJSytma9T1+Q W7Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wdArR4SHu2gVwVCDPOZrqVGBGWB7EWn5STqcT4bB33k=; b=H4YU/830WPs3X0dvKLZz9y1sPplSCnwxT5NSJWeBzPeOl89sTLSucNY5x05hGMdP5p mvzNFxoV+sNeqoPyHJ+GOmq5h36sPon2nMNceAuT/xcsuivbeAB7P32MHnD9xe8y9JFn Ei/SjI5Q4fLpzvJ/J6TVvy+sZcWI7LxnAHc+F5m37mRH47ij/Sg5U1Vwm5vA4BGsfHI0 82S+3QHNZXkk3PUed/Nv6lLY+8cFLHoU0oYoQWA00pJUYr/9uvPst/m7LP8kOaYRN0qY eEIOftKZ4hu3ee0AcL8uuwuNE1iYeiCok/TDhLoAc4vWhv10ci4tp0QVf74ZIa84Ml7y zlmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=aOkaNP8W; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p5si692135ejf.528.2020.11.06.04.15.44; Fri, 06 Nov 2020 04:16:10 -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=@infradead.org header.s=casper.20170209 header.b=aOkaNP8W; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727249AbgKFMOS (ORCPT + 99 others); Fri, 6 Nov 2020 07:14:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726939AbgKFMOS (ORCPT ); Fri, 6 Nov 2020 07:14:18 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C120C0613CF; Fri, 6 Nov 2020 04:14:18 -0800 (PST) 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=wdArR4SHu2gVwVCDPOZrqVGBGWB7EWn5STqcT4bB33k=; b=aOkaNP8WZH4t1Wns/ePyMSfp5O 155hPzRmP47qJCbmYtSQvXMqvRjT43bFMlTyiCKhIu25g6ZNZ61hhu6RRcePjR7HRtHf5BFqScCgY wC+CrZOl8xhJ4LGMfj06PRCHNvouk1xIyuoh3rz6S+eX5f0+wk35xlfsDHIy/LfRSMBWjfRRuc/4I i6rwfhMnKN2PiMR1hTVfOLsV6KoSUcNNtzkuFGcwClnRC2me+NCB+UTOGSDB69/JZx7yrzuz5tcDj xLebLHADq8qaWnlZH36ddbmZtSfNSfE3A3e1Pg45fmRxj7uHMzvkM5vL0iPCODUeUjxCApzedsJJl A38knfLg==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kb0d5-0006Re-7j; Fri, 06 Nov 2020 12:14:07 +0000 Date: Fri, 6 Nov 2020 12:14:07 +0000 From: Matthew Wilcox To: Ralph Campbell Cc: linux-mm@kvack.org, nouveau@lists.freedesktop.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Jerome Glisse , John Hubbard , Alistair Popple , Christoph Hellwig , Jason Gunthorpe , Bharata B Rao , Zi Yan , "Kirill A . Shutemov" , Yang Shi , Ben Skeggs , Shuah Khan , Andrew Morton Subject: Re: [PATCH v3 1/6] mm/thp: add prep_transhuge_device_private_page() Message-ID: <20201106121407.GQ17076@casper.infradead.org> References: <20201106005147.20113-1-rcampbell@nvidia.com> <20201106005147.20113-2-rcampbell@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201106005147.20113-2-rcampbell@nvidia.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 05, 2020 at 04:51:42PM -0800, Ralph Campbell wrote: > Add a helper function to allow device drivers to create device private > transparent huge pages. This is intended to help support device private > THP migrations. I think you'd be better off with these calling conventions: -void prep_transhuge_page(struct page *page) +struct page *thp_prep(struct page *page) { + if (!page || compound_order(page) == 0) + return page; /* - * we use page->mapping and page->indexlru in second tail page + * we use page->mapping and page->index in second tail page * as list_head: assuming THP order >= 2 */ + BUG_ON(compound_order(page) == 1); INIT_LIST_HEAD(page_deferred_list(page)); set_compound_page_dtor(page, TRANSHUGE_PAGE_DTOR); + + return page; } It simplifies the users. > +void prep_transhuge_device_private_page(struct page *page) > +{ > + prep_compound_page(page, HPAGE_PMD_ORDER); > + prep_transhuge_page(page); > + /* Only the head page has a reference to the pgmap. */ > + percpu_ref_put_many(page->pgmap->ref, HPAGE_PMD_NR - 1); > +} > +EXPORT_SYMBOL_GPL(prep_transhuge_device_private_page); Something else that may interest you from my patch series is support for page sizes other than PMD_SIZE. I don't know what page sizes your hardware supports. There's no support for page sizes other than PMD for anonymous memory, so this might not be too useful for you yet.