From patchwork Wed Jul 31 16:07:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13748949 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 15897C3DA64 for ; Wed, 31 Jul 2024 16:08:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 833626B0083; Wed, 31 Jul 2024 12:08:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E3416B0088; Wed, 31 Jul 2024 12:08:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D1F26B0089; Wed, 31 Jul 2024 12:08:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4FD7E6B0083 for ; Wed, 31 Jul 2024 12:08:08 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 04ED61A046E for ; Wed, 31 Jul 2024 16:08:07 +0000 (UTC) X-FDA: 82400529456.18.CFED55A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 4D88CC002B for ; Wed, 31 Jul 2024 16:08:06 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DmSC457k; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722442030; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=GoBWNItCy+5p/s715HtqO2A6k5AaBk19nlaEIZQ3fA8=; b=X6F2H7ZVDqmzF1SBEh/67DEOcGdQ8923DK6lmE6Ej/kaMDzZiN8l/mf+tzr2Fuo1oDhfxR tQBoujnR0KTur1DFoSAORk31h3XHows7DlfdDMmuMD6GWr9QJTTeeCaPRItsfYfFcYPhzx YyT0ELIaZMEqPMwlWfC987/f6PZYM+I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722442030; a=rsa-sha256; cv=none; b=W0ndhFLfOvOjtXuepqCghr1v8WvjgjjmSfcWBoGGMydiUO7Vcllg1L6Msa+p1WgfGOCiqd DsuhKPDFOaOucSE4AxHxsGHBFJQ1JBldYpcdB12IV/1/tJW7JBnA5N+gRuGQ9WAB1PNitp J6HWu7mtLqdhyBSBx4fFv93BC5SjSmY= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DmSC457k; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722442085; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=GoBWNItCy+5p/s715HtqO2A6k5AaBk19nlaEIZQ3fA8=; b=DmSC457kbg4C7VBPMS9x9XdqhPwrQUGdc4TrCulMLpbyjLBsU27qEJiHj0LzkwJQ04CDwY J7Mc6r7XoYfyxoLTwcWOeb9qT5xaeDRh40D8zYN6QGixEkBiBwjkoBRls2baBJAdDH2CYM 0AQmkjZdSZyKik3qIFhD2ZqKP3vLUxk= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-UW0f7oMtOV6TwNVlqTZEhg-1; Wed, 31 Jul 2024 12:08:04 -0400 X-MC-Unique: UW0f7oMtOV6TwNVlqTZEhg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BE4E21955D45; Wed, 31 Jul 2024 16:08:02 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.194.228]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 400311955D42; Wed, 31 Jul 2024 16:08:00 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton Subject: [PATCH v1] mm: clarify folio_likely_mapped_shared() documentation for KSM folios Date: Wed, 31 Jul 2024 18:07:58 +0200 Message-ID: <20240731160758.808925-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4D88CC002B X-Stat-Signature: gj1kwfk3z8wayaigef6kxkcnfospoac8 X-HE-Tag: 1722442086-321184 X-HE-Meta: U2FsdGVkX1+P31aOZoyOQzgFLyYAQiPKz74NYOzlDMmb5WcOLvz4qfmhhhflY8admXsU1twBgp+WD7MEsY/GqZCa1mMqOs5E6mJp84ILjzqyWER5kV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oNB4Nmvr7S8OPBapgNBRpZMASOhuqHQkhzcUvV/zHsWYC2ldA75Bwti7iZFI+UGDO0XrQiLuW6BnF8cjYPp3CS7aW51VBzt4QRfnvvWb8+IemJ5WelH5S3GcD/kBPEGGC+Eq2I4ZzQHe3dhW3EYrWq6mjDyBZjm2s3oCihKyI41pQuAuYtiENcGKtIFsFMCVYYtRxWNBxh3XPg== 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: List-Subscribe: List-Unsubscribe: For KSM folios, the function actually does what it is supposed to do: even having multiple mappings inside the same MM is considered "sharing", as there is no real relationship between these KSM page mappings -- in contrast to mapping the same file range twice and having the same pagecache page mapped twice. Cc: Andrew Morton Signed-off-by: David Hildenbrand --- include/linux/mm.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index a890a1731c14..58ca060f5dce 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2132,14 +2132,19 @@ static inline size_t folio_size(const struct folio *folio) * MM ("mapped shared"), or if the folio is only mapped into a single MM * ("mapped exclusively"). * + * For KSM folios, this function also returns "mapped shared" when a folio is + * mapped multiple times into the same MM, because the individual page mappings + * are independent. + * * As precise information is not easily available for all folios, this function * estimates the number of MMs ("sharers") that are currently mapping a folio * using the number of times the first page of the folio is currently mapped * into page tables. * - * For small anonymous folios (except KSM folios) and anonymous hugetlb folios, - * the return value will be exactly correct, because they can only be mapped - * at most once into an MM, and they cannot be partially mapped. + * For small anonymous folios and anonymous hugetlb folios, the return + * value will be exactly correct: non-KSM folios can only be mapped at most once + * into an MM, and they cannot be partially mapped. KSM folios are + * considered shared even if mapped multiple times into the same MM. * * For other folios, the result can be fuzzy: * #. For partially-mappable large folios (THP), the return value can wrongly @@ -2148,9 +2153,6 @@ static inline size_t folio_size(const struct folio *folio) * #. For pagecache folios (including hugetlb), the return value can wrongly * indicate "mapped shared" (false positive) when two VMAs in the same MM * cover the same file range. - * #. For (small) KSM folios, the return value can wrongly indicate "mapped - * shared" (false positive), when the folio is mapped multiple times into - * the same MM. * * Further, this function only considers current page table mappings that * are tracked using the folio mapcount(s).