Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp1997298lqt; Sun, 21 Apr 2024 19:45:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUprbfql8+Shqb9JsVyy9qqV94syofqDdEwPJ6DiO0x7ecswvAjbIzELAW/lRUnKv9x2rBayHI3ZeRgeJf6+iOMv5DGCm6ljbyLy2OEqg== X-Google-Smtp-Source: AGHT+IHEW2HU45wNecQ0NZjepLTTBK250nItd3yUFraXKzLC54SHw0tlURkMIvkyHclHWEwG3H0t X-Received: by 2002:ac8:7f02:0:b0:437:b3f2:b333 with SMTP id f2-20020ac87f02000000b00437b3f2b333mr9571844qtk.10.1713753909686; Sun, 21 Apr 2024 19:45:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713753909; cv=pass; d=google.com; s=arc-20160816; b=gousPgiuCeJMXdcf7BZ2dGIo9a0AByGDRzzNYvoTUrRCjdekJa56bhP3bvEmM2Wtwz Fvc9hoeoaqsJgHaQp0iGzu0XOfaCU3aXnDrUtnzgtp8aXzpFsWd4hTS/Vjl2COVMaXiQ MmYVPzhkgBpEiMvK1QeUn98yOSV/A8lFnDs6Xft4Tf0F3VOcfsLvAMR0OqrS3DZujAjO VpjmF1rGgibq5PITRLRuc/IJEb7rlivoa8uYZgVFJP6U34PEqRpR4BvMlz1381BNTWDI GZKhsnwTNWL3IOA317fPZLaCvGCqOoX1KxWF+0iuPyzFg7D8Sk1LEatGUb7dbY+067l1 7cZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=XIK5vML3v/bdvHLH+Cj3KR7pbajmQ/BzdHOwU1URj74=; fh=hzzTYIAL0HFGu/z7YQhdMXxjF6Qs9gXDo/+ezYBSgBQ=; b=cAs1pAlwk6NQ/HjA3+HPfm4zbQO/NTVM3YsMOhpVihdFLvlTTLMxNxxcwqEULyFczf foX+W+gNptk4VBxlGvf8m7Vg0nwE0gM2M0WIPZkUqOFgnkOFaQUVBvBpsIRTTJbNH9R8 ST29Kr5GHE5tu0KUzi+X7DQ3SiNKarxMAFchDavJJESYugwgN9hOwPjEp8fgTdAhg/3Q cIwIxXed/U6PgP1DTt0Sh/ljB9u/6YPBF7pw3uFLwyw6v8VHuP5z+k0g+5lxh7bXslve LlnHuCsrsjotYkLDZv+rShcw/57fQb4IbUrqRfB+A7ximK6XkiIf2igj2RfncssKIq3P hMhg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dapfjYMZ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-152685-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152685-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a8-20020a05622a064800b004344b882955si9570428qtb.779.2024.04.21.19.45.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 19:45:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152685-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=dapfjYMZ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-152685-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152685-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6C2981C20AB9 for ; Mon, 22 Apr 2024 02:45:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D7344C83; Mon, 22 Apr 2024 02:45:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dapfjYMZ" Received: from mail-oa1-f54.google.com (mail-oa1-f54.google.com [209.85.160.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B95F133EE for ; Mon, 22 Apr 2024 02:45:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713753903; cv=none; b=PpORESVUwcZBctWen9pwgz2IrevTjWfdstNAOeBKxqclffJq+ZIMH3kVUHqV+R3Xqe3YqotDY/zVUhuuejll3NFjhpFG6ZNqbmXMOIQoU8FBW8RR/K2HR4lMDpXKt5uyEGl1Clp+mjua3YXZc6IEOwOw/4jAVplQnJ7G7DdH6/g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713753903; c=relaxed/simple; bh=cDw11cIBcxmL95D6Hy2+ZjVaz9KsSCqVuZf4OLrMgdw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=een6xmxlGrZ6ZML/98qUBWiNXK3SkPaa9Ibs1HEecv82evmPF19BTGGR7E9iwgixUst4QQo6TmiZBHDlrXdz6cMkqkgSt8AznRGQgQPRtffuCphBMHpbShoxlw4NYzxp7PLQN+hQQXpmCtJRohQ/GnlQ9osYSd1MAeS4Tn24naA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dapfjYMZ; arc=none smtp.client-ip=209.85.160.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-22ed075a629so1523815fac.3 for ; Sun, 21 Apr 2024 19:45:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713753901; x=1714358701; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=XIK5vML3v/bdvHLH+Cj3KR7pbajmQ/BzdHOwU1URj74=; b=dapfjYMZZXg+86yPPniOh47hqtkMefB6W3TeBvsPNyzMQbszjOhL9Amy7MRQlMwyjE nP/KkhiS8wxbytH3TFtdn4CQ2ZixZRhfuGReerkW4hAG1kFWIHKiccr78zsXX52i9Z9R IKOAymbCnBKgCZcz+/YnJKzSfjX+dQbejOBYYPs/lTjnrF4nMThbnTbawRPhaL3Xs+X0 vQntFSuOKkK3e+QbjFuU9cun/PH/pRLXCSKq4XnPjW8sxH0PtcCheoxIrcdSLKZOG/z8 H2HBxn93nc8lw2APSHD7W6DnmdhW2Oj27BJehY05bal37zy1mpi27vk+xzZ8HJqXPWuR uLcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713753901; x=1714358701; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XIK5vML3v/bdvHLH+Cj3KR7pbajmQ/BzdHOwU1URj74=; b=UlbMXNfwf7XMElMFTiIKtlQUTPvp0YFvLPaBZNauDnqbEAV1CrNgm2P9igvUbckzSA NeeVH6ZQMqm/zunW3Xeb2mvqzUohdmrNUkXVWcqoQ6xqRsOLIQEOpFTVc5l4zZBklC94 c9rEM4gZt0BDtGZI9VEt0KsxjWbzf15sDvF9svESiziMLldGYOcEjPpVgqS5qs3XIoUt 5xnseJ/6r74qAZtSIankzRvvnj70ImO1LzoOqT92d0pQRX2CnFYKVWjDdHvj82E2Gjid oC6H5eIpMFoAc8vFm8ClA+Xy7GJGTs7iusqGYMKeAt8BhPOJgBbhLFruy4xlqAYYr9Iq rSXA== X-Forwarded-Encrypted: i=1; AJvYcCURG7DlZ9FNa/7QSBl7JGlm4+FQOKuk0LKEBJdmXiYgUvjpOujQSd59pNjfS3LpRcZYqjuKsnwRtaz6dZI2iwTv3gvcxh8B3j/0QiYe X-Gm-Message-State: AOJu0YxKmuRYO9/TSokxA4MIoFxm0mzj+4xbjYlojuRVIcuX6mv4DCTC CwYyH0EYkx0oOfffruYYqqEdhd843966W1ifxyvMqyAU3Kh+DA0xuacaHQ== X-Received: by 2002:a05:6870:ed98:b0:239:88f4:45d4 with SMTP id fz24-20020a056870ed9800b0023988f445d4mr9166514oab.2.1713753900725; Sun, 21 Apr 2024 19:45:00 -0700 (PDT) Received: from [192.168.255.10] ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id fq9-20020a056a0060c900b006e6b3c4e70bsm7026267pfb.171.2024.04.21.19.44.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Apr 2024 19:45:00 -0700 (PDT) Message-ID: <1dd938aa-3066-4e3d-a7eb-e1dd83ebbf25@gmail.com> Date: Mon, 22 Apr 2024 10:44:56 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1] mm/ksm: remove page_mapcount() usage in stable_tree_search() To: David Hildenbrand , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , Alex Shi References: <20240416172533.663418-1-david@redhat.com> Content-Language: en-US From: Alex Shi In-Reply-To: <20240416172533.663418-1-david@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 4/17/24 1:25 AM, David Hildenbrand wrote: > 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; > } > LGTM Reviewed-by: Alex Shi