Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp1279287rwl; Sun, 25 Dec 2022 18:42:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXuZTviRB8BKw+n0GGIjDzXxW6m+19atsKCDBnZAKtbQsl5ItPjWVq/qaLcgpgMdNGu6vZxL X-Received: by 2002:a05:6402:d5c:b0:46b:444b:ec40 with SMTP id ec28-20020a0564020d5c00b0046b444bec40mr14121031edb.15.1672022578548; Sun, 25 Dec 2022 18:42:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672022578; cv=none; d=google.com; s=arc-20160816; b=ei2dIO17rhBySd5siYyuS1fnyx5Bdkh10cxinmEqzRehHhzBNyM+vZjS4mVyha26bE 9Du3tmdq66i1HZ8sk/TuXN8R56wgqHqZMVV/rtiSc4sfIQzLR6isi1QEDsmklHKP5TLg TUmv2M6HRoVc4J0fNUaC+Ls4hjmuKZfczHyhnkWLi5hOC2n9kt69tRhWKb4ZK4RxeOm3 PdstkXqL/oNq8/Cwd5WbwmDKPUiTHZawhO5G+PpZ43C8fnBr0EhOrYc/9e8TrZXTdyWD ECG8m1XiJkgtBIj815jcdFZM6gkF/QlgkleaCkA4MZ2Pu4FvgMd1DNkJ10aqvCddkUUT QifA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:message-id:date; bh=28cza/u2aRQSvUsL28YQc+oAGxUZMdxK6+x65cyme5E=; b=YBnbmaeprIyAbBxGyb3tq7BQfPo8ORuVpo8nrphwQcrPcqT172luhMtHkN+4qugEab 3wDoLp+DRwYsb2/vuc0XD98wMwFV/jMUACxKf9mC19VmzIvq0j9PiIJRJIdTbC7gT1hz joWZr4f8hkJ5lbHysmXR2/T0xG6CEzmzUkl5n+YsbS1OIcDTkY0v/F9lpiXsX6g+EHIH UbcEhfGFtljPVv7Kz9WwoXySKm3m/Em1WC3M8ESfGIUJEI8CyoF5NAkuYKFbvZJahbnM 0wzAvV3dsKsUxL4pr1H9PdpR8zjfnEO0XwFvuyXxoP8mSd/m3aXrr/LldDW+FW4D91Hi 1/Ng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wz8-20020a170906fe4800b007aeb99bbb99si7885806ejb.48.2022.12.25.18.42.42; Sun, 25 Dec 2022 18:42:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231476AbiLZCBX (ORCPT + 67 others); Sun, 25 Dec 2022 21:01:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229560AbiLZCBV (ORCPT ); Sun, 25 Dec 2022 21:01:21 -0500 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [63.216.63.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A87C22DE2 for ; Sun, 25 Dec 2022 18:01:20 -0800 (PST) Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4NgLcH2ljtz8R041; Mon, 26 Dec 2022 10:01:19 +0800 (CST) Received: from szxlzmapp05.zte.com.cn ([10.5.230.85]) by mse-fl1.zte.com.cn with SMTP id 2BQ21E0a052063; Mon, 26 Dec 2022 10:01:14 +0800 (+08) (envelope-from yang.yang29@zte.com.cn) Received: from mapi (szxlzmapp01[null]) by mapi (Zmail) with MAPI id mid14; Mon, 26 Dec 2022 10:01:16 +0800 (CST) Date: Mon, 26 Dec 2022 10:01:16 +0800 (CST) X-Zmail-TransId: 2b0363a9006c2e76458f X-Mailer: Zmail v1.0 Message-ID: <202212261001160129980@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , , , , , Subject: =?UTF-8?B?W1BBVENIIHY0IDEvNl0ga3NtOiBhYnN0cmFjdCB0aGUgZnVuY3Rpb24gdHJ5X3RvX2dldF9vbGRfcm1hcF9pdGVt?= Content-Type: text/plain; charset="UTF-8" X-MAIL: mse-fl1.zte.com.cn 2BQ21E0a052063 X-Fangmail-Gw-Spam-Type: 0 X-FangMail-Miltered: at cgslv5.04-192.168.250.137.novalocal with ID 63A9006F.000 by FangMail milter! X-FangMail-Envelope: 1672020079/4NgLcH2ljtz8R041/63A9006F.000/10.5.228.132/[10.5.228.132]/mse-fl1.zte.com.cn/ X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 63A9006F.000/4NgLcH2ljtz8R041 X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SORTED_RECIPS,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: xu xin A new function try_to_get_old_rmap_item is abstracted from get_next_rmap_item. This function will be reused by the subsequent patches about counting ksm_zero_pages. The patch improves the readability and reusability of KSM code. Signed-off-by: xu xin Cc: David Hildenbrand Cc: Claudio Imbrenda Cc: Xuexin Jiang Reviewed-by: Xiaokai Ran Reviewed-by: Yang Yang --- mm/ksm.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index dd02780c387f..8d6336ef0750 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2214,23 +2214,36 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite } } -static struct ksm_rmap_item *get_next_rmap_item(struct ksm_mm_slot *mm_slot, - struct ksm_rmap_item **rmap_list, - unsigned long addr) +static struct ksm_rmap_item *try_to_get_old_rmap_item(unsigned long addr, + struct ksm_rmap_item **rmap_list) { - struct ksm_rmap_item *rmap_item; - while (*rmap_list) { - rmap_item = *rmap_list; + struct ksm_rmap_item *rmap_item = *rmap_list; if ((rmap_item->address & PAGE_MASK) == addr) return rmap_item; if (rmap_item->address > addr) break; *rmap_list = rmap_item->rmap_list; + /* Running here indicates it's vma has been UNMERGEABLE */ remove_rmap_item_from_tree(rmap_item); free_rmap_item(rmap_item); } + return NULL; +} + +static struct ksm_rmap_item *get_next_rmap_item(struct ksm_mm_slot *mm_slot, + struct ksm_rmap_item **rmap_list, + unsigned long addr) +{ + struct ksm_rmap_item *rmap_item; + + /* lookup if we have a old rmap_item matching the addr*/ + rmap_item = try_to_get_old_rmap_item(addr, rmap_list); + if (rmap_item) + return rmap_item; + + /* Need to allocate a new rmap_item */ rmap_item = alloc_rmap_item(); if (rmap_item) { /* It has already been zeroed */ -- 2.15.2