Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp435588lqo; Wed, 8 May 2024 04:38:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXDjbwWHaIFTP3s2Lz3MgnRIBnk7LBpHG1GcAOtRzuOiXUvHeTM8BOrm7RBOMEwVH0/1cGwz1USTzqHAsK5XQjkKDHzCBQ50q7GSgWuwg== X-Google-Smtp-Source: AGHT+IHrsPGzbsZetHBiz4BYO1kZ1MmoDcPVLGi2JhbVfNmvz3XjRrIGlmhI1MGp0C+OZeMnZdm/ X-Received: by 2002:a17:903:234d:b0:1e4:17e4:3a49 with SMTP id d9443c01a7336-1eeb049b2e1mr29800035ad.12.1715168284489; Wed, 08 May 2024 04:38:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715168284; cv=pass; d=google.com; s=arc-20160816; b=fyxVlneSSdR9KEGPviOE1kFwrdZdmf/SBIkmXpnk2vnV2uHXTAuH6ybjajT5trY+jh 2pQzjcrjarg0ccXU2zrlPyb2a23mNYsZ46wpOhZSbhKw6sZeD/DGKF/4QNqNeMhiKfOR gfPFvZ6h+i6KSMa5SDtC+ckOowQA8BI+2LSD2vWWxjdFbAU2z9j7SrQOc7zQ8qEAqgIh /n2p3P+ZJhy9Q0uPveR7fc+vZrnsKNSUbLN1Y9hfy31OonLFHon8VFHD9bT4HqGIA7I0 DinfVRjoJal7aYl1twXat/LoI4u5sxTmQTEYoq89t2mcXXL1F9fESBRuXZHzqxJpCg15 qeMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:from :dkim-signature; bh=nriJEVBMEpCdnex06+BPZnBx6tE8hsLyPOQq2hal354=; fh=UKWJzuM2EmCkwNB2B0ySvj9L6xZOem0cpYJ1p22A+x0=; b=Zn8d6d1tLy0fHOKAHg7o4/3eRx9Eyy1wfiGEmjG+sOfTkulizeoGg6wLRllnzijLQE CKnjEaTtiAcz5mr8OLdM6Viw7Tew9my/7LTopPgqfHQLniqKaFowMyQnVEduz8SVbip3 s/+XJhvpBTuJLKbSdIqfR69ctXJf+xUwYX9OKDLrqJ4YQaHVhU8hvoWgGGq9A8eQJCJq gm9FO/DaqccDcdDbvrt9dinaqdjVbgxRSWaaXqDvhP2x8lN2g4L9glUg40pWGLt41V1D lCQQuK5alUqq2zVpb5U6WqbVYTL/5/Aca3D08cl8mXrARrURklE3PLeK1tbdJhh5YAGS LpmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ex3Q7xo6; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-173151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173151-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b4-20020a170902d50400b001e27f807a8esi12708111plg.343.2024.05.08.04.38.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 04:38:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-173151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ex3Q7xo6; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-173151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-173151-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2187D28351B for ; Wed, 8 May 2024 11:38:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE54F82862; Wed, 8 May 2024 11:37:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ex3Q7xo6" Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (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 23F9E29CF0 for ; Wed, 8 May 2024 11:37:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715168274; cv=none; b=oeiobjAOZGV6aZ0O9UHAQNCvFWxTaRpRX6zDXhNV8AlZ5C0UnbK2Jj4OBx604HnlcBAZDYal2iNGNZHqt6uSazNuN/90sV1C9vwGTdjulobspa2FqgS3byjmIEJgiuRuf2iyjyCWg+tVy76nmx0iCF0/gLhdy3z7QgdjJX32mhM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715168274; c=relaxed/simple; bh=sxN0YLCXI7Y0n4Vqh32lIleqSk9k9glYHc0FeQ3opkw=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=MPi71J2yuwSFTKN3v+0+bO/69I43nvyyef2S+M8ZKaM6IF2bfUSfdhuEnSYIvBx3avxm/RGk3REfJ4RnEr+prIBTtGNDL7VKbXyVaj4lD73ekJSEbAch7BQspf/Q5SgQpwRVEf11vKIrZMCAwcd13zRamANaR7wdUv22eMJVKwc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ex3Q7xo6; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1715168270; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nriJEVBMEpCdnex06+BPZnBx6tE8hsLyPOQq2hal354=; b=ex3Q7xo6XxXF9sAXpowIwtq58PLnspUgVPY7Jq67105CmPW5K8ZUerwT2EcgIiEadTMPlc huyN3mAiw9RQq9uTbS2fzOh5XtoPRXdokFTA4viKM3qK0/m+h0XN80hoQWzn/K5wo8Mi0P 1EhyYdbqJ3g37Qh2MBFEMmtqh5W6wFQ= From: Chengming Zhou Subject: [PATCH 0/2] mm/ksm: optimize unstable_tree_search_insert() Date: Wed, 08 May 2024 19:35:40 +0800 Message-Id: <20240508-b4-ksm-unstable-insert-v1-0-631cdbc2b77f@linux.dev> 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="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAIxjO2YC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxMDUwML3SQT3eziXN3SvOKSxKQcoHQe0IQSXQNjI0sTEzNjQ/NUQyWg5oK i1LTMCrDB0bG1tQCaTOApaAAAAA== To: Andrew Morton , David Hildenbrand , Andrea Arcangeli , Stefan Roesch , Hugh Dickins Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, zhouchengming@bytedance.com, Chengming Zhou X-Developer-Signature: v=1; a=ed25519-sha256; t=1715168266; l=1099; i=chengming.zhou@linux.dev; s=20240508; h=from:subject:message-id; bh=sxN0YLCXI7Y0n4Vqh32lIleqSk9k9glYHc0FeQ3opkw=; b=auCEXbRktUQ9FKc3gKpYnYUR7iK9/N90VPMUkT6rOdxgYnMpoJViDw/Krb3BzqjXzp9UHYrax bnrgoo4ea6RCOB7VY06Xr/EL6EdKRT1LTL9bxwJvwOKZkl7vTIb/cut X-Developer-Key: i=chengming.zhou@linux.dev; a=ed25519; pk=kx40VUetZeR6MuiqrM7kPCcGakk1md0Az5qHwb6gBdU= X-Migadu-Flow: FLOW_OUT We use unstable_tree_search_insert() to find matched page or insert our rmap_item into the unstable tree if no matched found. Now it may return NULL too early in which cases we can do better: 1. get_mergeable_page() return NULL: which means tree_rmap_item is stale. 2. tree_page is migrated to another node and !ksm_merge_across_nodes. In both cases, we can just remove the staled or migrated one out of the unstable tree, so our rmap_item can be inserted successfully. The code flow becomes clearer and may increase the merge possibility too. Thanks for review and comments! Signed-off-by: Chengming Zhou --- Chengming Zhou (2): mm/ksm: re-search unstable tree when tree_rmap_item is stale mm/ksm: flush out migrated rmap_item to insert our rmap_item mm/ksm.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) --- base-commit: fb0f40125feec3de7ef4524600ac83946207117e change-id: 20240508-b4-ksm-unstable-insert-0329446317e1 Best regards, -- Chengming Zhou