From patchwork Thu Sep 29 02:59:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xu xin X-Patchwork-Id: 12993456 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 4004AC32771 for ; Thu, 29 Sep 2022 03:00:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E9536B0073; Wed, 28 Sep 2022 23:00:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7997A6B0074; Wed, 28 Sep 2022 23:00:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 613918D0001; Wed, 28 Sep 2022 23:00:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4F49F6B0073 for ; Wed, 28 Sep 2022 23:00:08 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CF809160F1D for ; Thu, 29 Sep 2022 03:00:07 +0000 (UTC) X-FDA: 79963618854.15.13A4159 Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) by imf25.hostedemail.com (Postfix) with ESMTP id 6A607A000C for ; Thu, 29 Sep 2022 03:00:07 +0000 (UTC) Received: by mail-pj1-f68.google.com with SMTP id 70so94133pjo.4 for ; Wed, 28 Sep 2022 20:00:07 -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; bh=mxeZyACnh97j+FymKAYz3kB3KSv2VBxKUGSN2j7Wq6Y=; b=EOz8icziHra0ftSQpyT3922e5VAw/fKBGYS00L0hmKII/vHtyvEOFWfza3kKS7yGCZ 1y2rMrAXxc7JHY8Ep6TvKdAZjqbdzfOmBdv4GsllOKeuNdL8FV3j1wPlTkIOyBAxtSCN wFXNkpLMIFoHmLuEc8tfWJjbaSP7cl+jmx6u8HQnV/dp3LKjUjlkrCk+Z8W6JYgZ7h7v VtllJuaFXsFZkW5yociCu7t64H8eVUQwFPn8ut7ESSkBID/c6ifrykOOLgVoYr+QlCET oScmPiqx1sXOVoKjHBfJtDGihq4pl88H5gxFaX86WPHsE4TjwpIix+evnd9CvfpqvFfy 5xXw== 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; bh=mxeZyACnh97j+FymKAYz3kB3KSv2VBxKUGSN2j7Wq6Y=; b=sJaVOwIFeF5n9dKB3Vz62UmNh7PJ1XE+BcyU7jw0ffLsN7x7gQpbUAuP2ItvdbNbhM i2R1lk8ZnjrDF3Ex1xJlT1Np2LWoYGdxatvpFkIQPhFhXRfYkDL700BzkSkpNIgJF82o ILeZ0TtehqxToyCNHMIIBYQ1BJtr0fof9c9F+iLstZwe+yVSUgU98ZOq8fdIPHo1i+v2 fTLf84Ckbm7cqiqLqfhIoqv0a46yIGNlZnDqmTiQqYzjEX0+725LmgtYAGCSzt4aa+lS b5sHlcPER3COzs0FahNeUIEpuqd9n0yENgWXxT0SOArKzWaLbt0N9KRf9oanL6ohnC6z GSXA== X-Gm-Message-State: ACrzQf1VO5lgQP0SP89jDTequS4SzgcFQV8TKbYBV4nkfffchElf5ld4 ffcCvk+KXLR3YJBNAATJFGQ= X-Google-Smtp-Source: AMsMyM6qqRWwaLSe1b37Y5HEzyG+6FA7W11RQ1KQ1jPPz/qLyl504CF4sqlfojbI0un7im7QrBrNtA== X-Received: by 2002:a17:902:d2c4:b0:178:32c4:6648 with SMTP id n4-20020a170902d2c400b0017832c46648mr1261890plc.88.1664420406551; Wed, 28 Sep 2022 20:00:06 -0700 (PDT) Received: from localhost.localdomain ([193.203.214.57]) by smtp.gmail.com with ESMTPSA id n4-20020a170903110400b0016dcbdf9492sm4610669plh.92.2022.09.28.20.00.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 20:00:06 -0700 (PDT) From: xu.xin.sc@gmail.com X-Google-Original-From: xu.xin16@zte.com.cn To: akpm@linux-foundation.org, david@redhat.com, imbrenda@linux.vnet.ibm.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, xu xin , Xiaokai Ran , Yang Yang , Jiang Xuexin , xu xin Subject: [PATCH 1/3] ksm: abstract the function try_to_get_old_rmap_item Date: Thu, 29 Sep 2022 02:59:57 +0000 Message-Id: <20220929025957.281329-1-xu.xin16@zte.com.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220929025206.280970-1-xu.xin16@zte.com.cn> References: <20220929025206.280970-1-xu.xin16@zte.com.cn> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664420407; 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=mxeZyACnh97j+FymKAYz3kB3KSv2VBxKUGSN2j7Wq6Y=; b=uL552qqEIIxMd16wHRdQVSwfSTrWiG8k3ktCE9AR++KVSruyXsuhKPyJHRv0UbTZUd3GCl yBXD0mTQAvqeVl7dtBjEX5TuC01KArT7QTzXtEFeJw3Wn9YCv96Ry5ePIXlYT8drRFn+Gc DNaIC5RNKo9609YfnsZnBzd9SywiqKA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=EOz8iczi; spf=pass (imf25.hostedemail.com: domain of xu.xin.sc@gmail.com designates 209.85.216.68 as permitted sender) smtp.mailfrom=xu.xin.sc@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664420407; a=rsa-sha256; cv=none; b=ed+zpRwnVu02yCNCbJ9nI0Wd+S0vy9pQr3Qeo5kmGr35m43X0tZlAQ4hPzLRA+p152Zk/y Dt11Prxa2xBJFIbko0YfPmjsMGNCu1FgUJMZkW8l7h+U5Nk2pD3DuWu/k3QMGX9tZYdndC InVd5LslgQ83JKDKYxBryckJEcp691I= Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=EOz8iczi; spf=pass (imf25.hostedemail.com: domain of xu.xin.sc@gmail.com designates 209.85.216.68 as permitted sender) smtp.mailfrom=xu.xin.sc@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Stat-Signature: 4w83uu5y3y3rw56hmumgzu1jadm38tna X-Rspamd-Queue-Id: 6A607A000C X-Rspamd-Server: rspam08 X-HE-Tag: 1664420407-77831 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. At the same time, the patch improves the readability and reusability of KSM code. Signed-off-by: xu xin Reviewed-by: Xiaokai Ran Reviewed-by: Yang Yang Cc: Jiang Xuexin Signed-off-by: xu xin --- 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 */