Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp123082lqb; Tue, 16 Apr 2024 10:26:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVES7ypX7K2143FA8INT3iPhjwQaywsXNFmOeojLlJDHhODsSia+L3ouflmIjf/O/NvJDiiz71IoktoCLwe7NfAy2wZmEU3dLl5xK80Ug== X-Google-Smtp-Source: AGHT+IEmcSR8GX/NslRfqLAT7WLCQEONIWNnbwEfm1WGQd63nIw8VDa69m+oJj9SFY2hkTolkJCG X-Received: by 2002:a50:cd98:0:b0:56e:3293:3777 with SMTP id p24-20020a50cd98000000b0056e32933777mr11339138edi.17.1713288382757; Tue, 16 Apr 2024 10:26:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713288382; cv=pass; d=google.com; s=arc-20160816; b=AOjBPPXdXtIzuY7PcnnMQ/rHlD34OcBkXmXMU8FHRpWyAYQUWJlqyiC6UIfZXYJPeI dsxKiS56HdENNRLbSZTOJJzdXNLoSK0miYMaUI1IMzrr8Esa4BP5uO0G3y6TTPQqdy9l gNG5Q/ZoOEUjDE/4KEf7NdU99k1WD5hbyE0QG5kvPBVo5ZWw1sn2MesyES7vzmtEn+x7 cAuvU6GkRFJmrNE+eHURRjdVRRv3W5DXRAr4+BpKTjiYdJHTDTXT8+ABbaX+swP4ozRy 4gtKs44QRnB0hCvLnuX/ff4Q4wzJLVQ3yfXexRdK2mVQYbSFI6Ypy1WOM4fCjZOcWx/l E3Kw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=1onEK+mjIGOBc7x6Ypb0bDNESgiVTW/1kwHRGIFFvkM=; fh=CkxnToVifuZ6SqLmI89ORYTCe1B62HdKBcNuDV7kujw=; b=LcHcUyTJXIf0+eH+CjkkM8rYPCiHpyVSB/dDex3MrvASSkBDk8tuDHgEfdwZ8dsYFO g4JTQigU2B5i7KPz8i5O2V2/ePq0HxtMGicOYjxi9FaKDdxv554QkTFH21p692kxheUX hlHq2cojlMUp9rtQmDLfoIsTQNT2+MZB9URxa+Ym2INkkCzrHDrblqQq/Gc+uwN4I1J2 fjBVNF1abaISxfGWEes8xw53jciJUHhU3+tDTmlbr+D9aqIo9OB0X18vvDeUTArvk9Cy rNyp4yvqwmn3JHsZivbK++OV9J7qPobccyPOTjUK9vpAbwQyuEvW0PN0NdvV7Wi0m91e hfPA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c8XALg5n; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-147306-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147306-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id t20-20020a508d54000000b0056ffb0b0307si4780394edt.147.2024.04.16.10.26.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 10:26:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147306-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c8XALg5n; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-147306-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147306-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 50A231F22DA6 for ; Tue, 16 Apr 2024 17:26:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8026E134403; Tue, 16 Apr 2024 17:26:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="c8XALg5n" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 287EF13340D for ; Tue, 16 Apr 2024 17:26:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713288362; cv=none; b=BaUKzemER9EFNMUtPUO3EIA5y67/2ajG3sxCrUgxc6xbOCUTqf8WApyKmpNe8Ozu2ZxO3O2xN35jZxolXSGTe6AhZLEAYkWAiEjWhSwIwO7kmeWFdnqt6/W7uaBmp00kxp86xRjev2hpLcf4UL6qInUXqCEa2BENDf89bNlkKeM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713288362; c=relaxed/simple; bh=IJuIYdnF0LWSygsLwsn6+waVDToijuxbtvLwjuDB96c=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=mIRxUiICfNdtdcjaOm5Aji2P0gRw3xV4kLHC8J1ZAFoA8d23/cPqWgJBsiyMPZLFTP76lUgbHDIqo+B6zPnSsplkKk5/VbmChek/pFBDAS05+jmbmDq2Im+aAI/K3yBi7SbzC+BESAn6lV8YXrhbaJZN4uZYLxjulFYV5L5IT7s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=c8XALg5n; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713288359; 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=1onEK+mjIGOBc7x6Ypb0bDNESgiVTW/1kwHRGIFFvkM=; b=c8XALg5nBqwNPx1DayV83y2zB9+ljr31D2dNqH1TSxhL7U0R1fgr2qbEa3+7xy+tStjB3e c4Xyf1tqtSWFVYpDFQqToSes1kbFa7UbMSqX4qogAOlPPa/UACkKCFamkQ/8aZQLPcucwV i9NcRbl9MfOYY4m711OezJK4M4Csbms= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-46-CG4LeTsyOi2kOFzEDet5uA-1; Tue, 16 Apr 2024 13:25:56 -0400 X-MC-Unique: CG4LeTsyOi2kOFzEDet5uA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2837A811001; Tue, 16 Apr 2024 17:25:56 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB2A949106; Tue, 16 Apr 2024 17:25:53 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Alex Shi Subject: [PATCH v1] mm/ksm: remove page_mapcount() usage in stable_tree_search() Date: Tue, 16 Apr 2024 19:25:33 +0200 Message-ID: <20240416172533.663418-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 We want to limit the use of page_mapcount() to the places where it is absolutely necessary. If our folio has a stable node, it is a (small) KSM folio -- see folio_stable_node(). Let's use folio_mapcount() in stable_tree_search() instead, which results in no functional change. The mapcount > 1 check is a bit confusing, because that's usually a check for page sharing. Looks like the reason is that we are guaranteed to not exceed ksm_max_page_sharing for the tree KSM folio when merging with that. Let's update the documentation to make that clearer. Cc: Andrew Morton Cc: Alex Shi (tencent) Signed-off-by: David Hildenbrand --- mm/ksm.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 486c9974f8e20..159604ad47799 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1909,12 +1909,15 @@ static struct page *stable_tree_search(struct page *page) if (page_node) { VM_BUG_ON(page_node->head != &migrate_nodes); /* - * Test if the migrated page should be merged - * into a stable node dup. If the mapcount is - * 1 we can migrate it with another KSM page - * without adding it to the chain. + * If the mapcount of our migrated KSM folio is + * at most 1, we can merge it with another + * KSM folio where we know that we have space + * for one more mapping without exceeding the + * ksm_max_page_sharing limit: see + * chain_prune(). This way, we can avoid adding + * this stable node to the chain. */ - if (page_mapcount(page) > 1) + if (folio_mapcount(folio) > 1) goto chain_append; } -- 2.44.0