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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BF40C433F5 for ; Thu, 16 Dec 2021 15:19:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A06F6B0073; Thu, 16 Dec 2021 10:19:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 850726B0074; Thu, 16 Dec 2021 10:19:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6F1B76B0075; Thu, 16 Dec 2021 10:19:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0248.hostedemail.com [216.40.44.248]) by kanga.kvack.org (Postfix) with ESMTP id 60F416B0073 for ; Thu, 16 Dec 2021 10:19:30 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 22B5583C3E for ; Thu, 16 Dec 2021 15:19:20 +0000 (UTC) X-FDA: 78924016080.12.3C63D6E Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) by imf11.hostedemail.com (Postfix) with ESMTP id B144140010 for ; Thu, 16 Dec 2021 15:19:17 +0000 (UTC) Received: by mail-qv1-f44.google.com with SMTP id kd9so1883010qvb.11 for ; Thu, 16 Dec 2021 07:19:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=IQa6+4S3HkIAKzN0VzmA4bvc4SzVQKH3U6rf2Bxxe9w=; b=TIgVjHnGVn3IN/RPHQvQRuimieQha+OdcjEiYTUV703IhFgkY/c/u2LFVEMX8EtZoE lyLeUZ4XbgYdF0RpXP/bs/fd8LnNNH8JOrZPvNzGLime+6vERssQLJ7fxgLlvx63zLRn 5oqyfl/9iTJYZlV9lZV98JnhQfM6jjXxB32BZaWezNEHlaT0sNC84qxirbAOq/zo4bSS 3STnCS8qmnKbVVV9HoA58We5KJsAYW8rbhQ9vVXkafBQfqALiE73hsQavnLsl2pwtZXR xsyGZNO3gnsAkNIGgBrOXk078UgzeEgWTR07pIsQxQfbS3A7BeHMhYsm+iN2d+QoimPG XPQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=IQa6+4S3HkIAKzN0VzmA4bvc4SzVQKH3U6rf2Bxxe9w=; b=3Tm5T4u2wxK+BVRqQPr2DtgWtmRTaDWS51bXb3niLsupmUXxDHMH1Fy3N1+WIkYNFK GUCLohf531wWylq8K3zEw4LvGuPFyQF71AswSoqQ+kPto/VyPj8vGTxMYEe/2NegccZO SWE2flsAROZ+OF4b2LTf2oXa+BYA9oHIx3D3NV+ZN0ELMeNP/+Bi3TO+OPUjJskgNvE3 FM3pb6Jn3N1SS/QWvAKwxcBiTNivHI9pQ4zUxKls1pLrdHB9ZqJtHmAUv5J3hoaWnNQM /hKMPKfDUEhrjr1vCXXQw4x5Ti1LMMpf4ONszddHc1+NhPgkQa1ezrYzn1LWUBszgsYU oyUQ== X-Gm-Message-State: AOAM532IE8jrqKguEg6MZGH2VFJ15i+jhjTo31ChJdpccHMY28/+AlRm UvkFCg7I/r5l5aklGqUcrYxglw== X-Google-Smtp-Source: ABdhPJzbhZ237JeRmhDeQugr6D2DXtlEp4AviNvKqjqRRl5znnHcZkBu25MI3NlXKiLwfH6jNwzOKQ== X-Received: by 2002:a05:6214:1467:: with SMTP id c7mr9886554qvy.116.1639667958805; Thu, 16 Dec 2021 07:19:18 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-162-113-129.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.129]) by smtp.gmail.com with ESMTPSA id de40sm2929346qkb.99.2021.12.16.07.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Dec 2021 07:19:18 -0800 (PST) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1mxsXN-005VJA-2c; Thu, 16 Dec 2021 11:19:17 -0400 Date: Thu, 16 Dec 2021 11:19:17 -0400 From: Jason Gunthorpe To: Matthew Wilcox Cc: "Kirill A. Shutemov" , linux-mm@kvack.org, Hugh Dickins , David Hildenbrand , Mike Kravetz Subject: Re: folio mapcount Message-ID: <20211216151917.GK6467@ziepe.ca> References: <20211216093737.7w2fv7p7j2rrx5r6@box.shutemov.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B144140010 X-Stat-Signature: 3nr8jgorqho6tsgbfaxq5sborkwyhfgg Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=ziepe.ca header.s=google header.b=TIgVjHnG; spf=pass (imf11.hostedemail.com: domain of jgg@ziepe.ca designates 209.85.219.44 as permitted sender) smtp.mailfrom=jgg@ziepe.ca; dmarc=none X-HE-Tag: 1639667957-549976 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 Thu, Dec 16, 2021 at 01:56:57PM +0000, Matthew Wilcox wrote: > p = mmap(x, 2MB, PROT_READ|PROT_WRITE, ...): THP allocated > mprotect(p, 4KB, PROT_READ): THP split. > > And in that case, I would say the THP now has mapcount of 2 because > there are 2 VMAs mapping it. At least today mapcount is only loosely connected to VMAs. It really counts the number of PUD/PTEs that point at parts of the memory. If, under the PTL, you observe a mapcount of 1 then you know that the PUD/PTE you have under lock is the ONLY PUD/PTE that refers to this page and will remain so while the lock is held. So, today the above ends up with a mapcount of 1 and when we take a COW fault we can re-use the page. If the above ends up with a mapcount of 2 then COW will copy not re-use, which will cause unexpected data corruption in all those annoying side cases. The actual value of mapcount doesn't matter, the main issue is if it is 1 or not, and if 1 the determination needs to be reliable and race free. Putting the mapcount on the head page is sort of an optimization 'all tail pages share the same mapcount' and the doublemap thing is about exiting that optimization with minimal locking. There is other stuff going on too that can possibly do other things but this seems to be the primary difficult task. (IIRC anyhow, from when I looked at this with David a few months ago) > I'm just trying to learn enough to make sensible suggestions for > simplification. As yesterday's call proved, there are all kinds of > corner cases when messing with mapcount and refcount. It would be amazing to get some better idea! Jason