Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7650919rwb; Wed, 23 Nov 2022 09:03:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf6I6cyBzoO6wqeKJZ16nGxC6oecpCuP2NGfbzXpZ0TAad/4SflGWosNCEYMGDFAW+cADCZu X-Received: by 2002:a17:90a:fe92:b0:213:ef84:195a with SMTP id co18-20020a17090afe9200b00213ef84195amr30919565pjb.177.1669223030410; Wed, 23 Nov 2022 09:03:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669223030; cv=none; d=google.com; s=arc-20160816; b=g16nX51hEjFT6sWbxxsb4POJthWAcWL4B917FPR+wnfV3dy7n+mRKJ5LO3V9G3DCuc 9EmufYDOUHEv3zed0CuzOToOCesP80GerysmE4cfNW4LcYNQl0lnLpzxa7blhs8IAT4x JSt2k/IPjlOh6dtQuFv9U5xyTRJYJa+kDobq6mUXRpzp1LTFfGanmhkQxnCsOt5Mt229 A/Vjw2acDFsWVdKwL1kskO7mQmH5lKQQWDUPRboHkIYNNfokw1Mt/+n/ShBlnd9VNX55 g8kL0kuazhGizemUC1rSUvCBOLC2FHJjP7mQvXvrpbiBjQvl9APwlo/rA7qm/hvJL2w+ FvGg== 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=sXPQl1YCs6Mf/k1U0Y2ft9SkDteXobSD5EsA9lUmMoc=; b=zrd+GbjHyTgJpWVYgdRG1LMKWeJCJ+RY9Tye6P9ZwqlOaMs2xQOa8T/lKJH51BfC6s o6jSuepoGPOc2mWy9gAV75A2eUhZULKli78EzpgrhCX808ukSHH82nyilbiandSSYGg3 8bqfCTjDDscJif/UHOm4lc/I4arsMvQqcZYus3BTQ3zORX6bQ7F7b+rzyCxtpfQ8MZNi 8AQGwaK4jijtcLluP7hIdIg2g5SXEx3DcxZ2VLQJxyeZNpEpFupjWKGdPmpbYesmXKqX 8YQ/3iOO0xk7N1DRysQz73qLQLqmPspsPr/1f16IfS0IVJYy8cli2kILA+VH4TPVYTko 4b/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=wK6p3Ixs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a21-20020a63e855000000b00476b15a02cesi7268936pgk.70.2022.11.23.09.03.37; Wed, 23 Nov 2022 09:03:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=wK6p3Ixs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238688AbiKWQHS (ORCPT + 88 others); Wed, 23 Nov 2022 11:07:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237705AbiKWQHQ (ORCPT ); Wed, 23 Nov 2022 11:07:16 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD4641088 for ; Wed, 23 Nov 2022 08:07:14 -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=sXPQl1YCs6Mf/k1U0Y2ft9SkDteXobSD5EsA9lUmMoc=; b=wK6p3Ixs4mi/OdEnPqTQiHQPWb DO57EVXUpyIl7hGks9JwF6K0xAph5UN4ZTuSvlrjIobF852T6qghB6h575mqOEqjgufwUzWtcq2Gv 5sooHj86ltRIuoSKDNz3Qcjwspl598rYwsmRr6kdGH9YMbbC+5sCZpJTJEWk3Ggb//DcPCPfK6eXX cbUNyEjZBM4xkbhxMAAOcPSkVPW0Px/kqRJw8T5P77fhCT67J2XmvVIGkGhpVNyCc1B7hsk05pYPi q8un9ay9sU4Op7tb6/wzJRftYQi4m4Sknal3i2gmJXLP91lW8qf0pSNRV/MGyBix/TVWuf/JFaKQv GPglhEwA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxsHF-007nFR-Hj; Wed, 23 Nov 2022 16:07:09 +0000 Date: Wed, 23 Nov 2022 16:07:09 +0000 From: Matthew Wilcox To: David Hildenbrand Cc: Hugh Dickins , Gavin Shan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, william.kucharski@oracle.com, ziy@nvidia.com, kirill.shutemov@linux.intel.com, zhenyzha@redhat.com, shan.gavin@gmail.com, riel@surriel.com, apopple@nvidia.com Subject: Re: [PATCH] mm: migrate: Fix THP's mapcount on isolation Message-ID: References: <20221123005752.161003-1-gshan@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 23, 2022 at 09:56:38AM +0100, David Hildenbrand wrote: > But we do have an even better helper in place already: > mm/huge_memory.c:can_split_folio() > > Which cares about > > a) Swapcache for THP: each subpage could be in the swapcache > b) Requires the caller to hold one reference to be safe > > But I am a bit confused about the "extra_pins" for !anon. Where do the > folio_nr_pages() references come from? When we add a folio to the page cache, we increment its refcount by folio_nr_pages() instead of by 1. I suspect this is no longer needed (if it was ever needed) and it could be changed. See __filemap_add_folio(): long nr = 1; if (!huge) { nr = folio_nr_pages(folio); folio_ref_add(folio, nr); > So *maybe* it makes sense to factor out can_split_folio() and call it > something like: "folio_maybe_additionally_referenced" [to clearly > distinguish it from "folio_maybe_dma_pinned" that cares about actual page > pinning (read/write page content)]. > > Such a function could return false positives/negatives due to races and the > caller would have to hold one reference and be able to deal with the > semantics. I don't like the 'pextra_pins' parameter to a generic function ...