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=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 320BFC32771 for ; Mon, 27 Jan 2020 11:24:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 043A320CC7 for ; Mon, 27 Jan 2020 11:24:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729712AbgA0LXu (ORCPT ); Mon, 27 Jan 2020 06:23:50 -0500 Received: from mx2.suse.de ([195.135.220.15]:41032 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729530AbgA0LXt (ORCPT ); Mon, 27 Jan 2020 06:23:49 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 51770AFF0; Mon, 27 Jan 2020 11:06:25 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 356041E0E4E; Mon, 27 Jan 2020 12:06:24 +0100 (CET) Date: Mon, 27 Jan 2020 12:06:24 +0100 From: Jan Kara To: John Hubbard Cc: Andrew Morton , Al Viro , Christoph Hellwig , Dan Williams , Dave Chinner , Ira Weiny , Jan Kara , Jason Gunthorpe , Jonathan Corbet , =?iso-8859-1?B?Suly9G1l?= Glisse , "Kirill A . Shutemov" , Michal Hocko , Mike Kravetz , Shuah Khan , Vlastimil Babka , linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-rdma@vger.kernel.org, linux-mm@kvack.org, LKML , "Kirill A . Shutemov" Subject: Re: [PATCH 1/3] mm/gup: track FOLL_PIN pages Message-ID: <20200127110624.GD19414@quack2.suse.cz> References: <20200125021115.731629-1-jhubbard@nvidia.com> <20200125021115.731629-2-jhubbard@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200125021115.731629-2-jhubbard@nvidia.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org On Fri 24-01-20 18:11:13, John Hubbard wrote: > +static __maybe_unused struct page *try_grab_compound_head(struct page *page, > + int refs, > + unsigned int flags) > +{ > + if (flags & FOLL_GET) > + return try_get_compound_head(page, refs); > + else if (flags & FOLL_PIN) { > + int orig_refs = refs; > + > + /* > + * When pinning a compound page of order > 1 (which is what > + * hpage_pincount_available() checks for), use an exact count to > + * track it, via hpage_pincount_inc/_dec(). > + * > + * However, be sure to *also* increment the normal page refcount > + * field at least once, so that the page really is pinned. > + */ > + if (!hpage_pincount_available(page)) > + refs *= GUP_PIN_COUNTING_BIAS; > + > + page = try_get_compound_head(page, refs); > + if (!page) > + return NULL; > + > + if (hpage_pincount_available(page)) > + hpage_pincount_inc(page); Umm, adding just 1 to pincount looks dangerous to me as try_grab_compound_head() would not compose - you could not release references acquired by try_grab_compound_head() with refs==2 by two calls to put_compound_head() with refs==1. So I'd rather have here: hpage_pincount_add(page, refs) and similarly in put_compound_head(). Otherwise the patch looks good to me from a quick look. Honza -- Jan Kara SUSE Labs, CR