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 131ACC32771 for ; Mon, 27 Jan 2020 11:06:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D4AD4206A2 for ; Mon, 27 Jan 2020 11:06:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D4AD4206A2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 853BF6B0003; Mon, 27 Jan 2020 06:06:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 804FE6B0006; Mon, 27 Jan 2020 06:06:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71B9B6B0007; Mon, 27 Jan 2020 06:06:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0030.hostedemail.com [216.40.44.30]) by kanga.kvack.org (Postfix) with ESMTP id 5936E6B0003 for ; Mon, 27 Jan 2020 06:06:28 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 1FC55180AD804 for ; Mon, 27 Jan 2020 11:06:28 +0000 (UTC) X-FDA: 76423135656.08.pies25_1b50d210f9028 X-HE-Tag: pies25_1b50d210f9028 X-Filterd-Recvd-Size: 3220 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Mon, 27 Jan 2020 11:06:27 +0000 (UTC) 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) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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