Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2870232rwb; Mon, 7 Aug 2023 05:03:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7vzC226fs5GOvcZ420oLzzcgkujx84j+jiDili6zCuC7UGIsQ9hqWZ4+RDbSR3P9+/Tyw X-Received: by 2002:a17:90a:bc1:b0:268:37b:a10e with SMTP id x1-20020a17090a0bc100b00268037ba10emr6810646pjd.11.1691409817130; Mon, 07 Aug 2023 05:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691409817; cv=none; d=google.com; s=arc-20160816; b=ns+70p6dnC0Z42EAri1tZdR+jx4P/83YW+R4M4yKFMAar4dA6fEq5DSo81v8cQK0/g MauHes2fh9kppVwryCJI6DF/4eyoY6qSOW1foNAehq35jbmZfsSP0oNdW7KMkVncVfX4 +Xxi/gn2qlWrUAZWW6wmMPGQDoeJ3/KFcCGRfL2gg477mGEr5gIcyHiC5BhR8ZR5QIDx kzuWRgMAuKzm1njc6KfCK0Hny10edS5e7wb2EpjVRbAQWBBx9B+bs3dd48M56yATrWX5 aIy14Mt4EGHp4Yauyz7H/bahej6L7oLSpNRyM4iCeA21EDsNvBvTZGKOoSC77hQwl1RN NRDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YQ2nJ797AaeiRC4tEbuFSwr/qroaEGD64TBkJX9gwcc=; fh=LQnZnJgbwA2rofRvgLxtxvFjbWmQSZR0bRTgn+flB4A=; b=TuqZvKDaCQHJUE/gC675N3opU464vtSAedCxmtm+T475Dj11TSqCAB/GimoSgeccL8 14mmiEnAIagV9pUnuVlS5eQCDqQQGuOXgUQjAuvPuGDX/FIr5sI3wzmALy8Qxy0ifQib a1BrHPdPqmemD2XiJs1Q1PbTToAVY+t8XUkwj2U8Y1b0f1atOOyrAaOWVWkLFiCcZpPr 2wuu8Aiosrvtf1dm6fBmN5f3yRozbFa1x5XEYRczT2mgUuwSQ4NyH4qsE2LvxXkalrcT 9C/2VagPRmS4pUykiCh9oxzgCPwoACPvO6bjYvWDzIZ0z7kDGAYUBCrcaobbkyKgIkKu aSqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ln47b2De; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oj10-20020a17090b4d8a00b00263d1729212si9334397pjb.85.2023.08.07.05.03.19; Mon, 07 Aug 2023 05:03:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ln47b2De; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232024AbjHGLMu (ORCPT + 99 others); Mon, 7 Aug 2023 07:12:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231357AbjHGLMU (ORCPT ); Mon, 7 Aug 2023 07:12:20 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B0CC1FC8 for ; Mon, 7 Aug 2023 04:11:33 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-55b5a37acb6so361734a12.0 for ; Mon, 07 Aug 2023 04:11:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1691406673; x=1692011473; 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=YQ2nJ797AaeiRC4tEbuFSwr/qroaEGD64TBkJX9gwcc=; b=ln47b2De8WoaconN/yovNFIYkpyrSlbHjJ7O30AuN0v3fhaptV8Rv8p/uTgMw5ewUp ZG1baXWX3w4cWqVDXIBOemS0oLj2+PNkaGXC2OZVpKMXphkVdxVMTs/lnTAL5HQl/5sY XaAH/gxR2iJTsD9i1SGvIVeauJ8ohBUlyO6fZCAIfCsaCSqlNBgSWC3X4OcCTxOF8D8P aJ3rhIbrBRQ4RScgXu8Juii6sq5YNvbJw6x09Ixyfaq7t74WXRGryvfs7JEz6b0jZFwc ahGUwsb8fn5Z7b9T7/r6r1MmeGyYyDblu8RFgBNHHb0eaf9aJCBTyNjHYvmNxb3vGqrU A9hQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691406673; x=1692011473; 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=YQ2nJ797AaeiRC4tEbuFSwr/qroaEGD64TBkJX9gwcc=; b=A0jfT5FPbYhdmsiNqPvYc4ReUaq8CEQIkl86t2Xu24pnbSaLhuM+WEpxGC+aMGu59x sOzXQSCGFau3ZKyOe1IikY4636WH4QWYK1w3mIg9F3U3GVyaEv3qWDEzrBWjjWjfNFAy B0EVwEC66YllH7QOyfeVp3BhQee92I2M4gqOsTGYJPsXx94c6iLv+pxepaoM1G+y6E9/ LuqF0G4Ko1Uh+cuaGwPTxkijbakZHLhxTxp16m+mq52tLCD6P2m3Ph20mhy+/Vk6slFo dO8ziLXJ9DE5LsZC0o19f0e7VRcf2s2j2Q8OmfUhO1zCv/9EsKGz8bn0e6jesB5L7o6Q 939w== X-Gm-Message-State: ABy/qLaPuz4Dfk8h4fTvC9KPawO4UCtw+ZTOgcatrqesUuHMvRehNrSW iGGcqLN4I+G86OmsGLi9W9Efwg== X-Received: by 2002:a17:90a:53a3:b0:268:437:7bd9 with SMTP id y32-20020a17090a53a300b0026804377bd9mr23468663pjh.3.1691406672888; Mon, 07 Aug 2023 04:11:12 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id y13-20020a17090aca8d00b0025be7b69d73sm5861191pjt.12.2023.08.07.04.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 04:11:12 -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, simon.horman@corigine.com, dlemoal@kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-bcache@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng Subject: [PATCH v4 06/48] binder: dynamically allocate the android-binder shrinker Date: Mon, 7 Aug 2023 19:08:54 +0800 Message-Id: <20230807110936.21819-7-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230807110936.21819-1-zhengqi.arch@bytedance.com> References: <20230807110936.21819-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Use new APIs to dynamically allocate the android-binder shrinker. Signed-off-by: Qi Zheng --- 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); } -- 2.30.2