From patchwork Thu Aug 24 03:42:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363436 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 3B810C3DA6F for ; Thu, 24 Aug 2023 03:44:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD72B280070; Wed, 23 Aug 2023 23:44:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C87288E0011; Wed, 23 Aug 2023 23:44:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4FAA280070; Wed, 23 Aug 2023 23:44:14 -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 A3E748E0011 for ; Wed, 23 Aug 2023 23:44:14 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7E76E1C9076 for ; Thu, 24 Aug 2023 03:44:14 +0000 (UTC) X-FDA: 81157605228.06.9DADD47 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) by imf21.hostedemail.com (Postfix) with ESMTP id 9B1B51C0015 for ; Thu, 24 Aug 2023 03:44:12 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="Iz2/0G+S"; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.161.47 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692848652; 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=tDsQ7RYDMLqwy7twIXuFD5p94As+lf02HfuxyLHsCC8=; b=xSFECfd+Br6KflU5L/t2xi3Lv5peVKFgOrABPtV7L4gnqJa+i13ZW0+1MTHK6J21PWW4WN TNb+P0Gelxem9BXAMPpp28r7hg4ln5Y/kzPLDIQTMdh4AfbIlzRPgUnm/tF7NQkR7pHTN+ WJILDfwGVMv6vqhazJ1jmei/xNfkE3M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848652; a=rsa-sha256; cv=none; b=1eUqjo+yrLYRD6V8GNLVvmg4OChqvUSlzlEgjwtURMA5Gc2PjisoevD35YOfluNMoMFNnZ xvrQqhnKjnYQgBpux+XiNtXo37/2cPkyn2z/rMWrJzhc9UxYwcn6L/Vgqe1c4mRLcHwg2d w2QH/pR3c+q6TkWx7nAnx6e7seeX1A8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="Iz2/0G+S"; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.161.47 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5711d5dac14so204179eaf.0 for ; Wed, 23 Aug 2023 20:44:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848652; x=1693453452; 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=tDsQ7RYDMLqwy7twIXuFD5p94As+lf02HfuxyLHsCC8=; b=Iz2/0G+SOuFIIhaxK3w/LEcD9PS4zKZ/5RcLqJKJdh7uItCmfOpE5/jAV7CTQYQwrv 9LBEDsGb7OQVTT0y75+W3hmVRKD+wPpekmo+U1aWv4VIpRlze67WWzhGK7PvHfv80+Aq 22HTG7tQsAc/n7lxTDb50FgYJVxBohbov3zGbdkxBFRg2+u94qfoy1WCYE/6SjCv6IEm ltAHVGpsm97r2LYMNXe9UbJZYZZt9/2CCg8ESzyBAJkE7r6xfLbBYY9uJptQzOq9AB8z gdd+zPqCkxoqARc/NmfQ31JLb8MZu5Pxd2lkneChOp1kQa9CHtD0HIZqJbsdwGK/j8pA D8xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848652; x=1693453452; 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=tDsQ7RYDMLqwy7twIXuFD5p94As+lf02HfuxyLHsCC8=; b=Xrg1QPxpsxHHzA5ZA9sI58kz7lUoeo+ZT+GZqujcB91ZXhJxf/Xncy4qEKseDt1m4E LfxBgVTmnI2zjn0C33jjYIN5WTiLUstNcsBwpZ/ns0FSEgf+A1CDeRz8F8bVzRUj7l5L msl3Ey7RcRB56ulF44ZwYifQIghtmf5pOtnCP9QOQANCYX3Vvu01TxFEpnbUekgmPRrU RZq7ZxHX+GcqLXrtO9U8ap0qAmBQp70EJHKv44I/rDISHygCWSMtbKgRYsbHXCG/vEkh N/13Y1zPaEDLLgm9F+2NlIifmfCfiiMCrqPN0bGLvY+L/ALRc5WC4o/3lAXELMrcJv2A 7deg== X-Gm-Message-State: AOJu0YxdiyiAA/cQn0YqarbHrnxW5jeeouG3rsVuojEiXy68Tc9lWjpc xDEReIaRXmY6do1wueetuMUcuw== X-Google-Smtp-Source: AGHT+IEM8N+jMmp+ItOCDi7GhGIbRWYtk0R7RyKurKUW+QPYSbNbY2W9LIX4qInIQ/vDJIM/8yTcQQ== X-Received: by 2002:a05:6808:1a84:b0:3a6:f8e5:edad with SMTP id bm4-20020a0568081a8400b003a6f8e5edadmr13552232oib.4.1692848651831; Wed, 23 Aug 2023 20:44:11 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:44:11 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Qi Zheng , Muchun Song , Carlos Llamas Subject: [PATCH v5 03/45] binder: dynamically allocate the android-binder shrinker Date: Thu, 24 Aug 2023 11:42:22 +0800 Message-Id: <20230824034304.37411-4-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Stat-Signature: 34wyip5r1333q55zw711atb3w6hfui6g X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9B1B51C0015 X-Rspam-User: X-HE-Tag: 1692848652-465452 X-HE-Meta: U2FsdGVkX19Zj3b+nyumsOGWXGwrapj2VeuGmytKJ5103/TcfuWXz6HHg+5mATwkKSotwp6KoLH8odG69MID1/Hz5iBZfWlRTJmeyrvgGuVkEOB9cB5PRQfZs9Kav//YkjoBLExDTUQ/2ZNXvEfTEe9ea0/71iDnBOzQpSgFNcXwO55mA5DMWg4Z1o0uhe2AEQN0DCPLwkfGwLn7YWkYtc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KgiGTnezFDKcrBS1qGlzNREnGrHaIfTQHM5TbK3byw83Sm4y4Gm4WMnvK1YIeRd43UOZoDbZuRExWYj89BtG7DkT9hpqAlWyGyPmb6rnzguf2GgWA/1ukvY5zxHppiZ0wboAq0QpPwj3XxZ5Dc59Bd4kq5PDmGXNiQFm2k87Woc/Ed6Vx4buwBX0+Tb21pBPig== 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: Use new APIs to dynamically allocate the android-binder shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Greg Kroah-Hartman CC: Carlos Llamas Acked-by: Carlos Llamas --- drivers/android/binder_alloc.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index e3db8297095a..62675cedd38e 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -1053,11 +1053,7 @@ binder_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) NULL, sc->nr_to_scan); } -static struct shrinker binder_shrinker = { - .count_objects = binder_shrink_count, - .scan_objects = binder_shrink_scan, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *binder_shrinker; /** * binder_alloc_init() - called by binder_open() for per-proc initialization @@ -1077,19 +1073,30 @@ void binder_alloc_init(struct binder_alloc *alloc) int binder_alloc_shrinker_init(void) { - int ret = list_lru_init(&binder_alloc_lru); + int ret; - if (ret == 0) { - ret = register_shrinker(&binder_shrinker, "android-binder"); - if (ret) - list_lru_destroy(&binder_alloc_lru); + ret = list_lru_init(&binder_alloc_lru); + if (ret) + return ret; + + binder_shrinker = shrinker_alloc(0, "android-binder"); + if (!binder_shrinker) { + list_lru_destroy(&binder_alloc_lru); + return -ENOMEM; } - return ret; + + binder_shrinker->count_objects = binder_shrink_count; + binder_shrinker->scan_objects = binder_shrink_scan; + binder_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(binder_shrinker); + + return 0; } void binder_alloc_shrinker_exit(void) { - unregister_shrinker(&binder_shrinker); + shrinker_free(binder_shrinker); list_lru_destroy(&binder_alloc_lru); }