From patchwork Wed Aug 31 03:19:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 12960292 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 CC080ECAAD8 for ; Wed, 31 Aug 2022 03:20:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F9796B0072; Tue, 30 Aug 2022 23:20:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 55A3D6B0073; Tue, 30 Aug 2022 23:20:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D4868D0001; Tue, 30 Aug 2022 23:20:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2CF096B0072 for ; Tue, 30 Aug 2022 23:20:14 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0792080562 for ; Wed, 31 Aug 2022 03:20:14 +0000 (UTC) X-FDA: 79858434348.08.5870AC3 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf08.hostedemail.com (Postfix) with ESMTP id AEEBF160033 for ; Wed, 31 Aug 2022 03:20:13 +0000 (UTC) Received: by mail-pf1-f169.google.com with SMTP id x19so11348769pfr.1 for ; Tue, 30 Aug 2022 20:20:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.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=im3YqRL2Rng/LKklgBeywc8L3p9g3oy/mXuP77cK8zU=; b=RD4nDOqLlkuwwB2t022lPA2anuLlf/CAS8a53Uv3i/r5QGL9l4YCtb8ZIiMBG7hbJC guoomosMxuYuN8jO6yVhowNvNsVavr98McnRWRcR5PVm8BYcH/KDGlV03enHRsETKqdN RXQKdUc/lvnulb44PzME6KYSESUO3mj/jRRKKZ+hOecySABPTqTrzlN6ah9eCr7yRUbS rjjh7Pmwpe0t+OMAT8XqcZDkDWbhDpmfXa2MFKhcLexZBRe76Jmz51AIvWELchSaNWUV LVgK/Y0PlNXGer69Rht7WgMzdbG9dlBLhwiFMBj/HMyH7wQN3BH5WnmbOS4U1Ucpon68 uxrA== 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=im3YqRL2Rng/LKklgBeywc8L3p9g3oy/mXuP77cK8zU=; b=PvAA9G1vZfQIsFYyTqkUz9qW4t5SrNnuDDHB93GDnag9wIW3rhEnZSAa72cdgz9q0Q i5WCXZLm6Hg5twu8WkjEypn9JELYZYg2oxD3hSj2tqFj8hZkVbsvcGjq5sR9NSMWrf/9 jaGeFoUic79eH0szNKNw9ZqtlzDO18VNppx6/zUaQJo5s3GVrywapmYTQWue+X/rCGWc 0PYX1v02gW3y07bmPU87otgBD9PW8siC4i7XMGHQwKsNzcG9SGA9BJ5BhWOpBUQ2FfHL e46l8m9UCIMXndKK5KGQFxG3NWiMYhiQmmv89eUAfLzmh3d/nA9BeYoBo08F60tNDHE5 Zoqg== X-Gm-Message-State: ACgBeo3CjHpOTKwYXeOAS/Z5JSqfep1D8l/aqsbDq8DgdwIBxiTyKpp/ Mt4LoLFgoIyYBd+LK8GkjKEzsg== X-Google-Smtp-Source: AA6agR6oR5JRUz8+cD5CEEtVrrOhgd1Fo8O/zVTIvVDMVu9FdFzHaITegImRSaKYL7R1u+K2Ofk0/A== X-Received: by 2002:a65:6417:0:b0:42b:2f13:8477 with SMTP id a23-20020a656417000000b0042b2f138477mr20270294pgv.329.1661916012858; Tue, 30 Aug 2022 20:20:12 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.245]) by smtp.gmail.com with ESMTPSA id i13-20020a170902c94d00b0015e8d4eb1d5sm8633535pla.31.2022.08.30.20.20.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Aug 2022 20:20:12 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, shy828301@gmail.com, willy@infradead.org, vbabka@suse.cz, hannes@cmpxchg.org, minchan@kernel.org, rppt@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qi Zheng Subject: [PATCH v2 1/7] mm: introduce common struct mm_slot Date: Wed, 31 Aug 2022 11:19:45 +0800 Message-Id: <20220831031951.43152-2-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20220831031951.43152-1-zhengqi.arch@bytedance.com> References: <20220831031951.43152-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=RD4nDOqL; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661916013; a=rsa-sha256; cv=none; b=FY8SY7fkoxMeDWmxQwqSgPRuTyTXhZyhj03NKTkY6UGHHUu5uZgkh1dHi844zyGIup/Rj6 TDCksTBRhl7Duc8W1iAoy5VCW+qRYxCdGxaBEcCf/SFh77o1PBL2G72rhFU2Y+0aXNRcX3 Dw+ULbcMPxbG7+JIBEOAFf+8T0DZ1Xw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661916013; 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=im3YqRL2Rng/LKklgBeywc8L3p9g3oy/mXuP77cK8zU=; b=Dl6b2BM+4XzmudjER5cFxHNlNve1atRTgzuMnBXOlyEaD7IKBUoD2Ili+uwcMu80vtLGVC na2lXJrR6RcNXR7DIX35IHL9jX/lyZJ7FjhYpcmYWwakYHe42rkgDrlDKDfcd+ON4O99FU PMkqeCfmiyTeACzOLqmx0A6ywaQHtdM= X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=RD4nDOqL; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspamd-Server: rspam02 X-Stat-Signature: s3wbieaiqtdygmszgs15bxdmynf9rri4 X-Rspamd-Queue-Id: AEEBF160033 X-HE-Tag: 1661916013-657375 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: At present, both THP and KSM module have similar structures mm_slot for organizing and recording the information required for scanning mm, and each defines the following exactly the same operation functions: - alloc_mm_slot - free_mm_slot - get_mm_slot - insert_to_mm_slots_hash In order to de-duplicate these codes, this patch introduces a common struct mm_slot, and subsequent patches will let THP and KSM to use it. Signed-off-by: Qi Zheng --- mm/mm_slot.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 mm/mm_slot.h diff --git a/mm/mm_slot.h b/mm/mm_slot.h new file mode 100644 index 000000000000..83f18ed1c4bd --- /dev/null +++ b/mm/mm_slot.h @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0 + +#ifndef _LINUX_MM_SLOT_H +#define _LINUX_MM_SLOT_H + +#include +#include + +/* + * struct mm_slot - hash lookup from mm to mm_slot + * @hash: link to the mm_slots hash list + * @mm_node: link into the mm_slots list + * @mm: the mm that this information is valid for + */ +struct mm_slot { + struct hlist_node hash; + struct list_head mm_node; + struct mm_struct *mm; +}; + +#define mm_slot_entry(ptr, type, member) \ + container_of(ptr, type, member) + +static inline void *mm_slot_alloc(struct kmem_cache *cache) +{ + if (!cache) /* initialization failed */ + return NULL; + return kmem_cache_zalloc(cache, GFP_KERNEL); +} + +static inline void mm_slot_free(struct kmem_cache *cache, void *objp) +{ + kmem_cache_free(cache, objp); +} + +#define mm_slot_lookup(_hashtable, _mm) \ +({ \ + struct mm_slot *tmp_slot, *mm_slot = NULL; \ + \ + hash_for_each_possible(_hashtable, tmp_slot, hash, (unsigned long)_mm) \ + if (_mm == tmp_slot->mm) { \ + mm_slot = tmp_slot; \ + break; \ + } \ + \ + mm_slot; \ +}) + +#define mm_slot_insert(_hashtable, _mm, _mm_slot) \ +({ \ + _mm_slot->mm = _mm; \ + hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm); \ +}) + +#endif /* _LINUX_MM_SLOT_H */