From mboxrd@z Thu Jan 1 00:00:00 1970 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 DAB31C0502C for ; Mon, 29 Aug 2022 14:32:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2BACC94000A; Mon, 29 Aug 2022 10:32:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 26A23940009; Mon, 29 Aug 2022 10:32:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10AE494000A; Mon, 29 Aug 2022 10:32:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id F2829940007 for ; Mon, 29 Aug 2022 10:32:14 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 837E180B2B for ; Mon, 29 Aug 2022 14:32:14 +0000 (UTC) X-FDA: 79852870188.12.3701F16 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf04.hostedemail.com (Postfix) with ESMTP id 942DA4003B for ; Mon, 29 Aug 2022 14:32:12 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id h13-20020a17090a648d00b001fdb9003787so3433619pjj.4 for ; Mon, 29 Aug 2022 07:32:12 -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; bh=OFwhHEGLumljaGedgUfodOQy4osJq+5CQC+cBVTf1a4=; b=IyANSXDIAVHdIMw1AI5TuvYNtfpaV67Jl260Y8+xMVdhjfSQFLTpLP4MgpOHqiy9SK 9UxJgUWjEjQAlh+KPBKpprPGSX21a88KTE3kn277BqYoVa6PgOUU6ReEZuIVulrm6bxV vZQbzD0Pa0jmvB4i8qDW4eYpd+LIPrBGTmfp+Tr6/1YfO4EOhzJSiEGnodgLaHizmu/e ZXK013ge40Yel978YJferBVAGCxaaVgpoFrXoVmdrIq7bb7vgL4oJeU3UOkfoMFNiVwY Rr90j8t2/o/Ns13DeCGEmlygJOc8ppDUKb61SG5SjFjEQ/rIjAk0va7BnB4cvxfLmW3u Thow== 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; bh=OFwhHEGLumljaGedgUfodOQy4osJq+5CQC+cBVTf1a4=; b=G5wlj+sBbe7twJcdeWt49BNuKk4ig9CFbDsAOVoGQMo6hvsVY6soFqWM5We8MDI2dK paiR7QqkOtyLR2ubtaDF1/c2j1PRBht60kvqEQ4nWcXZmLnCG9rO/xP7mRcpLEiOsUss VRik/hWYYlfT0Er+tN3ZKQEQuvCzWUtmtB5kOZ9kPoY1ylaTOC/GQmSbBo5LoVueUo45 v8UitvuQiHpx92ne7bChjI6fwkw1CxPnifxWodVyTLw0TIgSOprZTSagznjwcvIqjzHN atVYgKvN3IWSUJIXipnAcA+nBrM6Gwk5n+acZWi6qh8ZRLg8A9w3xEi+PjyNhwZzVVKh sJng== X-Gm-Message-State: ACgBeo1enEF7LdzwsQIYEIoAkdTZxU7NBfCC39yJp+4HaBfPtHc1Md2B 2o5RGrsa6tYAx3qMsoksDTgFKA== X-Google-Smtp-Source: AA6agR4kA8oyWWsZADmLylrRqrO+nQc/O3q31TITs1nYQy2t9TZrz7GEy7Vh87+LW0Y0vsMXeeg9sg== X-Received: by 2002:a17:902:7087:b0:173:2a01:9ddb with SMTP id z7-20020a170902708700b001732a019ddbmr16425709plk.109.1661783531249; Mon, 29 Aug 2022 07:32:11 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.228]) by smtp.gmail.com with ESMTPSA id x128-20020a626386000000b0052d200c8040sm7259327pfb.211.2022.08.29.07.32.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 07:32:10 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, 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 1/7] mm: introduce common struct mm_slot Date: Mon, 29 Aug 2022 22:30:49 +0800 Message-Id: <20220829143055.41201-2-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20220829143055.41201-1-zhengqi.arch@bytedance.com> References: <20220829143055.41201-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661783534; a=rsa-sha256; cv=none; b=ivj+hksqZJ+xGQPyFWATWMJk+dnLLmWztUPvI14Vwsj93zgPl5msIuEgCatNSeo0XIi7K6 o18l5DhjJHFK1v/ntVMKKZcchKEH7wlfhNpQ/LSief2/0pJ1zKaVdlRn7mw1nSy7xTapTr Et1VVCMTx4MfODcQFv5oJ+0o4LR3FP4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=IyANSXDI; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf04.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661783534; 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=OFwhHEGLumljaGedgUfodOQy4osJq+5CQC+cBVTf1a4=; b=6a2kVM/3cSS3biAMr5reSCTC3F66E8WTaGpdkHnEWB8eGOvHGFB2VjO6X3IslmZ7W1cnqv K3sjxhPsO84Z/nTnLZlr/76qh+StlWSv3bAm6w/otsa2ROQ0BCdfD2Ymlgqnf3Mgqo1UAq /Q8pMrWp8V8CeR6l0lHl8HP2NLUFAvU= Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=IyANSXDI; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf04.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com X-Rspam-User: X-Rspamd-Server: rspam10 X-Stat-Signature: uiws7t48zq3bzgu57hz8pdg47d5qecor X-Rspamd-Queue-Id: 942DA4003B X-HE-Tag: 1661783532-786049 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..c8f0d26ef7b0 --- /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 *alloc_mm_slot(struct kmem_cache *cache) +{ + if (!cache) /* initialization failed */ + return NULL; + return kmem_cache_zalloc(cache, GFP_KERNEL); +} + +static inline void free_mm_slot(struct kmem_cache *cache, void *objp) +{ + kmem_cache_free(cache, objp); +} + +#define get_mm_slot(_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 insert_to_mm_slots_hash(_hashtable, _mm, _mm_slot) \ +({ \ + _mm_slot->mm = _mm; \ + hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm); \ +}) + +#endif /* _LINUX_MM_SLOT_H */ -- 2.20.1