From patchwork Sat Oct 8 07:08:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xu xin X-Patchwork-Id: 13001711 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 D64F9C433F5 for ; Sat, 8 Oct 2022 07:09:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6DE016B0072; Sat, 8 Oct 2022 03:09:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 68D8A6B0073; Sat, 8 Oct 2022 03:09:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52E326B0074; Sat, 8 Oct 2022 03:09:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 433696B0072 for ; Sat, 8 Oct 2022 03:09:04 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 00E2C1A0886 for ; Sat, 8 Oct 2022 07:09:03 +0000 (UTC) X-FDA: 79996905408.07.B5EB7CA Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by imf02.hostedemail.com (Postfix) with ESMTP id 7900280023 for ; Sat, 8 Oct 2022 07:09:03 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id b5so6417384pgb.6 for ; Sat, 08 Oct 2022 00:09:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vwgE5luutAnRT+PkK5v8g5jEsmfaMaq0PpMbhLvP0lE=; b=KJH9tcBDp0sap3/a+uZB7MoB+le+Hj9E/RTZw8cXEhbev7uOO9m7VY6/LSqyjHSoWi vXFWcFDRVI4HnN2FfCyepXKx7Mm91gWvEe+682mOpaoxrqv2PHpP81rIZORMZACTcD2J 88NwHLa/ZTvZQcaMOoR4VA70825G9cVEGkPTfXkSf659eBsxTRT7WO0kYuEEd2PsBDUB hIJSykq3f1G2O0UB8I3QSl7do5Os+9lJAnvlS+GdJqi6yrk/pm3SLlFDeyugOo+MEngk s7/ahbIa17kdYFWZdMuq0F7DRE82lOWFnfoEBNSX3HpZBeLG1uTSPYPEAsOYCF9WKTsu OCrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vwgE5luutAnRT+PkK5v8g5jEsmfaMaq0PpMbhLvP0lE=; b=mFCCGuxu0RL6IgXUERlhZaQPYFvbMx+Y4Yvr4nEjNOsw+SCSOTPSYSCwse9SIm+Hq2 a7OU6UhVRav6pVsXiffhNgVUpxyuejuJ9zVMSxX2Og76J8tB1k0l2N8aqkJFYT0w7SH/ 3V2G7JsMynj1uxfk1KUwdydg8O0VwpEah1lJo0tiBxaPYZ2XHh/lwvsBVtnE6aCnu3Kq jpQS5kgkjc2zoaB/S8g+SFEjFtthTZCb5OjN3Tkuyv7ytWapWVFo3F5s0/OID2T/ADPT TibZJsm4KXhtmXmBzB0G55CYNdUE180QvL3N4TeHOx8IVvU/nFD8rIvlG74FT9NFsMkT cDLA== X-Gm-Message-State: ACrzQf0pnre173iTPnFq2IxYxZtTmGqG0IyPM8v8wHPlG4fK2EvOPpya jcUguKVbV0K7A41cumwWr88= X-Google-Smtp-Source: AMsMyM7XNpyJYi8+xXQI7TAFwE3wq3DKHhs27o0T2vzkkVChvR32huCVWy4yr1IJOdVca1qkQz1HwQ== X-Received: by 2002:a05:6a00:2c98:b0:553:e926:c47a with SMTP id ef24-20020a056a002c9800b00553e926c47amr8991912pfb.14.1665212942508; Sat, 08 Oct 2022 00:09:02 -0700 (PDT) Received: from localhost.localdomain ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id ij24-20020a170902ab5800b0017f49b41c12sm2593722plb.173.2022.10.08.00.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Oct 2022 00:09:01 -0700 (PDT) From: xu.xin.sc@gmail.com X-Google-Original-From: xu.xin16@zte.com.cn To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, xu xin , Claudio Imbrenda , David Hildenbrand , Xuexin Jiang , Xiaokai Ran , Yang Yang Subject: [PATCH 1/5] ksm: abstract the function try_to_get_old_rmap_item Date: Sat, 8 Oct 2022 07:08:53 +0000 Message-Id: <20221008070854.308851-1-xu.xin16@zte.com.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221008070156.308465-1-xu.xin16@zte.com.cn> References: <20221008070156.308465-1-xu.xin16@zte.com.cn> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665212943; a=rsa-sha256; cv=none; b=jcl2vkhkWLgpDEI+B9l3gKON7uCMs1bHVK/uGZe7Q3w4JZiuskpNmfuQwBr2fOm7afyPns PeAJRBXCsL2JCAFiZG5iYuxcIHrElPbJ0+kXNst7LX48z1RCybP6MW9gyp2NihSMxueA1l z/jySVXCczmijVvPUgbLH6vTxYvFehM= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KJH9tcBD; spf=pass (imf02.hostedemail.com: domain of xu.xin.sc@gmail.com designates 209.85.215.196 as permitted sender) smtp.mailfrom=xu.xin.sc@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665212943; 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:in-reply-to:references:references:dkim-signature; bh=vwgE5luutAnRT+PkK5v8g5jEsmfaMaq0PpMbhLvP0lE=; b=hdFqGsZDLaM1FAbvzCsgPo58bCCaGpyqlACRytdiSO+85bAVoHxMrqEArCIUHTNo/uQVlP TMDD1+UFEWj6EU6kbe122jsuADS0KzqDwQyYb4YvB8nZhXXWGeN+1cYSyhoVbSIfXqhoTL 8pKJTC4poBT+byBTCUaOZ1p+X3qF50M= Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KJH9tcBD; spf=pass (imf02.hostedemail.com: domain of xu.xin.sc@gmail.com designates 209.85.215.196 as permitted sender) smtp.mailfrom=xu.xin.sc@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: yw9y5hbe9axyb3obwhtcrgmwzmkguaca X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 7900280023 X-Rspam-User: X-HE-Tag: 1665212943-699142 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: 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: Claudio Imbrenda Cc: David Hildenbrand Cc: Xuexin Jiang Cc: Xiaokai Ran Cc: Yang Yang --- mm/ksm.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index c19fcca9bc03..5b68482d2b3b 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2187,14 +2187,11 @@ 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) @@ -2204,6 +2201,21 @@ static struct ksm_rmap_item *get_next_rmap_item(struct ksm_mm_slot *mm_slot, 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 */