Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp859246lqd; Wed, 24 Apr 2024 21:17:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXVlI3yPWSuPwN4InKm4HCL06tmfYKdxw+jZz4K7poXSrxiQ9Lz9z5Y7LCFUBa7EKbVFOut7RnzurbwljsLzLePvD4Y7J8GZalfSlCrlg== X-Google-Smtp-Source: AGHT+IGNEK4V06w8bIn9RyTPGD0B09T/srzDnyshf3cdzdIEhMOH/45hhuW4eSS3DckBj6UNtWnq X-Received: by 2002:a05:620a:8320:b0:790:829c:91a7 with SMTP id pa32-20020a05620a832000b00790829c91a7mr4798223qkn.24.1714018654116; Wed, 24 Apr 2024 21:17:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714018654; cv=pass; d=google.com; s=arc-20160816; b=I1fXcJ65UEzI38fax9QeqmxeegLihz7pW+js3aQZDLm601CJbl6Sgl68t+bmHI30TO ybjFdGIS1xrH7yWv/5QjJP2jNV1T6jOXLD9YFu6GtHSStCAEbsG9PDgZR8JKvYvIrXCk PgjfUCTwB53zDvIpQSwvKw2nk+4tXKkYkVWGFJODOOlNK8Lf/ysZ1+CPVIAtdr5csSO5 wMYxBmAmBg8meT8een5sullY+pf0CaW/2SJaZwGxGef+oaJu25D+BNSmyybjo8xhSCJV msHgCb2gsuLbVE9fgtBw1sjPBv2pciWQ0NAK6q3CeyG9cDvKl2v2ket9QzMOZYl50KeG 8WmA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ANgVjP9MVyrfjCZEO3eEEJT1uU8xEYCqPXFBgzQpPAM=; fh=OJyFYi5Qt5UNQTIjlB9LFvEKJQEohNtodNjwREFTIeg=; b=SEYpP51N1ipbm1yiypspk6TyZm23mof3rl8vEO2mbRmSs/OXBhEnKrHkM67CqRP1rR NqYrMAXBZ92DXnm6ejFSz0brD6dqGeJRECvad7HZN7hi2uqPqEi2IExaskoWvHgJtK3M Idkh8T6ulLlXsx1C4FO7YZsff5MPtiQiXtHGJNYIn/vusyT4Ws3p7ywQ6ZqaqpwJVIp3 vrgBU+tmxO3iEXROtV/1/cgtm+5do6QZidnjpvSxqKv/izmwovhvdSKbyeHNDTQN4VoT 8mO7cDP40I9RjkaRmcjxFIjtoxuD/F3MmSIny188UVib1KKbz+CNmlTzlhr+9/KROgrN dnWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=kbKPXNpJ; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-157988-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157988-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f20-20020a05620a15b400b0079089139e20si4057650qkk.472.2024.04.24.21.17.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 21:17:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157988-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=kbKPXNpJ; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-157988-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157988-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D16131C20FB6 for ; Thu, 25 Apr 2024 04:17:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C12B381AF; Thu, 25 Apr 2024 04:17:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="kbKPXNpJ" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 625362E642; Thu, 25 Apr 2024 04:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714018647; cv=none; b=p75z29uOv9DLN3WBxIlhN7Kwa1WLac0SJ8ntCds47MQQG5awKh8LBTodCwj1l3/9ubsqtsHJpUJwAyi+gc+TCbgkMhXglsaIRaLHPYR3sYulBqO2ymUrCWYJxeEpA3JPd7NGt8oLnHUUBskDU/0UOXFIc3ce6/eXsxGWDUuYuyM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714018647; c=relaxed/simple; bh=ne1fnBZqwQGJ6Xqqco9hd+ZpZLo54dfTsunxLhOYsMg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CldUgrTHxvCAjynPVT4uuvY2rECvOXpHevUIo8CiTP9AeyQfaPcncN/gYtjyir2Xj6yW7w0n74T0nJFEtCkyZ/KX4e9UlOI0HFYf3V+Y+D7kHuxK6dz3dbL3MechGu3ML3WbCWaY5F2wBo/AA301H2N1P8iOle+SiaWG7k8qsWc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=kbKPXNpJ; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org 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=ANgVjP9MVyrfjCZEO3eEEJT1uU8xEYCqPXFBgzQpPAM=; b=kbKPXNpJvsZf7A/62Zcy59tMFi yrULr3msYj/XIPTJLrxxkcPYlENIJBAlIF3NR2twl0wiQFwWwvp0u5hMoL5l3OxDEsdVqAJNkDz1U Z/PWhigmVZtMUWPKtqr71QCrZcvuDBStKU9u+yeSJMbhQzBremnJ+S7kOixjGiAVPmovoPbjuKHDc im1qXIx7jatqxBXVFCOcUm8xzYa3aBOtl1r1MBDX1sKTM4Us/aV/ubnarVnNbJG8cUBADJZBSTep+ m6B3BIWNq6u8T9xKif86DQeleaMZ1v1Gr5m542FGLxFUCH6aZQS/0PHsbYPbsm/A5pL2oeXfE3tnO cv4pNm5w==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzqXo-00000002INc-3GeG; Thu, 25 Apr 2024 04:17:12 +0000 Date: Thu, 25 Apr 2024 05:17:12 +0100 From: Matthew Wilcox To: John Hubbard Cc: David Hildenbrand , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, Andrew Morton , Jonathan Corbet , "Kirill A . Shutemov" , Zi Yan , Yang Shi , Ryan Roberts Subject: Re: [PATCH v1] mm/khugepaged: replace page_mapcount() check by folio_likely_mapped_shared() Message-ID: References: <20240424122630.495788-1-david@redhat.com> <73de5556-e574-4ed7-a7fb-c4648e46206b@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <73de5556-e574-4ed7-a7fb-c4648e46206b@nvidia.com> On Wed, Apr 24, 2024 at 09:00:50PM -0700, John Hubbard wrote: > > We want to limit the use of page_mapcount() to places where absolutely > > required, to prepare for kernel configs where we won't keep track of > > per-page mapcounts in large folios. > > > Just curious, can you elaborate on the motivation? I probably missed > the discussions that explained why page_mapcount() in large folios > is not desirable. Are we getting rid of a field in struct page/folio? > Some other reason? Two reasons. One is that, regardless of anything else, folio_mapcount() is expensive on large folios as it has to walk every page in the folio summing the mapcounts. The more important reason is that when we move to separately allocated folios, we don't want to allocate an array of mapcounts in order to maintain a per-page mapcount. So we're looking for a more compact scheme to avoid maintaining a per-page mapcount. > > The khugepage MM selftests keep working as expected, including: > > > > Run test: collapse_max_ptes_shared (khugepaged:anon) > > Allocate huge page... OK > > Share huge page over fork()... OK > > Trigger CoW on page 255 of 512... OK > > Maybe collapse with max_ptes_shared exceeded.... OK > > Trigger CoW on page 256 of 512... OK > > Collapse with max_ptes_shared PTEs shared.... OK > > Check if parent still has huge page... OK > > Well, a word of caution! These tests do not (yet) cover either of > the interesting new cases that folio_likely_mapped_shared() presents: > KSM or hugetlbfs interactions. In other words, false positives. Hmm ... KSM never uses large folios and hugetlbfs is disjoint from khugepaged?